From 90f28b5f7e7ef08e107e38002d122825764aad09 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Tue, 29 Mar 2022 21:52:47 +0900 Subject: 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. --- spec/parser.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'spec/parser.go') 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, } } -- cgit v1.2.3