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)
| 432 | // ParseContext parses a slice of token.Token with context support (backward compat shim). |
| 433 | // For new code prefer ParseContextFromModelTokens. |
| 434 | func (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. |