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

Method ParseContext

pkg/sql/parser/parser.go:434–442  ·  view source on GitHub ↗

ParseContext parses tokens into an AST with context support for cancellation and timeouts. This method enables graceful cancellation of long-running parsing operations by checking the context at strategic points (statement boundaries and expression starts). The parser checks context.Err() approxima

(ctx context.Context, tokens []token.Token)

Source from the content-addressed store, hash-verified

432// ParseContext parses a slice of token.Token with context support (backward compat shim).
433// For new code prefer ParseContextFromModelTokens.
434func (p *Parser) ParseContext(ctx context.Context, tokens []token.Token) (*ast.AST, error) {
435 // Wrap legacy token.Token into models.TokenWithSpan.
436 wrapped := make([]models.TokenWithSpan, len(tokens))
437 for i, t := range tokens {
438 wrapped[i] = models.WrapToken(models.Token{Type: t.Type, Value: t.Literal})
439 }
440 preprocessed := preprocessTokens(wrapped)
441 return p.parseContextTokens(ctx, preprocessed)
442}
443
444// parseContextTokens is the core context-aware parsing routine. It takes
445// a preprocessed []models.TokenWithSpan and respects ctx for cancellation.

Calls 3

parseContextTokensMethod · 0.95
WrapTokenFunction · 0.92
preprocessTokensFunction · 0.85