Module Wax_wasm.ParsingSource

Generic parsing utilities.

Exception raised when a syntax error occurs, with location range and message.

Sourcetype syntax_error = {
  1. location : Wax_utils.Ast.location;
  2. message : Wax_utils.Message.t;
  3. related : Wax_utils.Diagnostic.label list;
}

A syntax error returned as data by parse_diagnostics: the location range, the human-readable message, and any related labels (e.g. the matching opening delimiter).

Sourcetype sync_class =
  1. | Open
  2. | Close
  3. | Boundary
  4. | Leader
  5. | Terminal
  6. | Skip
    (*

    How the panic-mode recovery of Make.parse_recover treats a token when it is scanning for a place to resynchronize. The skip is nesting-aware: it tracks the bracket depth entered while skipping so a boundary belonging to a group opened inside the skipped span does not resynchronize the enclosing construct.

    • Open — an opening bracket. Descends one nesting level; never itself a resync point.
    • Close — a closing bracket. At the outer level (depth 0) it is a resync point closing an enclosing construct; otherwise it ascends one level (matching an Open met while skipping) and scanning continues.
    • Boundary — a non-bracket resync point (typically a statement separator), counted only at the outer level, like a Close. Recovery stops there, unwinds the parser stack to the closest state that can shift it, shifts it, and resumes.
    • Leader — a resync point valid at any depth: an item/statement-leading keyword. Recovery stops at one even inside an unbalanced opener, so a stray bracket cannot swallow the next top-level item.
    • Terminal — the end-of-input token. Recovery stops at it but never discards it; if no stacked state can accept it, parsing gives up (the best-effort AST is then absent).
    • Skip — anything else: discarded while scanning for the next boundary.
    *)
Sourcemodule Make (Output : sig ... end) (Tokens : sig ... end) (_ : sig ... end) (_ : sig ... end) (_ : sig ... end) : sig ... end

Core parser over a Menhir incremental API, without the fast parser. The incremental parser produces both the AST and, via Parser_messages, the error in a single pass, so this is all an in-process consumer that only wants parse_diagnostics needs. See Make_parser for the fast-path variant.

Sourcemodule Make_parser (Output : sig ... end) (Tokens : sig ... end) (_ : sig ... end) (_ : sig ... end) (_ : sig ... end) (_ : sig ... end) : sig ... end

Make plus a fast parser, whose only role is speed on the happy path: parse_from_string tries it and, on a syntax error, falls back to the core's incremental parser to produce the message. Same result signature as Make. The CLI uses this; an in-process consumer can use Make directly.