MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / ParseBytesWithTokens

Function ParseBytesWithTokens

pkg/sql/parser/validate.go:119–142  ·  view source on GitHub ↗

ParseBytesWithTokens is like ParseBytes but also returns the preprocessed token slice ([]models.TokenWithSpan) for callers that need both.

(input []byte)

Source from the content-addressed store, hash-verified

117// ParseBytesWithTokens is like ParseBytes but also returns the preprocessed
118// token slice ([]models.TokenWithSpan) for callers that need both.
119func ParseBytesWithTokens(input []byte) (*ast.AST, []models.TokenWithSpan, error) {
120 tkz := tokenizer.GetTokenizer()
121 defer tokenizer.PutTokenizer(tkz)
122
123 tokens, err := tkz.Tokenize(input)
124 if err != nil {
125 return nil, nil, fmt.Errorf("tokenization error: %w", err)
126 }
127
128 if len(tokens) == 0 {
129 return nil, nil, goerrors.IncompleteStatementError(models.Location{}, "")
130 }
131
132 p := GetParser()
133 defer PutParser(p)
134
135 preprocessed := preprocessTokens(tokens)
136 astResult, parseErr := p.parseTokens(preprocessed)
137 if parseErr != nil {
138 return nil, nil, parseErr
139 }
140
141 return astResult, preprocessed, nil
142}
143
144// ValidateWithDialect checks whether the given SQL string is syntactically valid
145// using the specified SQL dialect for keyword recognition.

Callers 1

TestParseBytesWithTokensFunction · 0.92

Calls 8

GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
GetParserFunction · 0.85
PutParserFunction · 0.85
preprocessTokensFunction · 0.85
TokenizeMethod · 0.80
parseTokensMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestParseBytesWithTokensFunction · 0.74