| 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 | type itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos# struct { |
| 25 | stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack. []stackElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement# |
| 26 | } |
| 27 | |
| 28 | type stackElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement# struct { |
| 29 | nodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#node. astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexNTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexNTNode# |
| 30 | posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos. int |
| 31 | } |
| 32 | |
| 33 | func newItemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/newItemPos().(lexPattern *astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexPatternscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexPattern#) (pos *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) { |
| 34 | pos = &itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#{ |
| 35 | stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.: make([]stackElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#, 0, 8), |
| 36 | } |
| 37 | pos.pushscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#push().(lexPattern, 0) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) clonescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#clone().() *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos# { |
| 42 | clone := &itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#{ |
| 43 | stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.: make([]stackElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#, len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.)), |
| 44 | } |
| 45 | copy(clone.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack., this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[0:len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.)]) |
| 46 | return clone |
| 47 | } |
| 48 | |
| 49 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) incscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#inc().() { |
| 50 | this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[this.levelscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#level().()].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos.++ |
| 51 | } |
| 52 | |
| 53 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) popscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#pop().() (ntNode astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexNTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexNTNode#, pos int) { |
| 54 | ntNode, pos = this.topscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#top().() |
| 55 | this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack. = this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[:len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.)-1] |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) pushscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#push().(node astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexNTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexNTNode#, pos int) { |
| 60 | this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack. = append(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack., stackElementscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#{node, pos}) |
| 61 | } |
| 62 | |
| 63 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) topscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#top().() (nt astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexNTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexNTNode#, pos int) { |
| 64 | top := len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.) - 1 |
| 65 | nt, pos = this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[top].nodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#node., this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[top].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos. |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | // level returns the level of stacking in the item, where the bottom is 0. |
| 70 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) levelscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#level().() int { |
| 71 | return len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.) - 1 |
| 72 | } |
| 73 | |
| 74 | // ntNode returns the ast.Node at the top of the stack. |
| 75 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) ntNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#ntNode().() astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/.LexNTNodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexNTNode# { |
| 76 | n, _ := this.topscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#top().() |
| 77 | return n |
| 78 | } |
| 79 | |
| 80 | // pos returns the position within the top level of the stack. |
| 81 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#pos().() int { |
| 82 | _, pos := this.topscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#top().() |
| 83 | return pos |
| 84 | } |
| 85 | |
| 86 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) setPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#setPos().(i int) { |
| 87 | this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[this.levelscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#level().()].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos. = i |
| 88 | } |
| 89 | |
| 90 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) setToEndscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#setToEnd().() { |
| 91 | node, _ := this.topscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#top().() |
| 92 | this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[this.levelscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#level().()].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos. = node.Lenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/ast`/LexNTNode#Len.() |
| 93 | } |
| 94 | |
| 95 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) equalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#equal().(that *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) bool { |
| 96 | if len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.) != len(that.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.) { |
| 97 | return false |
| 98 | } |
| 99 | |
| 100 | for i := 0; i < len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.); i++ { |
| 101 | if this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].nodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#node. != that.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].nodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#node. || |
| 102 | this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos. != that.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos. { |
| 103 | return false |
| 104 | } |
| 105 | } |
| 106 | return true |
| 107 | } |
| 108 | |
| 109 | func (this *itemPosscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#) Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#String().() string { |
| 110 | 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#) |
| 111 | for i := 0; i < len(this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.); i++ { |
| 112 | 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%T:%v; pos %d\n", (*this).stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].nodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#node., (*this).stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].nodescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#node., this.stackscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/itemPos#stack.[i].posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/lexer/items`/stackElement#pos.) |
| 113 | } |
| 114 | return buf.Stringscip-go gomod github.com/golang/go/src go1.24 strings/Builder#String().() |
| 115 | } |