MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Scan

Method Scan

pkg/sql/scanner/scan.go:169–496  ·  view source on GitHub ↗

Scan scans the next token and populates its information into lval.

(lval ScanSymType)

Source from the content-addressed store, hash-verified

167
168// Scan scans the next token and populates its information into lval.
169func (s *SQLScanner) Scan(lval ScanSymType) {
170 ch, skipWhiteSpace := s.scanSetup(lval, true /* allowComments */)
171
172 if skipWhiteSpace {
173 return
174 }
175
176 switch ch {
177 case '$':
178 // placeholder? $[0-9]+
179 if lexbase.IsDigit(s.peek()) {
180 s.scanPlaceholder(lval)
181 return
182 } else if s.scanDollarQuotedString(lval) {
183 lval.SetID(lexbase.SCONST)
184 return
185 }
186 return
187
188 case identQuote:
189 // "[^"]"
190 s.lastAttemptedID = int32(lexbase.IDENT)
191 s.quoted = true
192 if s.scanString(lval, identQuote, false /* allowEscapes */, true /* requireUTF8 */) {
193 lval.SetID(lexbase.IDENT)
194 }
195 return
196
197 case singleQuote:
198 // '[^']'
199 s.lastAttemptedID = int32(lexbase.SCONST)
200 if s.scanString(lval, ch, false /* allowEscapes */, true /* requireUTF8 */) {
201 lval.SetID(lexbase.SCONST)
202 }
203 return
204
205 case 'b':
206 // Bytes?
207 if s.peek() == singleQuote {
208 // b'[^']'
209 s.lastAttemptedID = int32(lexbase.BCONST)
210 s.pos++
211 if s.scanString(lval, singleQuote, true /* allowEscapes */, false /* requireUTF8 */) {
212 lval.SetID(lexbase.BCONST)
213 }
214 return
215 }
216 s.scanIdent(lval)
217 return
218
219 case 'r', 'R':
220 s.scanIdent(lval)
221 return
222
223 case 'e', 'E':
224 // Escaped string?
225 if s.peek() == singleQuote {
226 // [eE]'[^']'

Callers 9

scanOneMethod · 0.95
LastLexicalTokenFunction · 0.95
FirstLexicalTokenFunction · 0.95
InspectFunction · 0.95
SplitFirstStatementFunction · 0.45
TokensFunction · 0.45
scanOneStmtMethod · 0.45
mainFunction · 0.45
scanFnBlockMethod · 0.45

Calls 13

IsDigitFunction · 0.92
IsIdentStartFunction · 0.92
scanSetupMethod · 0.80
scanPlaceholderMethod · 0.80
scanBitStringMethod · 0.80
scanHexStringMethod · 0.80
peekNMethod · 0.80
SetIDMethod · 0.65
peekMethod · 0.45
scanStringMethod · 0.45
scanIdentMethod · 0.45

Tested by

no test coverage detected