| 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 | ) |
| 23 | |
| 24 | // set is kept sorted |
| 25 | type DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet# struct { |
| 26 | setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set. []CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange# |
| 27 | MatchAnyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#MatchAny. bool |
| 28 | } |
| 29 | |
| 30 | func NewDisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/NewDisjunctRangeSet().() *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet# { |
| 31 | return &DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#{ |
| 32 | setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.: make([]CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#, 0, 16), |
| 33 | MatchAnyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#MatchAny.: false, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) AddLexTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#AddLexTNode().(sym astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexTNode#) { |
| 38 | switch s := sym.(type) { |
| 39 | case *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexCharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharRange#: |
| 40 | this.AddRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#AddRange().(s.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharRange#From..Valscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharLit#Val., s.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharRange#To..Valscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharLit#Val.) |
| 41 | case *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexCharLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharLit#: |
| 42 | this.AddRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#AddRange().(s.Valscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharLit#Val., s.Valscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexCharLit#Val.) |
| 43 | case *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexDotscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexDot#: |
| 44 | this.MatchAnyscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#MatchAny. = true |
| 45 | case *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexRegDefIdscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexRegDefId#: |
| 46 | // ignore |
| 47 | default: |
| 48 | panic(fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("Unexpected type of symbol: %T", sym)) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) addRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#addRange().(rng ...CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#) { |
| 53 | for _, r := range rng { |
| 54 | this.AddRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#AddRange().(r.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From., r.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | |===========| |
| 60 | |
| 61 | |-------| |===========| 1 |
| 62 | |-----------+---|-------+ 2 |
| 63 | |-----------+-----------| 3 |
| 64 | |-----------+-----------+---| 4 |
| 65 | |
| 66 | |---|-------+ 5 |
| 67 | |===========| 6 |
| 68 | |-----------+---| 7 |
| 69 | +===========+ |----| 8 |
| 70 | +---|----|--+ 9 |
| 71 | +---|-------| 10 |
| 72 | +---|-------+---| 11 |
| 73 | */ |
| 74 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) AddRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#AddRange().(from, to rune) { |
| 75 | for i := 0; i < len(this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.) && from <= to; { |
| 76 | rng := this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i] |
| 77 | switch { |
| 78 | case from < rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From.: |
| 79 | switch { |
| 80 | case to < rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From.: // (1) |
| 81 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i, from, to) |
| 82 | i += 2 |
| 83 | case to < rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // but >= set[i].From (2) |
| 84 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i] = CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#{from, rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From. - 1} |
| 85 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+1, rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From., to) |
| 86 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+2, to+1, rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.) |
| 87 | i += 3 |
| 88 | case to == rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: //(3) |
| 89 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i, from, rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From.-1) |
| 90 | i += 2 |
| 91 | case to > rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (4) |
| 92 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i, from, rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From.-1) |
| 93 | i += 2 |
| 94 | } |
| 95 | from = rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. + 1 |
| 96 | case from == rng.Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From.: |
| 97 | switch { |
| 98 | case to < rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (5) |
| 99 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i].Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. = to |
| 100 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+1, to+1, rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.) |
| 101 | i += 2 |
| 102 | case to > rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (7) |
| 103 | i++ // do nothing |
| 104 | case to == rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (6) |
| 105 | i++ // do nothing |
| 106 | } |
| 107 | from = rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. + 1 |
| 108 | case from > rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (8) |
| 109 | i++ // do nothing |
| 110 | default: // from > rng.From && from <= rng.To: |
| 111 | switch { |
| 112 | case to < rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // 9 |
| 113 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i].Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. = from - 1 |
| 114 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+1, from, to) |
| 115 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+2, to+1, rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.) |
| 116 | i += 3 |
| 117 | case to == rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (10) |
| 118 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i].Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. = from - 1 |
| 119 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+1, from, to) |
| 120 | i += 2 |
| 121 | case to > rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.: // (11) |
| 122 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i].Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. = from - 1 |
| 123 | this.insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(i+1, from, rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To.) |
| 124 | i += 2 |
| 125 | } |
| 126 | from = rng.Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. + 1 |
| 127 | } |
| 128 | } |
| 129 | if from <= to { |
| 130 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set. = append(this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set., CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#{from, to}) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) Rangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#Range().(i int) CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange# { |
| 135 | return this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[i] |
| 136 | } |
| 137 | |
| 138 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) insertRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#insertRange().(at int, from, to rune) { |
| 139 | mvSegSize := len(this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.) - at |
| 140 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set. = append(this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set., CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#{from, to}) |
| 141 | if mvSegSize > 0 { |
| 142 | copy(this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[at+1:], this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[at:at+mvSegSize]) |
| 143 | this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[at].Fromscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#From., this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.[at].Toscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#To. = from, to |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) Listscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#List().() []CharRangescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange# { |
| 148 | return this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set. |
| 149 | } |
| 150 | |
| 151 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) Sizescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#Size().() int { |
| 152 | return len(this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set.) |
| 153 | } |
| 154 | |
| 155 | func (this *DisjunctRangeSetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#) Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#String().() string { |
| 156 | w := new(stringsscip-go gomod github.com/golang/go/src go1.24 strings/.Builderscip-go gomod github.com/golang/go/src go1.24 strings/Builder#) |
| 157 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, "{") |
| 158 | for i, rng := range this.setscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/DisjunctRangeSet#set. { |
| 159 | if i > 0 { |
| 160 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, ", %s", rng.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#String().()) |
| 161 | } else { |
| 162 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, "%s", rng.Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/CharRange#String().()) |
| 163 | } |
| 164 | } |
| 165 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Fprintf().(w, "}") |
| 166 | return w.Stringscip-go gomod github.com/golang/go/src go1.24 strings/Builder#String().() |
| 167 | } |