aboutsummaryrefslogtreecommitdiff
path: root/driver/parser
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--driver/parser.go9
-rw-r--r--driver/parser_test.go34
2 files changed, 20 insertions, 23 deletions
diff --git a/driver/parser.go b/driver/parser.go
index 14e9752..b7f12ff 100644
--- a/driver/parser.go
+++ b/driver/parser.go
@@ -44,9 +44,6 @@ type Grammar interface {
// Terminal retuns a string representaion of a terminal symbol.
Terminal(terminal int) string
- // TerminalAlias returns an alias for a terminal.
- TerminalAlias(terminal int) string
-
// ASTAction returns an AST action entries.
ASTAction(prod int) []int
}
@@ -370,11 +367,7 @@ func (p *Parser) searchLookahead(state int) []string {
continue
}
- if alias := p.gram.TerminalAlias(term); alias != "" {
- kinds = append(kinds, alias)
- } else {
- kinds = append(kinds, p.gram.Terminal(term))
- }
+ kinds = append(kinds, p.gram.Terminal(term))
}
return kinds
diff --git a/driver/parser_test.go b/driver/parser_test.go
index 215988d..dd58dd5 100644
--- a/driver/parser_test.go
+++ b/driver/parser_test.go
@@ -18,10 +18,6 @@ func termNode(kind string, text string, children ...*Node) *Node {
}
}
-func anonTermNode(text string, children ...*Node) *Node {
- return termNode("", text, children...)
-}
-
func errorNode() *Node {
return &Node{
Type: NodeTypeError,
@@ -50,18 +46,26 @@ func TestParser_Parse(t *testing.T) {
#name test;
expr
- : expr '+' term
+ : expr add term
| term
;
term
- : term '*' factor
+ : term mul factor
| factor
;
factor
- : '(' expr ')'
+ : l_paren expr r_paren
| id
;
+add
+ : '+';
+mul
+ : '*';
+l_paren
+ : '(';
+r_paren
+ : ')';
id
: "[A-Za-z_][0-9A-Za-z_]*";
`,
@@ -71,7 +75,7 @@ id
nonTermNode("term",
nonTermNode("term",
nonTermNode("factor",
- anonTermNode("("),
+ termNode("l_paren", "("),
nonTermNode("expr",
nonTermNode("expr",
nonTermNode("term",
@@ -80,10 +84,10 @@ id
),
),
),
- anonTermNode("+"),
+ termNode("add", "+"),
nonTermNode("term",
nonTermNode("factor",
- anonTermNode("("),
+ termNode("l_paren", "("),
nonTermNode("expr",
nonTermNode("expr",
nonTermNode("term",
@@ -92,27 +96,27 @@ id
),
),
),
- anonTermNode("+"),
+ termNode("add", "+"),
nonTermNode("term",
nonTermNode("factor",
termNode("id", "c"),
),
),
),
- anonTermNode(")"),
+ termNode("r_paren", ")"),
),
),
),
- anonTermNode(")"),
+ termNode("r_paren", ")"),
),
),
- anonTermNode("*"),
+ termNode("mul", "*"),
nonTermNode("factor",
termNode("id", "d"),
),
),
),
- anonTermNode("+"),
+ termNode("add", "+"),
nonTermNode("term",
nonTermNode("factor",
termNode("id", "e"),