diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-06-10 16:41:41 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-06-11 19:09:19 +0900 |
commit | 7403c18fbc04f3045df1e69b63d7ffd5f04d77db (patch) | |
tree | 0933a8e875bac01b1b5b385b5069eb069aaad219 /grammar/grammar.go | |
parent | Support testable tree output in vartan-parse command (diff) | |
download | cotia-7403c18fbc04f3045df1e69b63d7ffd5f04d77db.tar.gz cotia-7403c18fbc04f3045df1e69b63d7ffd5f04d77db.tar.xz |
Remove the kind field from a node corresponding to an anonymous terminal symbol
Diffstat (limited to 'grammar/grammar.go')
-rw-r--r-- | grammar/grammar.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go index 65d232d..80846d9 100644 --- a/grammar/grammar.go +++ b/grammar/grammar.go @@ -1317,12 +1317,10 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, *spec } 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[mlspec.LexKindIDNil] = symbolNil.num().Int() - term2Kind[symbolNil.num()] = mlspec.LexKindIDNil.Int() continue } @@ -1331,7 +1329,6 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, *spec return nil, 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 { @@ -1342,10 +1339,16 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, *spec } } - terms, err := gram.symbolTable.terminalTexts() + termTexts, err := gram.symbolTable.terminalTexts() if err != nil { return nil, nil, err } + terms := make([]string, len(termTexts)) + for i, t := range termTexts { + if !strings.HasPrefix(t, "x_") { + terms[i] = t + } + } kindAliases := make([]string, gram.symbolTable.termNum.Int()) for _, sym := range gram.symbolTable.terminalSymbols() { @@ -1440,7 +1443,6 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, *spec Maleeni: &spec.Maleeni{ Spec: lexSpec, KindToTerminal: kind2Term, - TerminalToKind: term2Kind, Skip: skip, KindAliases: kindAliases, }, |