| 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 | "testingscip-go gomod github.com/golang/go/src go1.24 testing/" |
| 20 | |
| 21 | "github.com/goccmack/gocc/internal/lexer/symbolsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/symbols`/" |
| 22 | ) |
| 23 | |
| 24 | /* |
| 25 | id : _a | _b _a => |
| 26 | |
| 27 | id : • _a | _b _a |
| 28 | id : _a | • _b _a |
| 29 | |
| 30 | id : • a | _b => |
| 31 | |
| 32 | id : (_a | _b _a) • |
| 33 | |
| 34 | id : a | • _b _a => |
| 35 | |
| 36 | id : _a | _b • _a => |
| 37 | id : (_a | _b _A) • |
| 38 | */ |
| 39 | func Test1scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Test1().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 40 | src := `_a : 'a'; _b : 'b' ; id : _a | _b _a ;` |
| 41 | g := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/parse().(src, t) |
| 42 | 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().(g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart.) |
| 43 | |
| 44 | items1 := NewItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewItem().("id", g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart., symbols).Emovesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#Emoves().() |
| 45 | exp1 := "id : • _a | _b _a" |
| 46 | exp2 := "id : _a | • _b _a" |
| 47 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items1, exp1, exp2) |
| 48 | |
| 49 | exp3 := "id : (_a | _b _a) •" |
| 50 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp1, items1).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_a"), exp3) |
| 51 | |
| 52 | exp4 := "id : _a | _b • _a" |
| 53 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp2, items1).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_b"), exp4) |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | /* |
| 58 | id : _a {_b} => |
| 59 | |
| 60 | id : • _a {_b} => |
| 61 | id : _a {• _b} |
| 62 | id : _a {_b} • |
| 63 | */ |
| 64 | func Test2scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Test2().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 65 | src := `_a : 'a'; _b : 'b' ; id : _a {_b};` |
| 66 | g := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/parse().(src, t) |
| 67 | 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().(g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart.) |
| 68 | |
| 69 | items1 := NewItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewItem().("id", g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart., symbols).Emovesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#Emoves().() |
| 70 | |
| 71 | exp1 := "id : • _a {_b}" |
| 72 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items1, exp1) |
| 73 | |
| 74 | items2 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp1, items1).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_a") |
| 75 | exp2 := "id : _a {• _b}" |
| 76 | exp3 := "id : _a {_b} •" |
| 77 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items2, exp2, exp3) |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | id : [.] . => |
| 82 | |
| 83 | id : [• .] . |
| 84 | id : [.] • . |
| 85 | |
| 86 | id : [.] • . => |
| 87 | |
| 88 | id : [.] . • |
| 89 | */ |
| 90 | func Test3scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Test3().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 91 | src := `id : [.] .;` |
| 92 | g := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/parse().(src, t) |
| 93 | 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().(g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart.) |
| 94 | |
| 95 | items := NewItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewItem().("id", g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart., symbols).Emovesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#Emoves().() |
| 96 | |
| 97 | exp1 := "id : [• .] ." |
| 98 | exp2 := "id : [.] • ." |
| 99 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items, exp1, exp2) |
| 100 | exp3 := "id : [.] . •" |
| 101 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp2, items).MoveDotscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveDot().(), exp3) |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | id : _a (_a | _b) _c => |
| 106 | |
| 107 | id : •a (_a | _b) _c => |
| 108 | id : _a (• _a | _b) _c |
| 109 | id : _a (_a | • _b) _c |
| 110 | |
| 111 | id : _a (• _a | _b) _c => |
| 112 | |
| 113 | id : _a (_a | _b) •_c => |
| 114 | id : _a (_a | _b) _c • |
| 115 | |
| 116 | id : _a (_a | • _b) _c |
| 117 | |
| 118 | id : _a (_a | _b) •_c => |
| 119 | id : _a (_a | _b) _c • |
| 120 | */ |
| 121 | func Test4scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Test4().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 122 | src := "id : _a (_a | _b) _c ;" |
| 123 | g := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/parse().(src, t) |
| 124 | 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().(g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart.) |
| 125 | |
| 126 | items := NewItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewItem().("id", g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart., symbols).Emovesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#Emoves().() |
| 127 | |
| 128 | exp1 := "id : • _a (_a | _b) _c" |
| 129 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items, exp1) |
| 130 | |
| 131 | items1 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp1, items).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_a") |
| 132 | exp2 := "id : _a (• _a | _b) _c" |
| 133 | exp3 := "id : _a (_a | • _b) _c" |
| 134 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items1, exp2, exp3) |
| 135 | |
| 136 | items2 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp2, items1).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_a") |
| 137 | exp4 := "id : _a (_a | _b) • _c" |
| 138 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items2, exp4) |
| 139 | items3 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp4, items2).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_c") |
| 140 | exp5 := "id : _a (_a | _b) _c •" |
| 141 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items3, exp5) |
| 142 | |
| 143 | items4 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp3, items1).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_b") |
| 144 | exp6 := "id : _a (_a | _b) • _c" |
| 145 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items4, exp6) |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | id : {_a | _b} => |
| 150 | |
| 151 | id : {• _a | _b} |
| 152 | id : {_a | • _b} |
| 153 | id : {_a | _b} • |
| 154 | |
| 155 | id : {• _a | _b} => |
| 156 | |
| 157 | id : {• _a | _b} |
| 158 | id : {_a | • _b} |
| 159 | id : {_a | _b} • |
| 160 | */ |
| 161 | func Test5scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Test5().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 162 | src := `id : {_a | _b};` |
| 163 | g := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/parse().(src, t) |
| 164 | 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().(g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart.) |
| 165 | |
| 166 | items := NewItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewItem().("id", g.LexPartscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/Grammar#LexPart., symbols).Emovesscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#Emoves().() |
| 167 | |
| 168 | exp1, exp2, exp3 := "id : {• _a | _b}", "id : {_a | • _b}", "id : {_a | _b} •" |
| 169 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items, exp1, exp2, exp3) |
| 170 | |
| 171 | items1 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp1, items).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_a") |
| 172 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items1, exp1, exp2, exp3) |
| 173 | |
| 174 | items2 := findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(exp2, items).MoveRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#MoveRegDefId().("_b") |
| 175 | matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t, items2, exp1, exp2, exp3) |
| 176 | } |
| 177 | |
| 178 | func findItemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItem().(item string, items []*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#) *Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item# { |
| 179 | for _, item1 := range items { |
| 180 | if item1.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#String().() == item { |
| 181 | return item1 |
| 182 | } |
| 183 | } |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | func findItemWithPosLevelscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/findItemWithPosLevel().(items []*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#, level int) *Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item# { |
| 188 | for _, item := range items { |
| 189 | if item.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#pos..levelscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#level().() == level { |
| 190 | return item |
| 191 | } |
| 192 | } |
| 193 | return nil |
| 194 | } |
| 195 | |
| 196 | func matchItemsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/matchItems().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#, generatedItems []*Itemscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#, expectedItems ...string) { |
| 197 | dumpGeneratedItems := false |
| 198 | if len(generatedItems) != len(expectedItems) { |
| 199 | dumpGeneratedItems = true |
| 200 | t.Errorfscip-go gomod github.com/golang/go/src go1.24 testing/common#Errorf().("Expected %d items, got %d\n", len(expectedItems), len(generatedItems)) |
| 201 | } |
| 202 | itemMap := make(map[string]bool) |
| 203 | for _, item := range generatedItems { |
| 204 | itemMap[item.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/Item#String().()] = true |
| 205 | } |
| 206 | |
| 207 | for _, item := range expectedItems { |
| 208 | if _, ok := itemMap[item]; !ok { |
| 209 | dumpGeneratedItems = true |
| 210 | t.Errorfscip-go gomod github.com/golang/go/src go1.24 testing/common#Errorf().("Expected item >%s< not found\n", item) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if dumpGeneratedItems { |
| 215 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printfscip-go gomod github.com/golang/go/src go1.24 fmt/Printf().("item_test.matchItems: Generated items:\n") |
| 216 | for i, item := range generatedItems { |
| 217 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printfscip-go gomod github.com/golang/go/src go1.24 fmt/Printf().("\t%d: %s\n", i, item) |
| 218 | // fmt.Printf("%s", item.pos) |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | // func parse(src string, t *testing.T) *ast.Grammar { |
| 224 | // scanner := new(scanner.Scanner) |
| 225 | // scanner.Init([]byte(src), token.FRONTENDTokens) |
| 226 | // parser := parser.NewParser(parser.ActionTable, parser.GotoTable, parser.ProductionsTable, token.FRONTENDTokens) |
| 227 | // g, err := parser.Parse(scanner) |
| 228 | // if err != nil { |
| 229 | // t.Fatal(fmt.Sprintf("Parse error: %s\n", err)) |
| 230 | // return nil |
| 231 | // } |
| 232 | |
| 233 | // return g.(*ast.Grammar) |
| 234 | // } |