Parser utils for ReaderT and StateT
@[reducible, inline]
Equations
Instances For
@[implicit_reducible]
instance
Parser.Parser.coeSimpleParser
{α ρ σ : Type}
:
Coe (SimpleCharParser α) (ReaderT ρ (StateT σ SimpleCharParser) α)
Equations
- Parser.Parser.coeSimpleParser = { coe := fun (p : Parser.SimpleCharParser α) (x : ρ) (σ_1 : σ) => do let __do_lift ← p pure (__do_lift, σ_1) }
def
Parser.attemptM
{ρ σ α : Type}
(p : ReaderT ρ (StateT σ SimpleCharParser) α)
:
ReaderT ρ (StateT σ SimpleCharParser) α
extends Lean.Parser.attempt
Equations
- Parser.attemptM p f = do let __do_lift ← get let __discr ← liftM (Parser.withBacktracking (p f __do_lift)) match __discr with | (a, s) => do set s pure a
Instances For
Equations
Instances For
Returns a natural number measure of remaining input. see https://github.com/fgdorais/lean4-parser/pull/99
- remaining : σ → Nat
Instances
@[implicit_reducible]
Equations
- Parser.instRemainingSlice = { remaining := fun (s : String.Slice) => s.utf8ByteSize }
@[irreducible]
def
Parser.loop
{ρ σ α : Type}
(p : ReaderT ρ (StateT σ SimpleCharParser) α → ReaderT ρ (StateT σ SimpleCharParser) α)
:
ReaderT ρ (StateT σ SimpleCharParser) α
The recursive function loop calls p with a parser that acts like p
except it fails if called from the same or lower string position
see https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/Advent.20of.20Code.3F/near/405471085
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Parser.manyM
{ρ σ α : Type}
(p : ReaderT ρ (StateT σ SimpleCharParser) α)
:
ReaderT ρ (StateT σ SimpleCharParser) (Array α)
Equations
- Parser.manyM p = do let __do_lift ← read liftM (Parser.foldM✝ (p __do_lift) #[])
Instances For
Equations
Instances For
def
Parser.withPosM
{ρ σ α : Type}
(p : ReaderT ρ (StateT σ SimpleCharParser) α)
:
ReaderT ρ (StateT σ SimpleCharParser) (String.Pos.Raw × String.Pos.Raw × α)
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- Parser.skipChar? c = tryCatch (Parser.skipChar c) fun (x : Parser.Error.Simple String.Slice Char) => pure ()
Instances For
Equations
- Parser.skipString tks = Parser.Char.chars tks *> pure ()
Instances For
Equations
- Parser.skipString? tks = tryCatch (Parser.withBacktracking (Parser.skipString tks)) fun (x : Parser.Error.Simple String.Slice Char) => pure ()
Instances For
exec check on current char and consume char on success
Equations
- One or more equations did not get rendered due to their size.
Instances For
exec check on current char and skip char on success
Equations
- Parser.trySkipChar check = do let __do_lift ← Parser.tryChar check match __do_lift with | some val => pure true | x => pure false
Instances For
exec check on current char and then exec p on success
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Parser.tryCharThenPWithPosM
{ρ σ α : Type}
(check : Char → Bool)
(p : ReaderT ρ (StateT σ SimpleCharParser) α)
:
ReaderT ρ (StateT σ SimpleCharParser) (Option (String.Pos.Raw × String.Pos.Raw × α))
exec check on current char and then exec p on success
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Parser.tryCharWithPosMap
{α : Type}
(check : Char → Bool)
(f : Char → String.Pos.Raw → String.Pos.Raw → α)
:
Equations
Instances For
Equations
- Parser.manyChars p = do let chars ← Parser.fold✝ p #[] pure (String.ofList chars.toList)
Instances For
Equations
- Parser.many1Chars p = do let __do_lift ← p let chars ← Parser.fold✝ p #[__do_lift] pure (String.ofList chars.toList)