aboutsummaryrefslogtreecommitdiff
path: root/spec/spec.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-05-27 22:14:53 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-05-27 22:14:53 +0900
commite6bd501a9d6a33f5b0b5c67cb4b4af76cb4c5572 (patch)
treef123dd54095ee8f6b7f7544ca71780ec3549ae8d /spec/spec.go
parentAdd fragment expression (diff)
downloadtre-e6bd501a9d6a33f5b0b5c67cb4b4af76cb4c5572.tar.gz
tre-e6bd501a9d6a33f5b0b5c67cb4b4af76cb4c5572.tar.xz
Allow duplicate names between fragments and non-fragments
Diffstat (limited to 'spec/spec.go')
-rw-r--r--spec/spec.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/spec/spec.go b/spec/spec.go
index 61955ac..829008a 100644
--- a/spec/spec.go
+++ b/spec/spec.go
@@ -143,11 +143,20 @@ func (s *LexSpec) Validate() error {
}
{
ks := map[string]struct{}{}
+ fks := map[string]struct{}{}
for _, e := range s.Entries {
- if _, exist := ks[e.Kind.String()]; exist {
- return fmt.Errorf("kinds `%v` are duplicates", e.Kind)
+ // Allow duplicate names between fragments and non-fragments.
+ if e.Fragment {
+ if _, exist := fks[e.Kind.String()]; exist {
+ return fmt.Errorf("kinds `%v` are duplicates", e.Kind)
+ }
+ fks[e.Kind.String()] = struct{}{}
+ } else {
+ if _, exist := ks[e.Kind.String()]; exist {
+ return fmt.Errorf("kinds `%v` are duplicates", e.Kind)
+ }
+ ks[e.Kind.String()] = struct{}{}
}
- ks[e.Kind.String()] = struct{}{}
}
}
return nil