Grip.Error: the parser result type and parse errors #
ParseResult α is the result of running a parser at an offset: ok value newOffset or
error e. One constructor holds the value and offset inline, so a successful step
allocates a single object.
Err is the error value carried by ParseResult.error. GParser proves that its byte offset
lies between the parser's starting offset and the end of the input. Built-in choice additionally
uses it to report the furthest failure and the labels expected there; that stronger diagnostic
convention is not part of the parser contract.
ParseError is the user-facing error produced by GParser.parse; it adds
1-based line and col computed from the source bytes.
Nothing in this file imports from Grip; only core Lean / Batteries.
The error value carried by ParseResult.error.
For every GParser run started in bounds, pos lies between that starting offset and the end of
the input. Built-in combinators use pos for the furthest byte offset reached during parsing and
expected for labels attached by label/<?>; the type does not prove that either diagnostic is
maximal or complete.
- pos : Nat
Diagnostic offset used by built-in failure merging.
Labels expected at
posin built-in diagnostics.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Grip.instReprErr = { reprPrec := Grip.instReprErr.repr }
Equations
- Grip.instBEqErr = { beq := Grip.instBEqErr.beq }
Equations
- Grip.instInhabitedErr = { default := Grip.instInhabitedErr.default }
The result of running a parser at an offset: ok value newOffset or error with a
diagnostic. One constructor holds the value and the new offset inline, so a
successful step allocates a single object rather than an Except.ok wrapping a Prod
(the representation Except Err (α × Nat) used before).
- ok
{α : Type}
(value : α)
(newOffset : Nat)
: ParseResult α
Success: the parsed
valueand thenewOffsetreached. - error
{α : Type}
: Err → ParseResult α
Failure carrying an
Err; built-in combinators retain the furthest one they observe.
Instances For
Equations
- Grip.instInhabitedParseResult = { default := Grip.ParseResult.error default }
Equations
- Grip.instReprParseError = { reprPrec := Grip.instReprParseError.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Equations
- e.message = match Grip.uniqueStrings✝ e.expected with | [] => "unexpected input" | xs => "expected " ++ " or ".intercalate xs
Instances For
Render a dependency-free plain fallback as line:col: message, followed by the offending
source line and a caret (^). Rich terminal presentation belongs to grip-diagnostics.
Equations
- One or more equations did not get rendered due to their size.