package wax-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Wax_utils.ParsingSource

Generic parsing utilities.

Sourcetype syntax_error = {
  1. location : Ast.location;
  2. message : Message.t;
  3. related : Diagnostic.label list;
  4. hint : Message.t option;
  5. fix : Diagnostic.edit option;
}

A syntax error, both the payload of Syntax_error and the value parse_diagnostics / parse_recover return: the location range, the human-readable message, any related labels (e.g. the matching opening delimiter), an optional prose hint, and an optional machine-applicable quick fix (a text edit, reusing Diagnostic.edit so a syntax error's fix flows through the same editor/LSP code-action path as the typer's suggestions). Recovery derives a fix mechanically from an insertion repair (see Make.parse_recover).

Sourceexception Syntax_error of syntax_error

Raised when a syntax error occurs, carrying the structured payload above.

Sourceval syntax_error : location:Ast.location -> ?related:Diagnostic.label list -> ?hint:Message.t -> ?fix:Diagnostic.edit -> Message.t -> 'a

syntax_error ~location ?related ?hint ?fix message raises Syntax_error with the structured payload. Smart constructor used by every enriched raise site (the lexers and both grammars), so the payload shape is spelled once.

Sourceval syntax_error_pair : ((Lexing.position * Lexing.position) * Message.t) -> exn

syntax_error_pair ((loc_start, loc_end), message) builds (without raising) the Syntax_error value from the legacy position-pair payload, with no related/hint/fix. It keeps the many pre-existing raise (Syntax_error (pair, msg)) sites in the lexers and grammars a one-token change; new code should prefer the raising syntax_error.

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.