diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-03-28 22:31:30 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-03-29 01:45:05 +0900 |
commit | ed43562cf58e8c0f9390421848879308fdfc60cb (patch) | |
tree | 16beff7d233b95ae53d2c8019bc47be378f304b8 /grammar/grammar.go | |
parent | Simplify the syntax of #ast directive (diff) | |
download | cotia-ed43562cf58e8c0f9390421848879308fdfc60cb.tar.gz cotia-ed43562cf58e8c0f9390421848879308fdfc60cb.tar.xz |
Add label notation
Diffstat (limited to 'grammar/grammar.go')
-rw-r--r-- | grammar/grammar.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go index 9d1933b..3f1117c 100644 --- a/grammar/grammar.go +++ b/grammar/grammar.go @@ -677,6 +677,7 @@ func (b *GrammarBuilder) genProductionsAndActions(root *spec.RootNode, symTabAnd LOOP_RHS: for _, alt := range prod.RHS { altSyms := make([]symbol, len(alt.Elements)) + labels := map[string]int{} for i, elem := range alt.Elements { var sym symbol if elem.Pattern != "" { @@ -707,6 +708,28 @@ func (b *GrammarBuilder) genProductionsAndActions(root *spec.RootNode, symTabAnd } } altSyms[i] = sym + + if elem.Label != nil { + if _, added := labels[elem.Label.Name]; added { + b.errs = append(b.errs, &verr.SpecError{ + Cause: semErrDuplicateLabel, + Detail: elem.Label.Name, + Row: elem.Label.Pos.Row, + Col: elem.Label.Pos.Col, + }) + continue LOOP_RHS + } + if _, found := symTab.toSymbol(elem.Label.Name); found { + b.errs = append(b.errs, &verr.SpecError{ + Cause: semErrInvalidLabel, + Detail: elem.Label.Name, + Row: elem.Label.Pos.Row, + Col: elem.Label.Pos.Col, + }) + continue LOOP_RHS + } + labels[elem.Label.Name] = i + } } p, err := newProduction(lhsSym, altSyms) |