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

Function ParseMultiWithRecovery

pkg/sql/parser/recovery.go:134–147  ·  view source on GitHub ↗

ParseMultiWithRecovery obtains a parser from the pool and parses a token stream, recovering from errors to collect multiple errors and return a partial AST. Unlike Parse(), which stops at the first error, this function uses synchronization tokens (semicolons and statement-starting keywords) to skip

(tokens []token.Token)

Source from the content-addressed store, hash-verified

132// defer result.Release()
133// fmt.Printf("parsed %d statements with %d errors\n", len(result.Statements), len(result.Errors))
134func ParseMultiWithRecovery(tokens []token.Token) *RecoveryResult {
135 // Wrap legacy token.Token into models.TokenWithSpan for the unified path.
136 wrapped := make([]models.TokenWithSpan, len(tokens))
137 for i, t := range tokens {
138 wrapped[i] = models.WrapToken(models.Token{Type: t.Type, Value: t.Literal})
139 }
140 p := GetParser()
141 stmts, errs := p.parseWithRecovery(preprocessTokens(wrapped))
142 return &RecoveryResult{
143 Statements: stmts,
144 Errors: errs,
145 parser: p,
146 }
147}
148
149// ParseWithRecovery parses a token stream, recovering from errors to collect multiple
150// errors and return a partial AST with successfully parsed statements.

Calls 4

WrapTokenFunction · 0.92
GetParserFunction · 0.85
preprocessTokensFunction · 0.85
parseWithRecoveryMethod · 0.80