| 1838 | } |
| 1839 | |
| 1840 | func yyErrorMessage(state, lookAhead int) string { |
| 1841 | const TOKSTART = 4 |
| 1842 | |
| 1843 | if !yyErrorVerbose { |
| 1844 | return "syntax error" |
| 1845 | } |
| 1846 | |
| 1847 | for _, e := range yyErrorMessages { |
| 1848 | if e.state == state && e.token == lookAhead { |
| 1849 | return "syntax error: " + e.msg |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | res := "syntax error: unexpected " + yyTokname(lookAhead) |
| 1854 | |
| 1855 | // To match Bison, suggest at most four expected tokens. |
| 1856 | expected := make([]int, 0, 4) |
| 1857 | |
| 1858 | // Look for shiftable tokens. |
| 1859 | base := yyPact[state] |
| 1860 | for tok := TOKSTART; tok-1 < len(yyToknames); tok++ { |
| 1861 | if n := base + tok; n >= 0 && n < yyLast && yyChk[yyAct[n]] == tok { |
| 1862 | if len(expected) == cap(expected) { |
| 1863 | return res |
| 1864 | } |
| 1865 | expected = append(expected, tok) |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | if yyDef[state] == -2 { |
| 1870 | i := 0 |
| 1871 | for yyExca[i] != -1 || yyExca[i+1] != state { |
| 1872 | i += 2 |
| 1873 | } |
| 1874 | |
| 1875 | // Look for tokens that we accept or reduce. |
| 1876 | for i += 2; yyExca[i] >= 0; i += 2 { |
| 1877 | tok := yyExca[i] |
| 1878 | if tok < TOKSTART || yyExca[i+1] == 0 { |
| 1879 | continue |
| 1880 | } |
| 1881 | if len(expected) == cap(expected) { |
| 1882 | return res |
| 1883 | } |
| 1884 | expected = append(expected, tok) |
| 1885 | } |
| 1886 | |
| 1887 | // If the default action is to accept or reduce, give up. |
| 1888 | if yyExca[i+1] != 0 { |
| 1889 | return res |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | for i, tok := range expected { |
| 1894 | if i == 0 { |
| 1895 | res += ", expecting " |
| 1896 | } else { |
| 1897 | res += " or " |