diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-03-29 21:52:47 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-03-29 22:12:37 +0900 |
commit | 90f28b5f7e7ef08e107e38002d122825764aad09 (patch) | |
tree | d80dfc08063727caa48fac4f28a929cb669c1465 /spec/parser.go | |
parent | Change syntax of production directives (diff) | |
download | urubu-90f28b5f7e7ef08e107e38002d122825764aad09.tar.gz urubu-90f28b5f7e7ef08e107e38002d122825764aad09.tar.xz |
Move directives given to lexical productions
Move all directives given to lexical productions from alternative directives to production directives.
This change aims to ensure consistency with respect to the syntax of definitions of terminal symbols and non-terminal symbols.
Diffstat (limited to 'spec/parser.go')
-rw-r--r-- | spec/parser.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/spec/parser.go b/spec/parser.go index be20e7d..fd11f83 100644 --- a/spec/parser.go +++ b/spec/parser.go @@ -16,10 +16,10 @@ type RootNode struct { } type ProductionNode struct { - Directive *DirectiveNode - LHS string - RHS []*AlternativeNode - Pos Position + Directives []*DirectiveNode + LHS string + RHS []*AlternativeNode + Pos Position } func (n *ProductionNode) isLexical() bool { @@ -312,7 +312,14 @@ func (p *parser) parseProduction() *ProductionNode { lhs := p.lastTok.text lhsPos := p.lastTok.pos - dir := p.parseDirective() + var dirs []*DirectiveNode + for { + dir := p.parseDirective() + if dir == nil { + break + } + dirs = append(dirs, dir) + } p.consume(tokenKindNewline) @@ -345,10 +352,10 @@ func (p *parser) parseProduction() *ProductionNode { } return &ProductionNode{ - Directive: dir, - LHS: lhs, - RHS: rhs, - Pos: lhsPos, + Directives: dirs, + LHS: lhs, + RHS: rhs, + Pos: lhsPos, } } |