Debian Codegraph @

internal/parser/gen/golang/gototable.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 "compress/gzipscip-go gomod github.com/golang/go/src go1.24 `compress/gzip`/"
20 "encoding/gobscip-go gomod github.com/golang/go/src go1.24 `encoding/gob`/"
21 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
22 "pathscip-go gomod github.com/golang/go/src go1.24 path/"
23 "text/templatescip-go gomod github.com/golang/go/src go1.24 `text/template`/"
24
25 "github.com/goccmack/gocc/internal/ioscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/io`/"
26 "github.com/goccmack/gocc/internal/parser/lr1/itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/"
27 "github.com/goccmack/gocc/internal/parser/symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/"
28 )
29
30 type gotoTableDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData# struct {
31 NumNTSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData#NumNTSymbols. int
32 Rowsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData#Rows. [][]gotoRowElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#
33 }
34
35 type gotoRowElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement# struct {
36 NTscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#NT. string
37 Statescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#State. int
38 Padscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#Pad. int
39 }
40
41 func GenGotoTablescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/GenGotoTable().(outDir string, 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#, sym *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#, zip bool) {
42 if zip {
43 GenCompGotoTablescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/GenCompGotoTable().(outDir, itemSets, sym)
44 return
45 }
46 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 goto table").Parsescip-go gomod github.com/golang/go/src go1.24 `text/template`/Template#Parse().(gotoTableSrcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableSrc.[1:])
47 if err != nil {
48 panic(err)
49 }
50 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#)
51 if err := tmpl.Executescip-go gomod github.com/golang/go/src go1.24 `text/template`/Template#Execute().(wr, getGotoTableDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/getGotoTableData().(itemSets, sym)); err != nil {
52 panic(err)
53 }
54 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().(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", "gototable.go"), wr.Bytesscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#Bytes().())
55 }
56
57 func getGotoTableDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/getGotoTableData().(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#, sym *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#) *gotoTableDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData# {
58 data := &gotoTableDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData#{
59 NumNTSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData#NumNTSymbols.: sym.NumNTSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#NumNTSymbols().(),
60 Rowsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData#Rows.: make([][]gotoRowElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#, itemSets.Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSets#Size().()),
61 }
62 for i, set := range itemSets.Listscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSets#List().() {
63 data.Rowsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableData#Rows.[i] = getGotoRowDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/getGotoRowData().(set, sym)
64 }
65 return data
66 }
67
68 func getGotoRowDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/getGotoRowData().(itemSet *itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/.ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#, sym *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#) []gotoRowElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement# {
69 row := make([]gotoRowElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#, sym.NumNTSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#NumNTSymbols().())
70 var max int
71 for i, nt := range sym.NTListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#NTList().() {
72 row[i].NTscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#NT. = nt
73 row[i].Statescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#State. = itemSet.NextSetIndexscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#NextSetIndex().(nt)
74 n := nbytesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/nbytes().(row[i].Statescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#State.)
75 if n > max {
76 max = n
77 }
78 }
79 // Calculate padding.
80 for i := range row {
81 row[i].Padscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#Pad. = max + 1 - nbytesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/nbytes().(row[i].Statescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoRowElement#State.)
82 }
83 return row
84 }
85
86 const gotoTableSrcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableSrc. = `
87 // Code generated by gocc; DO NOT EDIT.
88
89 package parser
90
91 const numNTSymbols = {{.NumNTSymbols}}
92
93 type (
94 gotoTable [numStates]gotoRow
95 gotoRow [numNTSymbols]int
96 )
97
98 var gotoTab = gotoTable{
99 {{- range $i, $r := .Rows }}
100 gotoRow{ // S{{$i}}
101 {{- range $j, $gto := . }}
102 {{ printf "%d,%*c// %s" $gto.State $gto.Pad ' ' $gto.NT }}
103 {{- end }}
104 },
105 {{- end }}
106 }
107 `
108
109 func genEncscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/genEnc().(v interface{}) string {
110 buf := bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24 bytes/NewBuffer().(nil)
111 z := gzipscip-go gomod github.com/golang/go/src go1.24 `compress/gzip`/.NewWriterscip-go gomod github.com/golang/go/src go1.24 `compress/gzip`/NewWriter().(buf)
112 enc := gobscip-go gomod github.com/golang/go/src go1.24 `encoding/gob`/.NewEncoderscip-go gomod github.com/golang/go/src go1.24 `encoding/gob`/NewEncoder().(z)
113 if err := enc.Encodescip-go gomod github.com/golang/go/src go1.24 `encoding/gob`/Encoder#Encode().(v); err != nil {
114 panic(err)
115 }
116 if err := z.Closescip-go gomod github.com/golang/go/src go1.24 `compress/gzip`/Writer#Close().(); err != nil {
117 panic(err)
118 }
119 strBuf := bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24 bytes/NewBuffer().(nil)
120 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(strBuf, "[]byte{\n")
121 b := buf.Bytesscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#Bytes().()
122 for len(b) > 0 {
123 n := 16
124 if n > len(b) {
125 n = len(b)
126 }
127 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(strBuf, "\t\t")
128 for i, c := range b[:n] {
129 if i != 0 {
130 strBuf.WriteStringscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#WriteString().(" ")
131 }
132 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(strBuf, "0x%02x,", c)
133 }
134 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(strBuf, "\n")
135 b = b[n:]
136 }
137 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(strBuf, "\t}")
138 return string(strBuf.Bytesscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#Bytes().())
139 }
140
141 func GenCompGotoTablescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/GenCompGotoTable().(outDir string, 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#, sym *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#) {
142 numNTSymbols := sym.NumNTSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#NumNTSymbols().()
143 rows := make([][]int, itemSets.Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSets#Size().())
144 for i, set := range itemSets.Listscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSets#List().() {
145 rows[i] = make([]int, numNTSymbols)
146 for j, nt := range sym.NTListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#NTList().() {
147 rows[i][j] = set.NextSetIndexscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#NextSetIndex().(nt)
148 }
149 }
150 bytesStr := genEncscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/genEnc().(rows)
151 v := struct {
152 NumNTSymbols int
153 Bytes string
154 }{
155 NumNTSymbols: numNTSymbols,
156 Bytes: bytesStr,
157 }
158 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 goto table").Parsescip-go gomod github.com/golang/go/src go1.24 `text/template`/Template#Parse().(gotoTableCompSrcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableCompSrc.[1:])
159 if err != nil {
160 panic(err)
161 }
162 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#)
163 if err := tmpl.Executescip-go gomod github.com/golang/go/src go1.24 `text/template`/Template#Execute().(wr, v); err != nil {
164 panic(err)
165 }
166 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().(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", "gototable.go"), wr.Bytesscip-go gomod github.com/golang/go/src go1.24 bytes/Buffer#Bytes().())
167 }
168
169 const gotoTableCompSrcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/gen/golang`/gotoTableCompSrc. = `
170 // Code generated by gocc; DO NOT EDIT.
171
172 package parser
173
174 import (
175 "bytes"
176 "compress/gzip"
177 "encoding/gob"
178 )
179
180 const numNTSymbols = {{.NumNTSymbols}}
181
182 type (
183 gotoTable [numStates]gotoRow
184 gotoRow [numNTSymbols]int
185 )
186
187 var gotoTab = gotoTable{}
188
189 func init() {
190 tab := [][]int{}
191 data := {{.Bytes}}
192 buf, err := gzip.NewReader(bytes.NewBuffer(data))
193 if err != nil {
194 panic(err)
195 }
196 dec := gob.NewDecoder(buf)
197 if err := dec.Decode(&tab); err != nil {
198 panic(err)
199 }
200 for i := 0; i < numStates; i++ {
201 for j := 0; j < numNTSymbols; j++ {
202 gotoTab[i][j] = tab[i][j]
203 }
204 }
205 }
206 `