Parser result type.
- ok
{ε σ α : Type u}
: σ → α → Parser.Result ε σ α
Result: success!
- error
{ε σ α : Type u}
: σ → ε → Parser.Result ε σ α
Result: error!
Instances For
Equations
- Parser.instInhabitedResult = { default := Parser.Result.ok default default }
Equations
- Parser.instReprResult = { reprPrec := Parser.reprResult✝ }
ParserT ε σ τ
is a monad transformer to parse tokens of type τ
from the stream type σ
with
error type ε
.
Equations
- ParserT ε σ τ m α = (σ → m (Parser.Result ε σ α))
Instances For
Run the monadic parser p
on input stream s
.
Instances For
Equations
- instMonadParserT σ ε τ m = Monad.mk
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- instMonadLiftParserTOfMonad σ ε τ m = { monadLift := fun {α : Type ?u.62} (x : m α) (s : σ) => (fun (x : α) => Parser.Result.ok s x) <$> x }
Run parser p
on input stream s
.
Instances For
TrivialParserT σ τ
monad transformer to parse tokens of type τ
from the stream σ
with trivial
error handling.
Equations
- TrivialParserT σ τ m = ParserT Parser.Error.Trivial σ τ m
Instances For
TrivialParser σ τ
monad to parse tokens of type τ
from the stream σ
with trivial error
handling.
Equations
- TrivialParser σ τ = Parser Parser.Error.Trivial σ τ
Instances For
BasicParserT σ τ
monad transformer to parse tokens of type τ
from the stream σ
with basic
error handling.
Equations
- BasicParserT σ τ m = ParserT (Parser.Error.Basic σ τ) σ τ m
Instances For
BasicParser σ τ
monad to parse tokens of type τ
from the stream σ
with basic error handling.
Equations
- BasicParser σ τ = Parser (Parser.Error.Basic σ τ) σ τ
Instances For
SimpleParserT σ τ
monad transformer to parse tokens of type τ
from the stream σ
with simple
error handling.
Equations
- SimpleParserT σ τ m = ParserT (Parser.Error.Simple σ τ) σ τ m
Instances For
SimpleParser σ τ
monad to parse tokens of type τ
from the stream σ
with simple error handling.
Equations
- SimpleParser σ τ = Parser (Parser.Error.Simple σ τ) σ τ
Instances For
Stream Functions #
Get parser stream.
Equations
- Parser.getStream s = pure (Parser.Result.ok s s)
Instances For
Set parser stream.
Equations
- Parser.setStream s x✝ = pure (Parser.Result.ok s PUnit.unit)
Instances For
Get stream position from parser.
Instances For
Set stream position from parser.
Equations
- Parser.setPosition pos = do let __do_lift ← Parser.getStream Parser.setStream (Parser.Stream.setPosition __do_lift pos)
Instances For
withBacktracking p
parses p
but does not consume any input on error.
Equations
- Parser.withBacktracking p = do let savePos ← Parser.getPosition tryCatch p fun (e : ε) => do Parser.setPosition savePos throw e
Instances For
withCapture p
parses p
and returns the output of p
with the corresponding stream segment.
Equations
- Parser.withCapture p = do let startPos ← Parser.getPosition let x ← p let stopPos ← Parser.getPosition pure (x, startPos, stopPos)
Instances For
Error Functions #
Throw error on unexpected token.
Equations
- Parser.throwUnexpected input = do let __do_lift ← Parser.getPosition throw (Parser.Error.unexpected __do_lift input)
Instances For
Throw error with additional message.
Equations
- Parser.throwErrorWithMessage e msg = do let __do_lift ← Parser.getPosition throw (Parser.Error.addMessage e __do_lift msg)
Instances For
Throw error on unexpected token with error message.
Equations
- Parser.throwUnexpectedWithMessage input msg = do let __do_lift ← Parser.getPosition Parser.throwErrorWithMessage (Parser.Error.unexpected __do_lift input) msg
Instances For
Add message on parser error.
Equations
- Parser.withErrorMessage msg p = tryCatch p fun (e : ε) => Parser.throwErrorWithMessage e msg
Instances For
Low-Level Combinators #
foldlP f init p
folds the parser function f
from left to right using init
as an intitial
value and the parser p
to generate inputs of type α
. The folding ends as soon as the update
parser function (p >>= f ⬝)
fails. Then the final folding result is returned along with the pair:
(e, true)
if the finalp
succeeds but thenf
fails reporting errore
.(e, false)
if the finalp
fails reporting errore
.
In either case, the final p
is not consumed. This parser never fails.
Equations
- Parser.efoldlP f init p s = Parser.efoldlPAux✝ f p init s
Instances For
foldlM f init p
folds the monadic function f
from left to right using init
as an intitial
value and the parser p
to generate inputs of type α
. The folding ends as soon as p
fails and
the error reported by p
is returned along with the result of folding. This parser never fails.
Equations
Instances For
foldl f init p
folds the function f
from left to right using init
as an intitial value
and the parser p
to generate inputs of type α
. The folding ends as soon as p
fails and the
error reported by p
is returned along with the result of folding. This parser never fails.
Equations
- Parser.efoldl f init p = Parser.efoldlM (fun (y : β) (x : α) => pure (f y x)) init p
Instances For
foldlP f init p
folds the parser function f
from left to right using init
as an intitial
value and the parser p
to generate inputs of type α
. The folding ends as soon as the update
function (p >>= f ·)
fails. This parser never fails.
Equations
- Parser.foldlP f init p = Prod.fst <$> Parser.efoldlP f init p
Instances For
foldlM f init p
folds the monadic function f
from left to right using init
as an intitial
value and the parser p
to generate inputs of type α
. The folding ends as soon as p
fails.
This parser never fails.
Equations
- Parser.foldlM f init p = Prod.fst <$> Parser.efoldlM f init p
Instances For
foldl f init p
folds the function f
from left to right using init
as an intitial value and
the parser p
to generate inputs of type α
. The folding ends as soon as p
fails.
This parser never fails.
Equations
- Parser.foldl f init p = Prod.fst <$> Parser.efoldl f init p
Instances For
option
family #
eoption p
tries to parse p
(with backtracking) and returns:
This parser never fails.
Equations
- One or more equations did not get rendered due to their size.
Instances For
optionM p
tries to parse p
(with backtracking) and returns x
if p
returns x
, returns the
monadic value default
if p
fails. This parser never fails.
Equations
- Parser.optionM p default = do let __do_lift ← Parser.eoption p match __do_lift with | Sum.inl x => pure x | Sum.inr val => liftM default
Instances For
optionD p
tries to parse p
(with backtracking) and returns x
if p
returns x
, returns
default
if p
fails. This parser never fails.
Equations
- Parser.optionD p default = Parser.optionM p (pure default)
Instances For
option! p
tries to parse p
(with backtracking) and returns x
if p
returns x
, returns
Inhabited.default
if p
fails. This parser never fails.
Equations
Instances For
option? p
tries to parse p
and returns some x
if p
returns x
, returns none
if p
fails. This parser never fails.
Equations
- Parser.option? p = Parser.option! (some <$> p)
Instances For
optional p
tries to parse p
(with backtracking) ignoring output or errors. This parser never
fails.
Equations
- Parser.optional p = Parser.eoption p *> pure PUnit.unit
Instances For
efirst ps
tries parsers from the list ps
in order (with backtracking) until one succeeds:
- Once a parser
p
succeeds with valuex
thensome x
is returne along with the list of errors from all previous parsers. - If none succeed then
none
is returned along with the list of errors of all parsers.
This parser never fails.
Equations
- Parser.efirst ps = Parser.efirst.go ps []
Instances For
Equations
Instances For
first ps
tries parsers from the list ps
in order (with backtracking) until one succeeds and
returns the result of that parser.
The optional parameter combine
can be used to control the error reported when all parsers fail.
The default is to only report the error from the last parser.
Equations
- Parser.first ps combine = do let __do_lift ← Parser.getPosition Parser.first.go combine ps (Parser.Error.unexpected __do_lift none)
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Parser.first.go combine [] x✝¹ x✝ = pure (Parser.Result.error x✝ x✝¹)