diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-02 01:42:50 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-02 01:42:50 +0900 |
commit | 74b51fb8cc2945af10da841a2ff901f4d3046977 (patch) | |
tree | c4f3d5e2f3fb4969cd7393107210e22649240f06 /grammar/grammar.go | |
parent | Use maleeni v0.3.0 (diff) | |
download | urubu-74b51fb8cc2945af10da841a2ff901f4d3046977.tar.gz urubu-74b51fb8cc2945af10da841a2ff901f4d3046977.tar.xz |
Print expected terminals on a parse error
Diffstat (limited to 'grammar/grammar.go')
-rw-r--r-- | grammar/grammar.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go index 4cde798..a7f80ca 100644 --- a/grammar/grammar.go +++ b/grammar/grammar.go @@ -629,10 +629,12 @@ func Compile(gram *Grammar, opts ...compileOption) (*spec.CompiledGrammar, error } kind2Term := make([]int, len(lexSpec.KindNames)) + term2Kind := make([]int, gram.symbolTable.termNum.Int()) skip := make([]int, len(lexSpec.KindNames)) for i, k := range lexSpec.KindNames { if k == mlspec.LexKindNameNil { - kind2Term[0] = symbolNil.num().Int() + kind2Term[mlspec.LexKindIDNil] = symbolNil.num().Int() + term2Kind[symbolNil.num()] = mlspec.LexKindIDNil.Int() continue } @@ -641,6 +643,7 @@ func Compile(gram *Grammar, opts ...compileOption) (*spec.CompiledGrammar, error return nil, fmt.Errorf("terminal symbol '%v' was not found in a symbol table", k) } kind2Term[i] = sym.num().Int() + term2Kind[sym.num()] = i for _, sk := range gram.skipLexKinds { if k != sk { @@ -735,6 +738,7 @@ func Compile(gram *Grammar, opts ...compileOption) (*spec.CompiledGrammar, error Maleeni: &spec.Maleeni{ Spec: lexSpec, KindToTerminal: kind2Term, + TerminalToKind: term2Kind, Skip: skip, }, }, @@ -751,6 +755,7 @@ func Compile(gram *Grammar, opts ...compileOption) (*spec.CompiledGrammar, error NonTerminals: nonTerms, NonTerminalCount: tab.nonTerminalCount, EOFSymbol: symbolEOF.num().Int(), + ExpectedTerminals: tab.expectedTerminals, }, ASTAction: &spec.ASTAction{ Entries: astActEnties, |