Debian Codegraph @

internal/ast/grammar.go

raw symbols SCIP
1 //Copyright 2013 Vastech SA (PTY) LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/
16
17 import (
18 "errorsscip-go gomod github.com/golang/go/src go1.24 errors/"
19 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
20 "osscip-go gomod github.com/golang/go/src go1.24 os/"
21 )
22
23 type Grammarscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar# struct {
24 *LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart.
25 *SyntaxPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#SyntaxPart.
26 }
27
28 func NewGrammarscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/NewGrammar().(lexPart, syntaxPart interface{}) (*Grammarscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#, error) {
29 g := &Grammarscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#{}
30 if lexPart != nil {
31 g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart. = lexPart.(*LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexPart#)
32 } else {
33 lp, _ := NewLexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/NewLexPart().(nil, nil, nil)
34 g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart. = lp
35 }
36 if syntaxPart != nil {
37 g.SyntaxPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#SyntaxPart. = syntaxPart.(*SyntaxPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxPart#).augmentscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxPart#augment().()
38 }
39
40 return g, consistentscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/consistent().(g)
41 }
42
43 var (
44 errUndefinedscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/errUndefined. = errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("undefined symbol used in production")
45 )
46
47 func consistentscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/consistent().(g *Grammarscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#) (err error) {
48 if g.SyntaxPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#SyntaxPart. == nil {
49 return
50 }
51
52 defs := make(map[string]bool)
53 used := make(map[string][]string)
54
55 for _, tok := range g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart..TokDefsListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexPart#TokDefsList. {
56 defs[tok.idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexTokDef#id.] = true
57 }
58 for _, prod := range g.SyntaxPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#SyntaxPart..ProdListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxPart#ProdList. {
59 if len(prod.Bodyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Body..Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxBody#Symbols.) == 0 {
60 return fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24 fmt/Errorf().("empty production alternative: Maybe you are missing the \"empty\" keyword in %q", prod)
61 }
62 defs[prod.Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Id.] = true
63 for _, s := range prod.Bodyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Body..Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxBody#Symbols. {
64 if s.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxSymbol#String.()[0] == '"' {
65 continue
66 }
67 used[s.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxSymbol#String.()] = append(used[s.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxSymbol#String.()], prod.Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Id.)
68 }
69 }
70 for s := range defs {
71 if s == "S'" {
72 continue
73 }
74 if _, ok := used[s]; !ok {
75 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24 os/.Stderrscip-go gomod github.com/golang/go/src go1.24 os/Stderr., "warning: symbol %q defined but never used\n", s)
76 }
77 }
78 for s, in := range used {
79 if _, ok := defs[s]; !ok {
80 if s == "empty" || s == "error" {
81 continue
82 }
83 if s[0] >= 'A' && s[0] <= 'Z' {
84 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24 os/.Stderrscip-go gomod github.com/golang/go/src go1.24 os/Stderr., "error: undefined symbol %q used in productions %q\n", s, in)
85 err = errUndefinedscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/errUndefined.
86 } else {
87 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24 os/.Stderrscip-go gomod github.com/golang/go/src go1.24 os/Stderr., "warning: undefined symbol %q used in productions %q\n", s, in)
88 }
89 }
90 }
91 return
92 }