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)
| 132 | // defer result.Release() |
| 133 | // fmt.Printf("parsed %d statements with %d errors\n", len(result.Statements), len(result.Errors)) |
| 134 | func 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. |