Parser utils for ReaderT and StateT
@[simp]
@[simp]
theorem Parser.advanced_of_remaining (it rest : Std.Iter Char) (heq : rest.internalState.slice = it.internalState.slice) (hlt : remaining rest < remaining it) :
ParseIt.Advanced rest it
@[irreducible]
def Parser.loopTakeMany? {ρ σ β α : Type} (pre : ReaderT ρ (StateT σ SimpleCharParser) β) (post : β → Array α → ReaderT ρ (StateT σ SimpleCharParser) α) (alternative : ReaderT ρ (StateT σ SimpleCharParser) α) (hpre :
∀ (r : ρ) (st : σ) (it rest₁ : Std.Iter Char) (h₁ : ParseIt.Progress rest₁ it) (x : β × σ),
pre r st it = ParseIt.Result.ok rest₁ h₁ x → ParseIt.Advanced rest₁ it) :
ReaderT ρ (StateT σ SimpleCharParser) (Option α)
loopTakeMany corresponds to the following parser:
loop := (pre >>= fun x => StateT.takeMany loop >>= fun y => post x y) <|> alternative
It return a value iff there is no termination failure.
Instances For
theorem Parser.loopTakeMany?_eq_some {ρ σ β α : Type} (pre : ReaderT ρ (StateT σ SimpleCharParser) β) (post : β → Array α → ReaderT ρ (StateT σ SimpleCharParser) α) (alternative : ReaderT ρ (StateT σ SimpleCharParser) α) (hpre :
∀ (r : ρ) (st : σ) (it rest₁ : Std.Iter Char) (h₁ : ParseIt.Progress rest₁ it) (x : β × σ),
pre r st it = ParseIt.Result.ok rest₁ h₁ x → ParseIt.Advanced rest₁ it) {r : ρ} {st st' : σ} {it rest : Std.Iter Char} {h : ParseIt.Progress rest it} {a : Option α} (heq : loopTakeMany? pre post alternative hpre r st it = ParseIt.Result.ok rest h (a, st')) :
A successful loopManyM? always returns some.
def Parser.loopTakeMany {ρ σ β α : Type} (pre : ReaderT ρ (StateT σ SimpleCharParser) β) (post : β → Array α → ReaderT ρ (StateT σ SimpleCharParser) α) (alternative : ReaderT ρ (StateT σ SimpleCharParser) α) (hpre :
∀ (r : ρ) (st : σ) (it rest₁ : Std.Iter Char) (h₁ : ParseIt.Progress rest₁ it) (x : β × σ),
pre r st it = ParseIt.Result.ok rest₁ h₁ x → ParseIt.Advanced rest₁ it) :
ReaderT ρ (StateT σ SimpleCharParser) α
loopTakeMany corresponds to the following mutual recursive parser:
loop := (pre >>= fun x => StateT.takeMany loop >>= fun y => post x y) <|> alternative
with the property ParseIt.Advanced for parser pre which excludes termination failures