Debian Codegraph @

internal/parser/lr1/items/itemset.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 itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
19 "sortscip-go gomod github.com/golang/go/src go1.24 sort/"
20 "stringsscip-go gomod github.com/golang/go/src go1.24 strings/"
21
22 "github.com/goccmack/gocc/internal/astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/"
23 "github.com/goccmack/gocc/internal/parser/firstscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/"
24 "github.com/goccmack/gocc/internal/parser/lr1/actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/"
25 "github.com/goccmack/gocc/internal/parser/symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/"
26 )
27
28 type ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet# struct {
29 SetNoscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#SetNo. int
30 imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap. map[string]*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#
31 Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. []*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#
32 // string: symbol, int: nextState.
33 Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions. map[string]int
34
35 Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#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#
36 Prodsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#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#
37 FSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#FS. *firstscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/.FirstSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/FirstSets#
38 }
39
40 // NewItemSet returns a newly cosntructed set of items.
41 func NewItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/NewItemSet().(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#, 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#, fs *firstscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/.FirstSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/FirstSets#) *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet# {
42 return &ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#{
43 SetNoscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#SetNo.: -1,
44 imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap.: make(map[string]*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#),
45 Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items.: make([]*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#, 0, 16),
46 Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions.: make(map[string]int),
47 Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Symbols.: symbols,
48 Prodsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Prods.: prods,
49 FSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#FS.: fs,
50 }
51 }
52
53 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Action().(symbol string) (act1 actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/.Actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#, conflicts []actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/.Actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#) {
54 conflictMap := make(map[string]actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/.Actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#)
55 act1 = actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/.ERRORscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/ERROR.
56 for _, item := range this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. {
57 act2 := item.actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#action().(symbol, this.Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions.[symbol])
58 switch {
59 case act2.Equalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#Equal.(actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/.ERRORscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/ERROR.):
60 // ignore
61 case act1.Equalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#Equal.(actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/.ERRORscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/ERROR.):
62 act1 = act2
63 case !act1.Equalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#Equal.(act2):
64 conflictMap[act1.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#String.()] = act1
65 conflictMap[act2.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#String.()] = act2
66 act1 = act1.ResolveConflictscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/action`/Action#ResolveConflict.(act2)
67 default:
68 // act1 == act2. Do nothing
69 }
70 }
71 for _, act := range conflictMap {
72 conflicts = append(conflicts, act)
73 }
74
75 return
76 }
77
78 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) AddItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#AddItem().(items ...*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#) {
79 for _, i := range items {
80 if _, contain := this.imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap.[i.strscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#str.]; !contain {
81 this.imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap.[i.strscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#str.] = i
82 this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. = append(this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items., i)
83 }
84 }
85 }
86
87 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) AddTransitionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#AddTransition().(symbol string, nextSet int) {
88 if _, exist := this.Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions.[symbol]; exist {
89 panic(fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("Transition %s -> %d already exists", symbol, nextSet))
90 }
91 this.Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions.[symbol] = nextSet
92 }
93
94 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) CanRecoverscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#CanRecover().() bool {
95 for _, item := range this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. {
96 if item.canRecoverscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#canRecover().() {
97 return true
98 }
99 }
100 return false
101 }
102
103 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) NextSetIndexscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#NextSetIndex().(symbol string) int {
104 if nextSet, exist := this.Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions.[symbol]; exist {
105 return nextSet
106 }
107 return -1
108 }
109
110 //TODO: optimise loop
111 /*
112 Dragon book, 2nd ed, section 4.7.2, p261
113 Closure(I)
114 repeat
115 for each item [A->x•By, a] in I
116 for each production B -> z in G'
117 for each terminal b in FIRST(ya)
118 add [B -> •z, b] to I
119 until no more items are added to I
120 */
121 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Closurescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Closure().() (c *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) {
122 if this.Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Size().() == 0 {
123 return NewItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/NewItemSet().(this.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Symbols., this.Prodsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Prods., this.FSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#FS.)
124 }
125 c = NewItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/NewItemSet().(this.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Symbols., this.Prodsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Prods., this.FSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#FS.)
126 c.AddItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#AddItem().(this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items....)
127 included := -1
128 for again := true; again; {
129 again = false
130 for idx, i := range c.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. {
131 if idx > included {
132 if i.Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Pos. >= i.Lenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Len. || this.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Symbols..IsTerminalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/symbols`/Symbols#IsTerminal().(i.ExpectedSymbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#ExpectedSymbol.) {
133 continue
134 }
135 for pi, prod := range this.Prodsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Prods. {
136 if prod.Idscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/SyntaxProd#Id. == i.ExpectedSymbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#ExpectedSymbol. {
137 first := first1scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/first1().(this.FSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#FS., i.Bodyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Body.[i.Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Pos.+1:], i.FollowingSymbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#FollowingSymbol.)
138 for _, t := range first {
139 if item := NewItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/NewItem().(pi, prod, 0, t); !c.Containscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Contain().(item) {
140 c.AddItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#AddItem().(item)
141 again = true
142 }
143 }
144 }
145 }
146
147 included = idx
148 }
149 }
150 }
151 return
152 }
153
154 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Containscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Contain().(item *Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#) bool {
155 if _, contain := this.imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap.[item.strscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#str.]; contain {
156 return true
157 }
158 return false
159 }
160
161 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) ContainStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#ContainString().(item string) bool {
162 if _, contain := this.imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap.[item]; contain {
163 return true
164 }
165 return false
166 }
167
168 // Equal will return whether two lists of Items are equal.
169 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Equalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Equal().(that *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) bool {
170 if that == nil || len(this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items.) != len(that.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items.) {
171 return false
172 }
173 for k := range this.imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap. {
174 if _, contain := that.imapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#imap.[k]; !contain {
175 return false
176 }
177 }
178
179 return true
180 }
181
182 // first1 returns the characters contained within the first set, sorted in
183 // alphabetical order.
184 func first1scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/first1().(firstSets *firstscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/.FirstSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/FirstSets#, symbols []string, following string) []string {
185 firsts := firstscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/.FirstSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/first`/FirstS().(firstSets, append(symbols, following))
186 keys := make([]string, 0, len(firsts))
187 for key := range firsts {
188 keys = append(keys, key)
189 }
190 sortscip-go gomod github.com/golang/go/src go1.24 sort/.Stringsscip-go gomod github.com/golang/go/src go1.24 sort/Strings().(keys)
191 return keys
192 }
193
194 // Goto implements Dragon book, 2nd ed, section 4.7.2, p261.
195 func (I *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Gotoscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Goto().(X string) *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet# {
196 J := NewItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/NewItemSet().(I.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Symbols., I.Prodsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Prods., I.FSscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#FS.)
197 for _, item := range I.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. {
198 if item.Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Pos. < item.Lenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Len. && X == item.ExpectedSymbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#ExpectedSymbol. {
199 nextItem := item.Movescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/Item#Move().()
200 J.AddItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#AddItem().(nextItem)
201 }
202 }
203 if J.Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Size().() > 0 {
204 J = J.Closurescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Closure().()
205 }
206 return J
207 }
208
209 // Size returns the number of items in the set.
210 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Size().() int {
211 return len(this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items.)
212 }
213
214 func (this *ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#) Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#String().() string {
215 buf := new(stringsscip-go gomod github.com/golang/go/src go1.24 strings/.Builderscip-go gomod github.com/golang/go/src go1.24 strings/Builder#)
216 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "{\n")
217 for _, item := range this.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Items. {
218 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "\t%s\n", item)
219 }
220 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "}\n")
221 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "Transitions:\n")
222 var keys transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#
223 for sym, set := range this.Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/ItemSet#Transitions. {
224 key := transitionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#{symbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#symbol.: sym, nextStatescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#nextState.: set}
225 keys = append(keys, key)
226 }
227 sortscip-go gomod github.com/golang/go/src go1.24 sort/.Sortscip-go gomod github.com/golang/go/src go1.24 sort/Sort().(keys)
228 for _, key := range keys {
229 sym, set := key.symbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#symbol., key.nextStatescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#nextState.
230 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "\t%s -> %d\n", sym, set)
231 }
232 fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "\n")
233 return buf.Stringscip-go gomod github.com/golang/go/src go1.24 strings/Builder#String().()
234 }
235
236 // transitions implements the sort.Sort interface, sorting transitions in
237 // ascending order based on the next state.
238 type transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions# []transitionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#
239
240 func (ts transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#) Lenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#Len().() int { return len(ts) }
241 func (ts transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#) Swapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#Swap().(i, j int) { ts[i], ts[j] = ts[j], ts[i] }
242 func (ts transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#) Lessscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transitions#Less().(i, j int) bool { return ts[i].nextStatescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#nextState. < ts[j].nextStatescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#nextState. }
243
244 // A transition represents a transition from a symbol to a given state.
245 type transitionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition# struct {
246 symbolscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#symbol. string
247 nextStatescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/parser/lr1/items`/transition#nextState. int
248 }