| 415 | } |
| 416 | |
| 417 | func yyErrorMessage(state, lookAhead int) string { |
| 418 | const TOKSTART = 4 |
| 419 | |
| 420 | if !yyErrorVerbose { |
| 421 | return "syntax error" |
| 422 | } |
| 423 | |
| 424 | for _, e := range yyErrorMessages { |
| 425 | if e.state == state && e.token == lookAhead { |
| 426 | return "syntax error: " + e.msg |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | res := "syntax error: unexpected " + yyTokname(lookAhead) |
| 431 | |
| 432 | // To match Bison, suggest at most four expected tokens. |
| 433 | expected := make([]int, 0, 4) |
| 434 | |
| 435 | // Look for shiftable tokens. |
| 436 | base := int(yyPact[state]) |
| 437 | for tok := TOKSTART; tok-1 < len(yyToknames); tok++ { |
| 438 | if n := base + tok; n >= 0 && n < yyLast && int(yyChk[int(yyAct[n])]) == tok { |
| 439 | if len(expected) == cap(expected) { |
| 440 | return res |
| 441 | } |
| 442 | expected = append(expected, tok) |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | if yyDef[state] == -2 { |
| 447 | i := 0 |
| 448 | for yyExca[i] != -1 || int(yyExca[i+1]) != state { |
| 449 | i += 2 |
| 450 | } |
| 451 | |
| 452 | // Look for tokens that we accept or reduce. |
| 453 | for i += 2; yyExca[i] >= 0; i += 2 { |
| 454 | tok := int(yyExca[i]) |
| 455 | if tok < TOKSTART || yyExca[i+1] == 0 { |
| 456 | continue |
| 457 | } |
| 458 | if len(expected) == cap(expected) { |
| 459 | return res |
| 460 | } |
| 461 | expected = append(expected, tok) |
| 462 | } |
| 463 | |
| 464 | // If the default action is to accept or reduce, give up. |
| 465 | if yyExca[i+1] != 0 { |
| 466 | return res |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | for i, tok := range expected { |
| 471 | if i == 0 { |
| 472 | res += ", expecting " |
| 473 | } else { |
| 474 | res += " or " |