aboutsummaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-11-05 14:21:13 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-11-05 14:21:13 +0900
commitb24f61a465d21af404ed647a977160042017e601 (patch)
tree0b695a6775ed6a0a7bb41404b598055855417673 /driver
parentUpdate README (diff)
downloadcotia-b24f61a465d21af404ed647a977160042017e601.tar.gz
cotia-b24f61a465d21af404ed647a977160042017e601.tar.xz
Remove alias system
Remove unimportant features to tidy up the specification.
Diffstat (limited to 'driver')
-rw-r--r--driver/parser.go9
-rw-r--r--driver/parser_test.go34
-rw-r--r--driver/spec.go4
-rw-r--r--driver/syntax_error_test.go4
-rw-r--r--driver/template.go15
5 files changed, 22 insertions, 44 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"),
diff --git a/driver/spec.go b/driver/spec.go
index dda1251..e694d0b 100644
--- a/driver/spec.go
+++ b/driver/spec.go
@@ -64,10 +64,6 @@ func (g *grammarImpl) Terminal(terminal int) string {
return g.g.ParsingTable.Terminals[terminal]
}
-func (g *grammarImpl) TerminalAlias(terminal int) string {
- return g.g.LexicalSpecification.Maleeni.KindAliases[terminal]
-}
-
func (g *grammarImpl) ASTAction(prod int) []int {
return g.g.ASTAction.Entries[prod]
}
diff --git a/driver/syntax_error_test.go b/driver/syntax_error_test.go
index f68f595..ada1fb0 100644
--- a/driver/syntax_error_test.go
+++ b/driver/syntax_error_test.go
@@ -242,7 +242,7 @@ foo
},
},
{
- caption: "when an anonymous symbol is expected, an expected symbol list contains an alias of the anonymous symbol",
+ caption: "when an anonymous symbol is expected, an expected symbol list contains an auto-generated name with the prefix `x_`",
specSrc: `
#name test;
@@ -256,7 +256,7 @@ foo
src: `foobaz`,
cause: `baz`,
expected: []string{
- "bar",
+ "x_1",
},
},
}
diff --git a/driver/template.go b/driver/template.go
index 5ff3aa5..87c74f6 100644
--- a/driver/template.go
+++ b/driver/template.go
@@ -147,7 +147,6 @@ type grammarImpl struct {
nonTerminals []string
lhsSymbols []int
terminals []string
- terminalAliases []string
astActions [][]int
}
@@ -161,7 +160,6 @@ func NewGrammar() *grammarImpl {
nonTerminals: {{ genNonTerminals }},
lhsSymbols: {{ genLHSSymbols }},
terminals: {{ genTerminals }},
- terminalAliases: {{ genTerminalAliases }},
astActions: {{ genASTActions }},
}
}
@@ -218,10 +216,6 @@ func (g *grammarImpl) Terminal(terminal int) string {
return g.terminals[terminal]
}
-func (g *grammarImpl) TerminalAlias(terminal int) string {
- return g.terminalAliases[terminal]
-}
-
func (g *grammarImpl) ASTAction(prod int) []int {
return g.astActions[prod]
}
@@ -361,15 +355,6 @@ func genGrammarTemplateFuncs(cgram *spec.CompiledGrammar) template.FuncMap {
fmt.Fprintf(&b, "}")
return b.String()
},
- "genTerminalAliases": func() string {
- var b strings.Builder
- fmt.Fprintf(&b, "[]string{\n")
- for _, v := range cgram.LexicalSpecification.Maleeni.KindAliases {
- fmt.Fprintf(&b, "%v,\n", strconv.Quote(v))
- }
- fmt.Fprintf(&b, "}")
- return b.String()
- },
"genASTActions": func() string {
var b strings.Builder
fmt.Fprintf(&b, "[][]int{\n")