Parser utils for SimpleCharParser
def Parser.pushResultStateT {ε ι τ σ α : Type u} [Std.Iterator ι Id τ] (it : Std.Iter τ) (post : α → (pair' : σ × Std.Iter τ) → ParseIt.Progress pair'.snd it → Prop) (epost : ε → Prop) :
ParseIt.Result ε it (α × σ) → Prop
Instances For
@[instance_reducible]
instance Parser.StateTParser.instWP {ε ι τ σ α : Type u} [Std.Iterator ι Id τ] :
Std.WP.WP (StateT σ (ParseIt.Parser ε ι τ) α) α (σ × ParseIt.IterWithProgress ι τ → Prop) (ε → Prop)
@[instance_reducible]
instance Parser.ReaderTStateTParser.instWP {ε ι τ σ ρ α : Type u} [Std.Iterator ι Id τ] :
Std.WP.WP (ReaderT ρ (StateT σ (ParseIt.Parser ε ι τ)) α) α (ρ × σ × ParseIt.IterWithProgress ι τ → Prop) (ε → Prop)
@[instance_reducible]
instance Parser.ReaderTStateTParser.instWPMonad {ε ι τ σ ρ : Type u} [Std.Iterator ι Id τ] :
Std.WP.WPMonad (ReaderT ρ (StateT σ (ParseIt.Parser ε ι τ))) (ρ × σ × ParseIt.IterWithProgress ι τ → Prop) (ε → Prop)
theorem Parser.ReaderTStateTParser.of_wp_eq {ε ι τ σ ρ α : Type u} [Std.Iterator ι Id τ] {pre : ρ × σ × ParseIt.IterWithProgress ι τ → Prop} {post : α → ρ × σ × ParseIt.IterWithProgress ι τ → Prop} {epost : ε → Prop} (x : ReaderT ρ (StateT σ (ParseIt.Parser ε ι τ)) α) (h : ⦃ pre ⦄ x ⦃ post; epost ⦄) (r : ρ) (st : σ) (it : Std.Iter τ) (hp : pre (r, st, ParseIt.IterWithProgress.refl it)) :
match x r st it with
| ParseIt.Result.ok s h a => post a.fst (r, a.snd, { it := it, rest := s, p := h })
| ParseIt.Result.error e => epost e
theorem Parser.Spec.ReaderTStateTParser.monadLift {ε ι τ σ ρ α : Type u} [Std.Iterator ι Id τ] {pre : ParseIt.IterWithProgress ι τ → Prop} {post : α → ParseIt.IterWithProgress ι τ → Prop} {epost : ε → Prop} (x : ParseIt.Parser ε ι τ α) (h : ⦃ pre ⦄ x ⦃ post; epost ⦄) (r : ρ) (st : σ) (it : Std.Iter τ) :
⦃ fun (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => s.it = it ∧ s.rest = it ∧ _r = r ∧ _st = st ∧ pre s ⦄ MonadLift.monadLift (MonadLiftT.monadLift x) ⦃ fun (a : α) (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => s.it = it ∧ post a s; epost ⦄
theorem Parser.Progress.trans_self {ι τ : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] (s s' : Std.Iter τ) (h1 : ParseIt.Progress s s') (h2 : ParseIt.Progress s' s') :
theorem Parser.Spec.ReaderTStateTParser.default_parser {ε ι τ σ ρ α : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] (x : ReaderT ρ (StateT σ (ParseIt.Parser ε ι τ)) α) (r : ρ) (st : σ) (it : Std.Iter τ) :
⦃ fun (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => s.it = it ∧ s.rest = it ∧ r = _r ∧ st = _st ⦄ x ⦃ fun (a : α) (x_1 : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x_1 with
| (_r, _st, s) => s.it = it ∧ x _r st s.it = ParseIt.Result.ok s.rest s.p (a, _st); fun (e : ε) => x r st it = ParseIt.Result.error e ⦄
theorem Parser.Spec.ReaderTStateTParser.read {ε ι τ σ ρ : Type u} [Std.Iterator ι Id τ] (r : ρ) (st : σ) (it : Std.Iter τ) :
⦃ fun (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => s.it = it ∧ s.rest = it ∧ _r = r ∧ _st = st ⦄ MonadReaderOf.read ⦃ fun (a : ρ) (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => a = r ∧ s.it = it ∧ s.rest = it ∧ _r = r ∧ _st = st; fun (x : ε) => False ⦄
theorem Parser.Spec.ReaderTStateTParser.get {ε ι τ σ ρ : Type u} [Std.Iterator ι Id τ] (r : ρ) (st : σ) (it : Std.Iter τ) :
⦃ fun (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => s.it = it ∧ s.rest = it ∧ _r = r ∧ _st = st ⦄ MonadLift.monadLift (MonadLiftT.monadLift MonadStateOf.get) ⦃ fun (a : σ) (x : ρ × σ × ParseIt.IterWithProgress ι τ) =>
match x with
| (_r, _st, s) => a = st ∧ s.it = it ∧ s.rest = it ∧ _r = r ∧ _st = st; fun (x : ε) => False ⦄
theorem Parser.Spec.ReaderTStateTParser.progress {ε ι τ σ ρ α : Type u} [Std.Iterator ι Id τ] (x : ReaderT ρ (StateT σ (ParseIt.Parser ε ι τ)) α) (it₀ it : Std.Iter τ) :
Any x started at it (with parse start it₀) never moves backwards from it.
theorem Parser.Spec.fail {α : Type} (msg : String) (it : Std.Iter Char) :
⦃ fun (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) => s.rest = it ⦄ Parser.fail msg ⦃ fun (x : α) (x_1 : ParseIt.IterWithProgress ParseIt.CharIterator Char) => False; fun (e : ParseIt.Error.Simple ParseIt.CharIterator) =>
e = ParseIt.Error.addMessage (ParseIt.Error.unexpected it none) it msg ⦄
Instances For
def Parser.StateT.efoldlP {ε ι τ : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] {β α σ : Type u} (f : β → α → StateT σ (ParseIt.Parser ε ι τ) β) (init : β) (p : StateT σ (ParseIt.Parser ε ι τ) α) :
StateT σ (ParseIt.Parser ε ι τ) (β × Option ε)
Instances For
@[irreducible]
def Parser.StateT.efoldlP.loop {ε ι τ : Type u} [Std.Iterator ι Id τ] {β α σ : Type u} [Std.Iterators.Finite ι Id] (f : β → α → StateT σ (ParseIt.Parser ε ι τ) β) (p : StateT σ (ParseIt.Parser ε ι τ) α) (s : σ) (it : Std.Iter τ) (y : β) (cur : Std.Iter τ) (hcur : ParseIt.Progress cur it) :
Id (ParseIt.Result ε it ((β × Option ε) × σ))
Instances For
theorem Parser.efoldlP.loop_eq_ok {ε ι τ : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] {α σ : Type u} (st : σ) (it cur : Std.Iter τ) (hcur : ParseIt.Progress cur it) (f : Array α → α → StateT σ (ParseIt.Parser ε ι τ) (Array α)) (y : Array α) (p : StateT σ (ParseIt.Parser ε ι τ) α) :
StateT.efoldlP.loop always returns .ok
theorem Parser.efoldlP.loop_all {ε ι τ : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] {α σ : Type u} (P : α → Prop) (st : σ) (it cur : Std.Iter τ) (hcur : ParseIt.Progress cur it) (y : Array α) (p : StateT σ (ParseIt.Parser ε ι τ) α) (hp :
∀ (st' : σ) (s rest : Std.Iter τ) (h : ParseIt.Progress rest s) (x : α × σ) (a : ParseIt.Progress s it),
p st' s = ParseIt.Result.ok rest h x → P x.fst) (hy : ∀ (a : α), a ∈ y → P a) {rest : Std.Iter τ} {h' : ParseIt.Progress rest it} {z : (Array α × Option ε) × σ} (heq :
StateT.efoldlP.loop (fun (y : Array α) (x : α) => StateT.pure (y.push x)) p st it y cur hcur = ParseIt.Result.ok rest h' z) (a : α) :
every element collected by the fold loop satisfies P if every successful p result does
def Parser.StateT.foldlP {ε ι τ : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] {β α σ : Type u} (f : β → α → StateT σ (ParseIt.Parser ε ι τ) β) (init : β) (p : StateT σ (ParseIt.Parser ε ι τ) α) :
StateT σ (ParseIt.Parser ε ι τ) β
Instances For
def Parser.StateT.foldl {ε ι τ : Type u} [Std.Iterator ι Id τ] [Std.Iterators.Finite ι Id] {β α σ : Type u} (f : β → α → β) (init : β) (p : StateT σ (ParseIt.Parser ε ι τ) α) :
StateT σ (ParseIt.Parser ε ι τ) β
Instances For
def Parser.StateT.takeMany {ρ σ α : Type} (p : ReaderT ρ (StateT σ SimpleCharParser) α) :
ReaderT ρ (StateT σ SimpleCharParser) (Array α)
Instances For
theorem Parser.takeMany_eq_ok {ρ σ α : Type} (p : ReaderT ρ (StateT σ SimpleCharParser) α) (r : ρ) (st : σ) (it : Std.Iter Char) :
StateT.takeMany always returns .ok
theorem Parser.takeMany_ne_error {ρ✝ σ✝ α✝ : Type} {p : ReaderT ρ✝ (StateT σ✝ SimpleCharParser) α✝} {r : ρ✝} {st : σ✝} {it : Std.Iter Char} {e : ParseIt.Error.Simple ParseIt.CharIterator} (h : StateT.takeMany p r st it = ParseIt.Result.error e) :
StateT.takeMany never returns .error
theorem Parser.takeMany_all {α ρ σ : Type} (P : α → Prop) (p : ReaderT ρ (StateT σ SimpleCharParser) α) (r : ρ) (st : σ) (it : Std.Iter Char) (hp :
∀ (st' : σ) (s rest : Std.Iter Char) (h : ParseIt.Progress rest s) (x : α × σ) (a : ParseIt.Progress s it),
p r st' s = ParseIt.Result.ok rest h x → P x.fst) {rest : Std.Iter Char} {h : ParseIt.Progress rest it} {y : Array α × σ} (heq : StateT.takeMany p r st it = ParseIt.Result.ok rest h y) (a : α) :
every element collected by takeMany p satisfies P if every successful p result does
Instances For
theorem Parser.Spec.withPos {α : Type} {pre : ParseIt.IterWithProgress ParseIt.CharIterator Char → Prop} {post : α → ParseIt.IterWithProgress ParseIt.CharIterator Char → Prop} {epost : ParseIt.Error.Simple ParseIt.CharIterator → Prop} (x : SimpleCharParser α) (h : ⦃ pre ⦄ x ⦃ post; epost ⦄) (it : Std.Iter Char) :
⦃ fun (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) => s.it = it ∧ s.rest = it ∧ pre s ⦄ Parser.withPos x ⦃ fun (a : String.Pos.Raw × String.Pos.Raw × α) (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) =>
s.it = it ∧ post a.snd.snd s ∧ a.fst = ParseIt.HasPos.pos it ∧ a.snd.fst = ParseIt.HasPos.pos s.rest; epost ⦄
def Parser.withPosM {ρ σ α : Type} (p : ReaderT ρ (StateT σ SimpleCharParser) α) :
ReaderT ρ (StateT σ SimpleCharParser) (String.Pos.Raw × String.Pos.Raw × α)
Instances For
exec check on current char
Instances For
exec check on current char and consume char on success
Instances For
exec check on current char and skip char on success
Instances For
exec check on current char and then exec p on success
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
Instances For
Instances For
theorem Parser.Spec.tryCharWithPos.from_it (check : Char → Bool) (it : Std.Iter Char) :
⦃ fun (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) => s.it = it ∧ s.rest = it ⦄ Parser.tryCharWithPos check ⦃ fun (r : Option (String.Pos.Raw × String.Pos.Raw × Char)) (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) =>
s.it = it ∧ match r with
| some val => ParseIt.Advanced s.rest it
| none => s.rest = it; fun (x : ParseIt.Error.Simple ParseIt.CharIterator) => False ⦄
Spec.tryCharWithPos for the special case where the parse start is the current iterator.
theorem Parser.Spec.tryCharWithPos (check : Char → Bool) (it₀ it : Std.Iter Char) :
⦃ fun (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) => s.it = it₀ ∧ s.rest = it ⦄ Parser.tryCharWithPos check ⦃ fun (r : Option (String.Pos.Raw × String.Pos.Raw × Char)) (s : ParseIt.IterWithProgress ParseIt.CharIterator Char) =>
s.it = it₀ ∧ match r with
| some val => ParseIt.Advanced s.rest it
| none => s.rest = it; fun (x : ParseIt.Error.Simple ParseIt.CharIterator) => False ⦄