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

Function Inspect

pkg/sql/scanner/scan.go:1226–1259  ·  view source on GitHub ↗

Inspect analyses the string and returns the tokens found in it. If an incomplete token was encountered at the end, an InspectToken entry with ID -1 is appended. If a syntax error was encountered, it is returned as a token with type ERROR. See TestInspect and the examples in testdata/inspect for mo

(sql string)

Source from the content-addressed store, hash-verified

1224//
1225// See TestInspect and the examples in testdata/inspect for more details.
1226func Inspect(sql string) []InspectToken {
1227 var s SQLScanner
1228 var lval fakeSym
1229 var tokens []InspectToken
1230 s.Init(sql)
1231 for {
1232 s.Scan(&lval)
1233 tok := InspectToken{
1234 ID: lval.id,
1235 MaybeID: s.lastAttemptedID,
1236 Str: lval.s,
1237 Start: lval.pos,
1238 End: int32(s.pos),
1239 Quoted: s.quoted,
1240 }
1241
1242 // A special affordance for unterminated quoted identifiers: try
1243 // to find the normalized text of the identifier found so far.
1244 if lval.id == lexbase.ERROR && s.lastAttemptedID == lexbase.IDENT && s.quoted {
1245 maybeIdent := sql[tok.Start:tok.End] + "\""
1246 var si SQLScanner
1247 si.Init(maybeIdent)
1248 si.Scan(&lval)
1249 if lval.id == lexbase.IDENT {
1250 tok.Str = lval.s
1251 }
1252 }
1253
1254 tokens = append(tokens, tok)
1255 if lval.id == 0 || lval.id == lexbase.ERROR {
1256 return tokens
1257 }
1258 }
1259}

Callers

nothing calls this directly

Calls 2

ScanMethod · 0.95
InitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…