| 2040 | } |
| 2041 | |
| 2042 | func yyErrorMessage(state, lookAhead int) string { |
| 2043 | const TOKSTART = 4 |
| 2044 | |
| 2045 | if !yyErrorVerbose { |
| 2046 | return "syntax error" |
| 2047 | } |
| 2048 | |
| 2049 | for _, e := range yyErrorMessages { |
| 2050 | if e.state == state && e.token == lookAhead { |
| 2051 | return "syntax error: " + e.msg |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | res := "syntax error: unexpected " + yyTokname(lookAhead) |
| 2056 | |
| 2057 | // To match Bison, suggest at most four expected tokens. |
| 2058 | expected := make([]int, 0, 4) |
| 2059 | |
| 2060 | // Look for shiftable tokens. |
| 2061 | base := yyPact[state] |
| 2062 | for tok := TOKSTART; tok-1 < len(yyToknames); tok++ { |
| 2063 | if n := base + tok; n >= 0 && n < yyLast && yyChk[yyAct[n]] == tok { |
| 2064 | if len(expected) == cap(expected) { |
| 2065 | return res |
| 2066 | } |
| 2067 | expected = append(expected, tok) |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | if yyDef[state] == -2 { |
| 2072 | i := 0 |
| 2073 | for yyExca[i] != -1 || yyExca[i+1] != state { |
| 2074 | i += 2 |
| 2075 | } |
| 2076 | |
| 2077 | // Look for tokens that we accept or reduce. |
| 2078 | for i += 2; yyExca[i] >= 0; i += 2 { |
| 2079 | tok := yyExca[i] |
| 2080 | if tok < TOKSTART || yyExca[i+1] == 0 { |
| 2081 | continue |
| 2082 | } |
| 2083 | if len(expected) == cap(expected) { |
| 2084 | return res |
| 2085 | } |
| 2086 | expected = append(expected, tok) |
| 2087 | } |
| 2088 | |
| 2089 | // If the default action is to accept or reduce, give up. |
| 2090 | if yyExca[i+1] != 0 { |
| 2091 | return res |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | for i, tok := range expected { |
| 2096 | if i == 0 { |
| 2097 | res += ", expecting " |
| 2098 | } else { |
| 2099 | res += " or " |