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

Method parse

pkg/sql/plpgsql/parser/parse.go:99–133  ·  view source on GitHub ↗

parse parses a statement from the given scanned tokens.

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

Source from the content-addressed store, hash-verified

97
98// parse parses a statement from the given scanned tokens.
99func (p *Parser) parse(
100 depth int, sql string, tokens []plpgsqlSymType, nakedIntType *types.T,
101) (statements.PLpgStatement, error) {
102 p.lexer.init(sql, tokens, nakedIntType, &p.parserImpl)
103 defer p.lexer.cleanup()
104 if p.parserImpl.Parse(&p.lexer) != 0 {
105 if p.lexer.lastError == nil {
106 // This should never happen -- there should be an error object
107 // every time Parse() returns nonzero. We're just playing safe
108 // here.
109 p.lexer.Error("syntax error")
110 }
111 err := p.lexer.lastError
112
113 // Compatibility with 19.1 telemetry: prefix the telemetry keys
114 // with the "syntax." prefix.
115 // TODO(knz): move the auto-prefixing of feature names to a
116 // higher level in the call stack.
117 tkeys := errors.GetTelemetryKeys(err)
118 if len(tkeys) > 0 {
119 for i := range tkeys {
120 tkeys[i] = "syntax." + tkeys[i]
121 }
122 err = errors.WithTelemetry(err, tkeys...)
123 }
124
125 return statements.PLpgStatement{}, err
126 }
127 return statements.PLpgStatement{
128 AST: p.lexer.stmt,
129 SQL: sql,
130 NumPlaceholders: p.lexer.numPlaceholders,
131 NumAnnotations: p.lexer.numAnnotations,
132 }, nil
133}
134
135// Parse parses a sql statement string and returns a list of Statements.
136func Parse(sql string) (statements.PLpgStatement, error) {

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