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 /spec/test | |
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 'spec/test')
-rw-r--r-- | spec/test/parser.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/spec/test/parser.go b/spec/test/parser.go index 175c89e..483e553 100644 --- a/spec/test/parser.go +++ b/spec/test/parser.go @@ -68,7 +68,11 @@ func (t *Tree) format(buf *bytes.Buffer, depth int) { buf.WriteString(" ") } buf.WriteString("(") - buf.WriteString(t.Kind) + if t.Kind == "" { + buf.WriteString("<anonymous>") + } else { + buf.WriteString(t.Kind) + } if len(t.Children) > 0 { buf.WriteString("\n") for i, c := range t.Children { @@ -228,9 +232,17 @@ func formatSyntaxError(synErr *SyntaxError, gram Grammar) []byte { case tok.Invalid(): b.WriteString(fmt.Sprintf("'%v' (<invalid>)", string(tok.Lexeme()))) default: - b.WriteString(fmt.Sprintf("'%v' (%v)", string(tok.Lexeme()), gram.Terminal(tok.TerminalID()))) + if term := gram.Terminal(tok.TerminalID()); term != "" { + if alias := gram.TerminalAlias(tok.TerminalID()); alias != "" { + b.WriteString(fmt.Sprintf("'%v' (%v)", string(tok.Lexeme()), alias)) + } else { + b.WriteString(fmt.Sprintf("'%v' (%v)", string(tok.Lexeme()), term)) + } + } else { + b.WriteString(fmt.Sprintf("'%v'", string(tok.Lexeme()))) + } } - b.WriteString(fmt.Sprintf("; expected: %v", synErr.ExpectedTerminals[0])) + b.WriteString(fmt.Sprintf(": expected: %v", synErr.ExpectedTerminals[0])) for _, t := range synErr.ExpectedTerminals[1:] { b.WriteString(fmt.Sprintf(", %v", t)) } |