From e6bd501a9d6a33f5b0b5c67cb4b4af76cb4c5572 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Thu, 27 May 2021 22:14:53 +0900 Subject: Allow duplicate names between fragments and non-fragments --- spec/spec.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'spec/spec.go') 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 -- cgit v1.2.3