Parse with panic-mode error recovery, collecting every syntax error instead of stopping at the first. On each error the parser stack is resynchronized: tokens are discarded up to the next boundary (as classified by sync), the stack is unwound to the closest state that can shift that boundary, the boundary is shifted, and parsing resumes; see sync_class. A lexer error (bad character, malformed byte) is likewise recorded and skipped, so a stray character does not truncate the parse. Returns the best-effort AST (Some ast if parsing reached an accepting state, None if recovery could not), the errors in source order, and the trivia context. Nothing is printed. Intended for in-process consumers such as a language server that must report all errors and keep a partial AST across them.
insert is a list of candidate tokens (each (token, diagnostic, move_pos, source_text): the token to insert, the diagnostic to report, whether to place the caret at the previous token's end rather than the offending token, and the token's source spelling used as the derived quick fix's new_text) that recovery may insert in front of an offending token instead of skipping to a boundary — a statement separator like ;, or a placeholder operand like a zero 0 that lets an incomplete construct complete. The candidates are tried in order; the engine's acceptable answers whether one fits, and the repair is kept only if the offending token then shifts too (validated, so a wrong guess is discarded); a validated repair also attaches source_text as a machine-applicable fix. Insertion is attempted at most once per source position, so it cannot loop; it falls back to skip-based recovery. The candidates also serve close_pending (e.g. completing an unclosed construct at EOF). Omit ([]) to disable insertion.
closers lists the closing-bracket tokens, each with its source spelling. At end of input inside an unclosed bracketed construct, recovery auto-closes: it inserts whichever of these the parser accepts (and, between them, the insert separator when a statement must be terminated first), repeatedly, until EOF is accepted, so the construct the user is still typing reduces into the best-effort AST instead of being unwound away and dropped. The syntax error is still reported; only the recovered AST improves. When the auto-close used closers alone (no insert separator), the concatenation of their spellings is attached to that error as a machine-applicable fix — a single edit inserting the missing closers at the boundary. Omit to keep the unwind-and-discard behaviour.
barrier adapts recovery to a fully parenthesized grammar (WAT), which has no separator or leader token: a missing closer then surfaces not as an unclosed construct but as a new field offered where an instruction was expected. It is a triple — the ( token to re-offer, a predicate for a field keyword written after a bare ( (offered as the pair ( ; kw), and a predicate for a fused (type/(import/(export opener the lexer folds into one token (offered alone) — and lets recovery close the enclosing field and restart at the new one instead of letting paren-depth counting swallow the sibling; both predicates fire only at the enclosing level, so a field-like opener nested in skipped content is not mistaken for a field. Supplying barrier also enables group-drop: when a closer cannot be shifted because an inner group's production is incomplete and needs more than one token to repair (e.g. (v128.const)), the broken group is dropped whole and its enclosing field kept. Omit (the default) in a grammar with real separator/leader anchors (Wax), where neither applies.