diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-08-03 23:07:06 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-08-05 02:36:21 +0900 |
commit | 2fcab705ddf787fa0f4edab2f2dc7e579ca982d9 (patch) | |
tree | bf4d37e9985109c7456a48fa61cc53d688ef3376 /spec/test/parser.go | |
parent | Fix parse error messages for tree parser (diff) | |
download | cotia-2fcab705ddf787fa0f4edab2f2dc7e579ca982d9.tar.gz cotia-2fcab705ddf787fa0f4edab2f2dc7e579ca982d9.tar.xz |
Prohibit error node having children
Diffstat (limited to 'spec/test/parser.go')
-rw-r--r-- | spec/test/parser.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/spec/test/parser.go b/spec/test/parser.go index 33e035b..e9c557d 100644 --- a/spec/test/parser.go +++ b/spec/test/parser.go @@ -289,6 +289,14 @@ func formatSyntaxError(synErr *SyntaxError, gram Grammar, lineOffset int) []byte } func (tp *treeParser) genTree(node *Node) (*Tree, error) { + // A node labeled 'error' cannot have children. It always must be (error). + if sym := node.Children[0]; sym.Text == "error" { + if len(node.Children) > 1 { + return nil, fmt.Errorf("%v:%v: error node cannot take children", tp.lineOffset+sym.Row+1, sym.Col+1) + } + return NewTerminalNode(sym.Text, ""), nil + } + if len(node.Children) == 2 && node.Children[1].KindName == "string" { var text string str := node.Children[1].Children[0] |