aboutsummaryrefslogtreecommitdiff
path: root/cmd/vartan/parse.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-06-10 16:41:41 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-06-11 19:09:19 +0900
commit7403c18fbc04f3045df1e69b63d7ffd5f04d77db (patch)
tree0933a8e875bac01b1b5b385b5069eb069aaad219 /cmd/vartan/parse.go
parentSupport testable tree output in vartan-parse command (diff)
downloadcotia-7403c18fbc04f3045df1e69b63d7ffd5f04d77db.tar.gz
cotia-7403c18fbc04f3045df1e69b63d7ffd5f04d77db.tar.xz
Remove the kind field from a node corresponding to an anonymous terminal symbol
Diffstat (limited to 'cmd/vartan/parse.go')
-rw-r--r--cmd/vartan/parse.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/cmd/vartan/parse.go b/cmd/vartan/parse.go
index d1fc80e..3f895c9 100644
--- a/cmd/vartan/parse.go
+++ b/cmd/vartan/parse.go
@@ -112,14 +112,7 @@ func runParse(cmd *cobra.Command, args []string) error {
if !*parseFlags.onlyParse {
// A parser can construct a parse tree even if syntax errors occur.
// When therer is a parse tree, print it.
-
- var tree *driver.Node
- if *parseFlags.cst {
- tree = tb.Tree()
- } else {
- tree = tb.Tree()
- }
- if tree != nil {
+ if tree := tb.Tree(); tree != nil {
switch *parseFlags.format {
case "tree":
b := tester.ConvertSyntaxTreeToTestableTree(tree).Format()
@@ -179,10 +172,14 @@ func writeSyntaxErrorMessage(b *strings.Builder, cgram *spec.CompiledGrammar, sy
case tok.Invalid():
fmt.Fprintf(b, "'%v' (<invalid>)", string(tok.Lexeme()))
default:
- fmt.Fprintf(b, "'%v' (%v)", string(tok.Lexeme()), cgram.ParsingTable.Terminals[tok.TerminalID()])
+ if kind := cgram.ParsingTable.Terminals[tok.TerminalID()]; kind != "" {
+ fmt.Fprintf(b, "'%v' (%v)", string(tok.Lexeme()), kind)
+ } else {
+ fmt.Fprintf(b, "'%v'", string(tok.Lexeme()))
+ }
}
- fmt.Fprintf(b, "; expected: %v", synErr.ExpectedTerminals[0])
+ fmt.Fprintf(b, ": expected: %v", synErr.ExpectedTerminals[0])
for _, t := range synErr.ExpectedTerminals[1:] {
fmt.Fprintf(b, ", %v", t)
}