| 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/lexer/items`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/" |
| 19 | "stringsscip-go gomod github.com/golang/go/src go1.24 strings/" |
| 20 | |
| 21 | "github.com/goccmack/gocc/internal/astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/" |
| 22 | "github.com/goccmack/gocc/internal/lexer/symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/" |
| 23 | ) |
| 24 | |
| 25 | type ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets# struct { |
| 26 | setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets. []*ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet# |
| 27 | lexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#lexPart. *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexPart# |
| 28 | symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols. *symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/Symbols# |
| 29 | } |
| 30 | |
| 31 | func GetItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/GetItemSets().(lexPart *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexPart#) *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets# { |
| 32 | itemSets := &ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#{ |
| 33 | setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.: make([]*ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#, 0, 256), |
| 34 | lexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#lexPart.: lexPart, |
| 35 | symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols.: symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/.NewSymbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/NewSymbols().(lexPart), |
| 36 | } |
| 37 | |
| 38 | itemSets.Addscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Add().(ItemsSet0scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemsSet0().(lexPart, itemSets.symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols.)) |
| 39 | |
| 40 | return itemSets.Closurescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Closure().() |
| 41 | } |
| 42 | |
| 43 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Addscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Add().(items ItemListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemList#) (setNo int) { |
| 44 | if yes, setNo := this.Containscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Contain().(items); yes { |
| 45 | return setNo |
| 46 | } |
| 47 | setNo = this.Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Size().() |
| 48 | this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets. = append(this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets., NewItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewItemSet().(setNo, this.lexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#lexPart., this.symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols., items)) |
| 49 | return setNo |
| 50 | } |
| 51 | |
| 52 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Closurescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Closure().() *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets# { |
| 53 | for i := 0; i < len(this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.); i++ { |
| 54 | for symI, rng := range this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].SymbolClassesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#SymbolClasses..Listscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#List().() { |
| 55 | if items := this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].Nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Next().(rng); len(items) != 0 { |
| 56 | setNo, nextState := this.Addscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Add().(items), this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Transitions.[symI] |
| 57 | if nextState != -1 && nextState != setNo { |
| 58 | panic(fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("Next set conflict in (S%d, %s) -> %d. Existing setNo: %d", i, rng, setNo, nextState)) |
| 59 | } |
| 60 | this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Transitions.[symI] = setNo |
| 61 | } |
| 62 | } |
| 63 | for impI, imprt := range this.symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols..ImportIdListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/Symbols#ImportIdList. { |
| 64 | if items := this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].NextImportscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#NextImport().(imprt); len(items) != 0 { |
| 65 | setNo, nextState := this.Addscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Add().(items), this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].ImportTransitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#ImportTransitions.[this.symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols..ImportTypescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/Symbols#ImportType().(imprt)] |
| 66 | if nextState != -1 && nextState != setNo { |
| 67 | panic(fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("Next set conflict in (S%d, %s) -> %d. Existing setNo: %d", i, imprt, setNo, nextState)) |
| 68 | } |
| 69 | this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].ImportTransitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#ImportTransitions.[impI] = setNo |
| 70 | } |
| 71 | } |
| 72 | if items := this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].NextDotscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#NextDot().(); len(items) != 0 { |
| 73 | setNo := this.Addscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Add().(items) |
| 74 | this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.[i].DotTransitionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#DotTransition. = setNo |
| 75 | } |
| 76 | } |
| 77 | return this |
| 78 | } |
| 79 | |
| 80 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Containscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Contain().(items ItemListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemList#) (yes bool, index int) { |
| 81 | for i, thisSet := range this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets. { |
| 82 | if thisSet.Equalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Equal().(items) { |
| 83 | return true, i |
| 84 | } |
| 85 | } |
| 86 | return false, -1 |
| 87 | } |
| 88 | |
| 89 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Size().() int { |
| 90 | return len(this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets.) |
| 91 | } |
| 92 | |
| 93 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Listscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#List().() []*ItemSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet# { |
| 94 | return this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets. |
| 95 | } |
| 96 | |
| 97 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#Symbols().() *symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/.Symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/Symbols# { |
| 98 | return this.symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols. |
| 99 | } |
| 100 | |
| 101 | func (this *ItemSetsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#) Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#String().() string { |
| 102 | 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#) |
| 103 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "Item sets:\n") |
| 104 | for i, s := range this.setsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#sets. { |
| 105 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "S%d{\n", i) |
| 106 | for _, item := range s.Itemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Items. { |
| 107 | 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) |
| 108 | } |
| 109 | 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") |
| 110 | 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") |
| 111 | symClasses := s.SymbolClassesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#SymbolClasses..Listscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#List().() |
| 112 | for idx, symClass := range symClasses { |
| 113 | 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 -> S%d\n", symClass, s.Transitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Transitions.[idx]) |
| 114 | } |
| 115 | for idx, imprt := range this.symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSets#symbols..ImportIdListscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/Symbols#ImportIdList. { |
| 116 | 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", imprt, s.ImportTransitionsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#ImportTransitions.[idx]) |
| 117 | } |
| 118 | if s.SymbolClassesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#SymbolClasses..MatchAnyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#MatchAny. { |
| 119 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, ". -> S%d\n", s.DotTransitionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#DotTransition.) |
| 120 | } |
| 121 | if s.Actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Action().() == nil { |
| 122 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "Action: nil\n") |
| 123 | } else { |
| 124 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "Action: %s\n", s.Actionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#Action().()) |
| 125 | } |
| 126 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(buf, "Symbols classes: %s\n\n", s.SymbolClassesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/ItemSet#SymbolClasses.) |
| 127 | } |
| 128 | return buf.Stringscip-go gomod github.com/golang/go/src go1.24 strings/Builder#String().() |
| 129 | } |