Debian Codegraph @

internal/parser/gen/golang/productionstable.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 golangscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/
16
17 import (
18 "bytesscip-go gomod github.com/golang/go/src go1.24 bytes/"
19 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
20 "pathscip-go gomod github.com/golang/go/src go1.24 path/"
21 "text/templatescip-go gomod github.com/golang/go/src go1.24 `text/template`/"
22
23 "github.com/goccmack/gocc/internal/astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/"
24 "github.com/goccmack/gocc/internal/ioscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/io`/"
25 "github.com/goccmack/gocc/internal/parser/lr1/itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/"
26 "github.com/goccmack/gocc/internal/parser/symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/"
27 "github.com/goccmack/gocc/internal/tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/token`/"
28 )
29
30 func GenProductionsTablescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/GenProductionsTable().(pkg, outDir, header string, prods astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.SyntaxProdListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProdList#, symbols *symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#,
31 itemsets *itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/.ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSets#, tokMap *tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/token`/.TokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/token`/TokenMap#) {
32 fname := pathscip-go gomod github.com/golang/go/src go1.24 path/.Joinscip-go gomod github.com/golang/go/src go1.24 path/Join().(outDir, "parser", "productionstable.go")
33 tmpl, err := templatescip-go gomod github.com/golang/go/src go1.24 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.24 `text/template`/New().("parser productions table").Parsescip-go gomod github.com/golang/go/src go1.24 `text/template`/Template#Parse().(prodsTabSrcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabSrc.[1:])
34 if err != nil {
35 panic(err)
36 }
37 wr := new(bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#)
38 if err := tmpl.Executescip-go gomod github.com/golang/go/src go1.24 `text/template`/Template#Execute().(wr, getProdsTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/getProdsTab().(header, prods, symbols, itemsets, tokMap)); err != nil {
39 panic(err)
40 }
41 ioscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/io`/.WriteFilescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/io`/WriteFile().(fname, wr.Bytesscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#Bytes().())
42 }
43
44 func getProdsTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/getProdsTab().(header string, prods astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.SyntaxProdListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProdList#, symbols *symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#,
45 itemsets *itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/.ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSets#, tokMap *tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/token`/.TokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/token`/TokenMap#) *prodsTabDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData# {
46 data := &prodsTabDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#{
47 Headerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#Header.: header,
48 ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.: make([]prodTabEntryscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#, len(prods)),
49 }
50 for i, prod := range prods {
51 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#String. = fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("`%s`", prod.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#String().())
52 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#Id. = prod.Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Id.
53 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].NTTypescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#NTType. = symbols.NTTypescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#NTType().(prod.Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Id.)
54 isEmpty := 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].SymbolStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxSymbol#SymbolString.() == "empty"
55 if isEmpty {
56 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].NumSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#NumSymbols. = 0
57 } else {
58 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].NumSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#NumSymbols. = 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.)
59 }
60 switch {
61 case len(prod.Bodyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Body..SDTscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxBody#SDT.) > 0:
62 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].ReduceFuncscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#ReduceFunc. = fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("return %s", prod.Bodyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Body..SDTscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxBody#SDT.)
63 case isEmpty:
64 // Empty production with no semantic action.
65 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].ReduceFuncscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#ReduceFunc. = "return nil, nil"
66 default:
67 data.ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab.[i].ReduceFuncscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#ReduceFunc. = "return X[0], nil"
68 }
69 }
70
71 return data
72 }
73
74 type prodsTabDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData# struct {
75 Headerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#Header. string
76 ProdTabscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabData#ProdTab. []prodTabEntryscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#
77 }
78
79 type prodTabEntryscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry# struct {
80 Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#String. string
81 Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#Id. string
82 NTTypescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#NTType. int
83 NumSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#NumSymbols. int
84 ReduceFuncscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodTabEntry#ReduceFunc. string
85 }
86
87 // TODO(types): change type and variable names to be consistent with other tables
88 const prodsTabSrcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/prodsTabSrc. = `
89 // Code generated by gocc; DO NOT EDIT.
90
91 package parser
92 {{if .Header}}
93 {{.Header}}
94 {{end}}
95 type (
96 ProdTab [numProductions]ProdTabEntry
97 ProdTabEntry struct {
98 String string
99 Id string
100 NTType int
101 Index int
102 NumSymbols int
103 ReduceFunc func([]Attrib, interface{}) (Attrib, error)
104 }
105 Attrib interface {
106 }
107 )
108
109 var productionsTable = ProdTab{
110 {{- range $i, $entry := .ProdTab }}
111 ProdTabEntry{
112 String: {{$entry.String}},
113 Id: "{{$entry.Id}}",
114 NTType: {{$entry.NTType}},
115 Index: {{$i}},
116 NumSymbols: {{$entry.NumSymbols}},
117 ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
118 {{$entry.ReduceFunc}}
119 },
120 },
121 {{- end }}
122 }
123 `