| 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // A scanner for Go source text. Takes a []byte as source which can |
| 6 | // then be tokenized through repeated calls to the Scan function. |
| 7 | // For a sample use of a scanner, see the implementation of Tokenize. |
| 8 | package scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/ |
| 9 | |
| 10 | import ( |
| 11 | "bytesscip-go gomod github.com/golang/go/src go1.24 bytes/" |
| 12 | "strconvscip-go gomod github.com/golang/go/src go1.24 strconv/" |
| 13 | "unicodescip-go gomod github.com/golang/go/src go1.24 unicode/" |
| 14 | "unicode/utf8scip-go gomod github.com/golang/go/src go1.24 `unicode/utf8`/" |
| 15 | |
| 16 | "github.com/goccmack/gocc/internal/frontend/tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/" |
| 17 | ) |
| 18 | |
| 19 | // A Scanner holds the scanner's internal state while processing |
| 20 | // a given text. It can be allocated as part of another data |
| 21 | // structure but must be initialized via Init before use. For |
| 22 | // a sample use, see the implementation of Tokenize. |
| 23 | type Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner# struct { |
| 24 | // immutable state |
| 25 | srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src. []byte // source |
| 26 | tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap. *tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.TokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap# |
| 27 | |
| 28 | // scanning state |
| 29 | posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos. tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position# // previous reading position (position before ch) |
| 30 | offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset. int // current reading offset (position after ch) |
| 31 | chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. rune // one char look-ahead |
| 32 | |
| 33 | // public state - ok to modify |
| 34 | ErrorCountscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ErrorCount. int // number of errors encountered |
| 35 | } |
| 36 | |
| 37 | // Read the next Unicode char into S.ch. |
| 38 | // S.ch < 0 means end-of-file. |
| 39 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() { |
| 40 | if S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset. < len(S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.) { |
| 41 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset. = S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset. |
| 42 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Columnscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Column.++ |
| 43 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '\n' { |
| 44 | // next character starts a new line |
| 45 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Line.++ |
| 46 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Columnscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Column. = 1 |
| 47 | } |
| 48 | r, w := rune(S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.[S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset.]), 1 |
| 49 | if r == 0 { |
| 50 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos., "illegal character NUL") |
| 51 | } else if r >= 80 { |
| 52 | // not ASCII |
| 53 | r, w = utf8scip-go gomod github.com/golang/go/src go1.24 `unicode/utf8`/.DecodeRunescip-go gomod github.com/golang/go/src go1.24 `unicode/utf8`/DecodeRune().(S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.[S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset.:]) |
| 54 | if r == utf8scip-go gomod github.com/golang/go/src go1.24 `unicode/utf8`/.RuneErrorscip-go gomod github.com/golang/go/src go1.24 `unicode/utf8`/RuneError. && w == 1 { |
| 55 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos., "illegal UTF-8 encoding") |
| 56 | } |
| 57 | } |
| 58 | S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset. += w |
| 59 | S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. = r |
| 60 | } else { |
| 61 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset. = len(S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.) |
| 62 | S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. = -1 // eof |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // The mode parameter to the Init function is a set of flags (or 0). |
| 67 | // They control scanner behavior. |
| 68 | const ( |
| 69 | ScanCommentsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/ScanComments. = 1 << iota // return comments as COMMENT tokens |
| 70 | AllowIllegalCharsscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/AllowIllegalChars. // do not report an error for illegal chars |
| 71 | InsertSemisscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/InsertSemis. // automatically insert semicolons |
| 72 | ) |
| 73 | |
| 74 | // Init prepares the scanner S to tokenize the text src. Calls to Scan |
| 75 | // will use the error handler err if they encounter a syntax error and |
| 76 | // err is not nil. Also, for each error encountered, the Scanner field |
| 77 | // ErrorCount is incremented by one. The filename parameter is used as |
| 78 | // filename in the token.Position returned by Scan for each token. The |
| 79 | // mode parameter determines how comments and illegal characters are |
| 80 | // handled. |
| 81 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) Initscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#Init().(src []byte, tokenMap *tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.TokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#) { |
| 82 | // Explicitly initialize all fields since a scanner may be reused. |
| 83 | S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src. = src |
| 84 | S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap. = tokenMap |
| 85 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos. = tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#{Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.: 0, Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Line.: 1, Columnscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Column.: 0} |
| 86 | S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset. = 0 |
| 87 | S.ErrorCountscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ErrorCount. = 0 |
| 88 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 89 | } |
| 90 | |
| 91 | func charStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/charString().(ch rune) string { |
| 92 | var s string |
| 93 | switch ch { |
| 94 | case -1: |
| 95 | return "EOF" |
| 96 | case '\a': |
| 97 | s = "\\a" |
| 98 | case '\b': |
| 99 | s = "\\b" |
| 100 | case '\f': |
| 101 | s = "\\f" |
| 102 | case '\n': |
| 103 | s = "\\n" |
| 104 | case '\r': |
| 105 | s = "\\r" |
| 106 | case '\t': |
| 107 | s = "\\t" |
| 108 | case '\v': |
| 109 | s = "\\v" |
| 110 | case '\\': |
| 111 | s = "\\\\" |
| 112 | case '\'': |
| 113 | s = "\\'" |
| 114 | default: |
| 115 | s = string(ch) |
| 116 | } |
| 117 | return "'" + s + "' (U+" + strconvscip-go gomod github.com/golang/go/src go1.24 strconv/.FormatIntscip-go gomod github.com/golang/go/src go1.24 strconv/FormatInt().(int64(ch), 16) + ")" |
| 118 | } |
| 119 | |
| 120 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#, msg string) { |
| 121 | S.ErrorCountscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ErrorCount.++ |
| 122 | } |
| 123 | |
| 124 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) expectscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#expect().(ch rune) { |
| 125 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != ch { |
| 126 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos., "expected "+charStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/charString().(ch)+", found "+charStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/charString().(S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch.)) |
| 127 | } |
| 128 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() // always make progress |
| 129 | } |
| 130 | |
| 131 | var prefixscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/prefix. = []byte("line ") |
| 132 | |
| 133 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanCommentscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanComment().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) { |
| 134 | // first '/' already consumed |
| 135 | |
| 136 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '/' { |
| 137 | //-style comment |
| 138 | for S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. >= 0 { |
| 139 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 140 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '\n' { |
| 141 | // '\n' is not part of the comment for purposes of scanning |
| 142 | // (the comment ends on the same line where it started) |
| 143 | if pos.Columnscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Column. == 1 { |
| 144 | text := S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.[pos.Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.+2 : S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.] |
| 145 | if bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.HasPrefixscip-go gomod github.com/golang/go/src go1.24 bytes/HasPrefix().(text, prefixscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/prefix.) { |
| 146 | // comment starts at beginning of line with "//line "; |
| 147 | // get filename and line number, if any |
| 148 | i := bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.Indexscip-go gomod github.com/golang/go/src go1.24 bytes/Index().(text, []byte{':'}) |
| 149 | if i >= 0 { |
| 150 | if line, err := strconvscip-go gomod github.com/golang/go/src go1.24 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.24 strconv/Atoi().(string(text[i+1:])); err == nil && line > 0 { |
| 151 | // valid //line filename:line comment; |
| 152 | // update scanner position |
| 153 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Line. = line - 1 // -1 since the '\n' has not been consumed yet |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | return |
| 159 | } |
| 160 | } |
| 161 | } else { |
| 162 | // / *-style comment * / |
| 163 | S.expectscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#expect().('*') |
| 164 | for S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. >= 0 { |
| 165 | ch := S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. |
| 166 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 167 | if ch == '*' && S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '/' { |
| 168 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 169 | return |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "comment not terminated") |
| 175 | } |
| 176 | |
| 177 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) findNewlinescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#findNewline().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) bool { |
| 178 | // first '/' already consumed; assume S.ch == '/' || S.ch == '*' |
| 179 | |
| 180 | // read ahead until a newline or non-comment token is found |
| 181 | newline := false |
| 182 | for pos1 := pos; S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. >= 0; { |
| 183 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '/' { |
| 184 | //-style comment always contains a newline |
| 185 | newline = true |
| 186 | break |
| 187 | } |
| 188 | S.scanCommentscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanComment().(pos1) |
| 189 | if pos1.Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Line. < S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Linescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Line. { |
| 190 | // / *-style comment contained a newline * / |
| 191 | newline = true |
| 192 | break |
| 193 | } |
| 194 | S.skipWhitespacescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#skipWhitespace().() // S.insertSemi is set |
| 195 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '\n' { |
| 196 | newline = true |
| 197 | break |
| 198 | } |
| 199 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != '/' { |
| 200 | // non-comment token |
| 201 | break |
| 202 | } |
| 203 | pos1 = S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos. |
| 204 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 205 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != '/' && S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != '*' { |
| 206 | // non-comment token |
| 207 | break |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // reset position to where it was upon calling findNewline |
| 212 | S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos. = pos |
| 213 | S.offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#offset. = pos.Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset. + 1 |
| 214 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 215 | |
| 216 | return newline |
| 217 | } |
| 218 | |
| 219 | func isLetterscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/isLetter().(ch rune) bool { |
| 220 | return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || |
| 221 | ch >= 0x80 && unicodescip-go gomod github.com/golang/go/src go1.24 unicode/.IsLetterscip-go gomod github.com/golang/go/src go1.24 unicode/IsLetter().(ch) || ch == '_' |
| 222 | } |
| 223 | |
| 224 | func isDigitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/isDigit().(ch rune) bool { |
| 225 | return '0' <= ch && ch <= '9' || ch >= 0x80 && unicodescip-go gomod github.com/golang/go/src go1.24 unicode/.IsDigitscip-go gomod github.com/golang/go/src go1.24 unicode/IsDigit().(ch) |
| 226 | } |
| 227 | |
| 228 | func digitValscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/digitVal().(ch rune) int { |
| 229 | switch { |
| 230 | case '0' <= ch && ch <= '9': |
| 231 | return int(ch) - '0' |
| 232 | case 'a' <= ch && ch <= 'f': |
| 233 | return int(ch) - 'a' + 10 |
| 234 | case 'A' <= ch && ch <= 'F': |
| 235 | return int(ch) - 'A' + 10 |
| 236 | } |
| 237 | return 16 // larger than any legal digit val |
| 238 | } |
| 239 | |
| 240 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanEscapescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanEscape().(quote rune) { |
| 241 | pos := S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos. |
| 242 | |
| 243 | var i, base, max uint32 |
| 244 | switch S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. { |
| 245 | case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', quote: |
| 246 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 247 | return |
| 248 | case '0', '1', '2', '3', '4', '5', '6', '7': |
| 249 | i, base, max = 3, 8, 255 |
| 250 | case 'x': |
| 251 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 252 | i, base, max = 2, 16, 255 |
| 253 | case 'u': |
| 254 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 255 | i, base, max = 4, 16, unicodescip-go gomod github.com/golang/go/src go1.24 unicode/.MaxRunescip-go gomod github.com/golang/go/src go1.24 unicode/MaxRune. |
| 256 | case 'U': |
| 257 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 258 | i, base, max = 8, 16, unicodescip-go gomod github.com/golang/go/src go1.24 unicode/.MaxRunescip-go gomod github.com/golang/go/src go1.24 unicode/MaxRune. |
| 259 | default: |
| 260 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() // always make progress |
| 261 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "unknown escape sequence") |
| 262 | return |
| 263 | } |
| 264 | |
| 265 | var x uint32 |
| 266 | for ; i > 0; i-- { |
| 267 | d := uint32(digitValscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/digitVal().(S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch.)) |
| 268 | if d > base { |
| 269 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos., "illegal character in escape sequence") |
| 270 | return |
| 271 | } |
| 272 | x = x*base + d |
| 273 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 274 | } |
| 275 | if x > max || 0xd800 <= x && x < 0xe000 { |
| 276 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "escape sequence is invalid Unicode code point") |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanCharscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanChar().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) { |
| 281 | // '\'' already consumed |
| 282 | |
| 283 | n := 0 |
| 284 | for S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != '\'' { |
| 285 | ch := S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. |
| 286 | n++ |
| 287 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 288 | if ch == '\n' || ch < 0 { |
| 289 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "character literal not terminated") |
| 290 | n = 1 |
| 291 | break |
| 292 | } |
| 293 | if ch == '\\' { |
| 294 | S.scanEscapescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanEscape().('\'') |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 299 | |
| 300 | if n != 1 { |
| 301 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "illegal character literal") |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanIdentifierscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanIdentifier().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type# { |
| 306 | ch0 := S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. |
| 307 | for isLetterscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/isLetter().(S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch.) || isDigitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/isDigit().(S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch.) || S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '!' { |
| 308 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 309 | } |
| 310 | switch { |
| 311 | case string(S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.[pos.Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.:S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.]) == "import": |
| 312 | return S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("import") |
| 313 | case ch0 == '!': |
| 314 | return S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("ignoredTokId") |
| 315 | case ch0 == '_': |
| 316 | return S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("regDefId") |
| 317 | case unicodescip-go gomod github.com/golang/go/src go1.24 unicode/.IsUpperscip-go gomod github.com/golang/go/src go1.24 unicode/IsUpper().(ch0): |
| 318 | return S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("prodId") |
| 319 | default: |
| 320 | return S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("tokId") |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | var ( |
| 325 | rw_CharLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/rw_CharLit. = []byte("char_lit") |
| 326 | rw_StringLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/rw_StringLit. = []byte("string_lit") |
| 327 | ) |
| 328 | |
| 329 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) isReservedWordscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#isReservedWord().(lit []byte) bool { |
| 330 | return bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.Equalscip-go gomod github.com/golang/go/src go1.24 bytes/Equal().(lit, rw_CharLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/rw_CharLit.) || bytesscip-go gomod github.com/golang/go/src go1.24 bytes/.Equalscip-go gomod github.com/golang/go/src go1.24 bytes/Equal().(lit, rw_StringLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/rw_StringLit.) |
| 331 | } |
| 332 | |
| 333 | // func (S *Scanner) scanInteger() { |
| 334 | // if !isDigit(S.ch) { S.error(S.pos, "integer index expected") } |
| 335 | // |
| 336 | // |
| 337 | // for S.next(); isDigit(S.ch); S.next() {} |
| 338 | // } |
| 339 | |
| 340 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanNumberscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanNumber().() tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type# { |
| 341 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '-' { |
| 342 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 343 | } |
| 344 | for isDigitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/isDigit().(S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch.) { |
| 345 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 346 | } |
| 347 | return S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("int_lit") |
| 348 | } |
| 349 | |
| 350 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanSDTLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanSDTLit().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) { |
| 351 | // '<' already consumed |
| 352 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() // consume second < |
| 353 | for cmp := false; !cmp; { |
| 354 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. < 0 { |
| 355 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "SDT not terminated") |
| 356 | break |
| 357 | } |
| 358 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '>' { |
| 359 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 360 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '>' { |
| 361 | break |
| 362 | } |
| 363 | } |
| 364 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 365 | } |
| 366 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 367 | } |
| 368 | |
| 369 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanString().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) { |
| 370 | // '"' already consumed |
| 371 | |
| 372 | for S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != '"' { |
| 373 | ch := S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. |
| 374 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 375 | if ch == '\n' || ch < 0 { |
| 376 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "string not terminated") |
| 377 | break |
| 378 | } |
| 379 | if ch == '\\' { |
| 380 | S.scanEscapescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanEscape().('"') |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 385 | } |
| 386 | |
| 387 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) scanRawStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanRawString().(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) { |
| 388 | // '\140' already consumed |
| 389 | |
| 390 | for S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. != '\140' { |
| 391 | ch := S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. |
| 392 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 393 | if ch < 0 { |
| 394 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "string not terminated") |
| 395 | break |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 400 | } |
| 401 | |
| 402 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) skipWhitespacescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#skipWhitespace().() { |
| 403 | for S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == ' ' || S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '\t' || S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '\n' || S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '\r' { |
| 404 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // Helper functions for scanning multi-byte tokens such as >> += >>= . |
| 409 | // Different routines recognize different length tok_i based on matches |
| 410 | // of ch_i. If a token ends in '=', the result is tok1 or tok3 |
| 411 | // respectively. Otherwise, the result is tok0 if there was no other |
| 412 | // matching character, or tok2 if the matching character was ch2. |
| 413 | |
| 414 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) switch2scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#switch2().(tok0, tok1 tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type#) tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type# { |
| 415 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '=' { |
| 416 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 417 | return tok1 |
| 418 | } |
| 419 | return tok0 |
| 420 | } |
| 421 | |
| 422 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) switch3scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#switch3().(tok0, tok1 tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type#, ch2 rune, tok2 tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type#) tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type# { |
| 423 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '=' { |
| 424 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 425 | return tok1 |
| 426 | } |
| 427 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == ch2 { |
| 428 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 429 | return tok2 |
| 430 | } |
| 431 | return tok0 |
| 432 | } |
| 433 | |
| 434 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) switch4scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#switch4().(tok0, tok1 tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type#, ch2 rune, tok2, tok3 tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type#) tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Type# { |
| 435 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '=' { |
| 436 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 437 | return tok1 |
| 438 | } |
| 439 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == ch2 { |
| 440 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 441 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '=' { |
| 442 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 443 | return tok3 |
| 444 | } |
| 445 | return tok2 |
| 446 | } |
| 447 | return tok0 |
| 448 | } |
| 449 | |
| 450 | var semicolonscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/semicolon. = []byte{';'} |
| 451 | |
| 452 | // Scan scans the next token and returns the token position pos, |
| 453 | // the token tok, and the literal text lit corresponding to the |
| 454 | // token. The source end is indicated by token.EOF. |
| 455 | // |
| 456 | // For more tolerant parsing, Scan will return a valid token if |
| 457 | // possible even if a syntax error was encountered. Thus, even |
| 458 | // if the resulting token sequence contains no illegal tokens, |
| 459 | // a client may not assume that no error occurred. Instead it |
| 460 | // must check the scanner's ErrorCount or the number of calls |
| 461 | // of the error handler, if there was one installed. |
| 462 | func (S *Scannerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#) Scanscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#Scan().() (*tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Token#, tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#) { |
| 463 | scanAgain: |
| 464 | S.skipWhitespacescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#skipWhitespace().() |
| 465 | |
| 466 | // current token start |
| 467 | pos, tok := S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos., tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.ILLEGALscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/ILLEGAL. |
| 468 | |
| 469 | // determine token value |
| 470 | switch ch := S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch.; { |
| 471 | case ch == '!' || isLetterscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/isLetter().(ch): |
| 472 | tok = S.scanIdentifierscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanIdentifier().(pos) |
| 473 | default: |
| 474 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() // always make progress |
| 475 | switch ch { |
| 476 | case -1: |
| 477 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("␚") |
| 478 | case '"': |
| 479 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("string_lit") |
| 480 | S.scanStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanString().(pos) |
| 481 | case '\'': |
| 482 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("char_lit") |
| 483 | S.scanCharscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanChar().(pos) |
| 484 | case '\140': |
| 485 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("string_lit") |
| 486 | S.scanRawStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanRawString().(pos) |
| 487 | case '-': |
| 488 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("-") |
| 489 | case '{': |
| 490 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("{") |
| 491 | case '}': |
| 492 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("}") |
| 493 | case ':': |
| 494 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().(":") |
| 495 | case ';': |
| 496 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().(";") |
| 497 | case ',': |
| 498 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().(",") |
| 499 | case '[': |
| 500 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("[") |
| 501 | case ']': |
| 502 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("]") |
| 503 | case '(': |
| 504 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("(") |
| 505 | case ')': |
| 506 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().(")") |
| 507 | case '|': |
| 508 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("|") |
| 509 | case '/': |
| 510 | if S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '/' || S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. == '*' { |
| 511 | // comment |
| 512 | S.scanCommentscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanComment().(pos) |
| 513 | goto scanAgain |
| 514 | } else { |
| 515 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("/") |
| 516 | } |
| 517 | case '<': |
| 518 | switch S.chscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#ch. { |
| 519 | case '<': |
| 520 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("g_sdt_lit") |
| 521 | S.scanSDTLitscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#scanSDTLit().(pos) |
| 522 | case '=': |
| 523 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("<=") |
| 524 | S.nextscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#next().() |
| 525 | default: |
| 526 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().("<") |
| 527 | } |
| 528 | case '.': |
| 529 | tok = S.tokenMapscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#tokenMap..Typescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/TokenMap#Type().(".") |
| 530 | default: |
| 531 | S.errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#error().(pos, "illegal character "+charStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/charString().(ch)) |
| 532 | } |
| 533 | } |
| 534 | return tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.NewTokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/NewToken().(tok, S.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#src.[pos.Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.:S.posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Scanner#pos..Offsetscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#Offset.]), pos |
| 535 | } |
| 536 | |
| 537 | // An implementation of an ErrorHandler may be provided to the Scanner. |
| 538 | // If a syntax error is encountered and a handler was installed, Error |
| 539 | // is called with a position and an error message. The position points |
| 540 | // to the beginning of the offending token. |
| 541 | type ErrorHandlerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/ErrorHandler# interface { |
| 542 | Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/ErrorHandler#Error.(pos tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#, msg string) |
| 543 | } |
| 544 | |
| 545 | // Within ErrorVector, an error is represented by an Error node. The |
| 546 | // position Pos, if valid, points to the beginning of the offending |
| 547 | // token, and the error condition is described by Msg. |
| 548 | type Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error# struct { |
| 549 | Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#Pos. tokenscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/.Positionscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position# |
| 550 | Msgscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#Msg. string |
| 551 | } |
| 552 | |
| 553 | func (e *Errorscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#) Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#String().() string { |
| 554 | if e.Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#Pos..IsValidscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#IsValid().() { |
| 555 | // don't print "<unknown position>" |
| 556 | return e.Posscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#Pos..Stringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/token`/Position#String().() + ": " + e.Msgscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#Msg. |
| 557 | } |
| 558 | return e.Msgscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/internal/frontend/scanner`/Error#Msg. |
| 559 | } |