MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / scan

Method scan

pkg/sql/parser/scan.go:92–390  ·  view source on GitHub ↗
(lval *sqlSymType)

Source from the content-addressed store, hash-verified

90}
91
92func (s *scanner) scan(lval *sqlSymType) {
93 lval.id = 0
94 lval.pos = int32(s.pos)
95 lval.str = "EOF"
96
97 if _, ok := s.skipWhitespace(lval, true); !ok {
98 return
99 }
100
101 ch := s.next()
102 if ch == eof {
103 lval.pos = int32(s.pos)
104 return
105 }
106
107 lval.id = int32(ch)
108 lval.pos = int32(s.pos - 1)
109 lval.str = s.in[lval.pos:s.pos]
110
111 switch ch {
112 case '$':
113 // placeholder? $[0-9]+
114 if lex.IsDigit(s.peek()) {
115 s.scanPlaceholder(lval)
116 return
117 } else if s.scanDollarQuotedString(lval) {
118 lval.id = SCONST
119 return
120 }
121 return
122
123 case identQuote:
124 // "[^"]"
125 if s.scanString(lval, identQuote, false /* allowEscapes */, true /* requireUTF8 */) {
126 lval.id = IDENT
127 }
128 return
129
130 case singleQuote:
131 // '[^']'
132 if s.scanString(lval, ch, false /* allowEscapes */, true /* requireUTF8 */) {
133 lval.id = SCONST
134 }
135 return
136
137 case 'b':
138 // Bytes?
139 if s.peek() == singleQuote {
140 // b'[^']'
141 s.pos++
142 if s.scanString(lval, singleQuote, true /* allowEscapes */, false /* requireUTF8 */) {
143 lval.id = BCONST
144 }
145 return
146 }
147 s.scanIdent(lval)
148 return
149

Callers 4

SplitFirstStatementFunction · 0.80
TokensFunction · 0.80
LastLexicalTokenFunction · 0.80
scanOneStmtMethod · 0.80

Calls 13

skipWhitespaceMethod · 0.95
nextMethod · 0.95
peekMethod · 0.95
scanPlaceholderMethod · 0.95
scanStringMethod · 0.95
scanIdentMethod · 0.95
scanBitStringMethod · 0.95
scanHexStringMethod · 0.95
scanNumberMethod · 0.95
peekNMethod · 0.95
IsDigitFunction · 0.92

Tested by

no test coverage detected