ParseIt core #
Parsers read tokens from a pure iterator Std.Iter (α := ι) τ. The parser state is the iterator
itself, so backtracking is simply reusing an earlier iterator value.
Every successful parse reports its Progress: either the iterator did not move, or it moved
strictly forward along plausible successor steps. Proofs are erased at runtime, so Progress
compiles to a one-bit tag, and that tag is what allows repetition combinators to be total.
it' is reachable from it by one or more plausible successor steps.
Instances For
How far a parser moved the iterator from it to it'.
- stay {ι τ : Type u} [Std.Iterator ι Id τ] {it' it : Std.Iter τ} : it' = it → Progress it' it
The iterator did not move.
- moved {ι τ : Type u} [Std.Iterator ι Id τ] {it' it : Std.Iter τ} : Advanced it' it → Progress it' it
The iterator moved strictly forward.
Instances For
Whether the iterator moved.
Instances For
No progress.
Instances For
Compose progress.
Instances For
Parser result for a parse starting at iterator it.
- ok {ι τ : Type u} [Std.Iterator ι Id τ] {ε : Type u} {it : Std.Iter τ} {α : Type u} (rest : Std.Iter τ) (progress : Progress rest it) (value : α) : Result ε it α
Success, with the remaining iterator and the progress made.
- error {ι τ : Type u} [Std.Iterator ι Id τ] {ε : Type u} {it : Std.Iter τ} {α : Type u} (err : ε) : Result ε it α
Failure. No input is consumed on failure.
Instances For
ParserT ε ι τ m is a monad transformer to parse tokens of type τ from an iterator with internal
state ι, with error type ε.
Instances For
Run parser p on iterator it.
Instances For
Run parser p on iterator it.
Instances For
Run parser p on iterator it, returning the parsed value or the error.
Instances For
Positions and errors #
getPos returns the current input position. Consumes no input and never fails.
Instances For
withSpan p parses p and returns its result together with the input positions where p started
and stopped.
Instances For
Basic combinators #
notFollowedBy p succeeds only if p fails. Consumes no input.
Instances For
option family #
optionD p default tries to parse p and returns x if p returns x, otherwise returns the
monadic value default. This parser never fails.
Instances For
option! p tries to parse p and returns x if p returns x, otherwise returns
Inhabited.default. This parser never fails.
Instances For
first ps tries the parsers from the list ps in order until one succeeds and returns its result.
When all parsers fail, their errors are folded with combine, from left to right. The default is
Error.merge. When ps is empty, an unexpected input error at the current position is reported.