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

Method parse

pkg/sql/parser/parse.go:175–211  ·  view source on GitHub ↗

parse parses a statement from the given scanned tokens.

(
	depth int, sql string, tokens []sqlSymType, nakedIntType *types.T,
)

Source from the content-addressed store, hash-verified

173
174// parse parses a statement from the given scanned tokens.
175func (p *Parser) parse(
176 depth int, sql string, tokens []sqlSymType, nakedIntType *types.T,
177) (statements.Statement[tree.Statement], error) {
178 p.lexer.init(sql, tokens, nakedIntType)
179 defer p.lexer.cleanup()
180 if p.parserImpl.Parse(&p.lexer) != 0 {
181 if p.lexer.lastError == nil {
182 // This should never happen -- there should be an error object
183 // every time Parse() returns nonzero. We're just playing safe
184 // here.
185 p.lexer.Error("syntax error")
186 }
187 err := p.lexer.lastError
188
189 // Compatibility with 19.1 telemetry: prefix the telemetry keys
190 // with the "syntax." prefix.
191 // TODO(knz): move the auto-prefixing of feature names to a
192 // higher level in the call stack.
193 tkeys := errors.GetTelemetryKeys(err)
194 if len(tkeys) > 0 {
195 for i := range tkeys {
196 tkeys[i] = "syntax." + tkeys[i]
197 }
198 err = errors.WithTelemetry(err, tkeys...)
199 }
200
201 return statements.Statement[tree.Statement]{}, err
202 }
203
204 return statements.Statement[tree.Statement]{
205 AST: p.lexer.stmt,
206 SQL: sql,
207 Comments: p.scanner.Comments,
208 NumPlaceholders: p.lexer.numPlaceholders,
209 NumAnnotations: p.lexer.numAnnotations,
210 }, nil
211}
212
213// unaryNegation constructs an AST node for a negation. This attempts
214// to preserve constant NumVals and embed the negative sign inside

Callers 1

parseWithDepthMethod · 0.95

Calls 4

initMethod · 0.65
ParseMethod · 0.65
ErrorMethod · 0.65
cleanupMethod · 0.45

Tested by

no test coverage detected