Documentation

Regex.Syntax.Grammar.Basic

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') :
    h1.trans h2 = h1
    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 τ) :
    ⦃ fun (x : ρ × σ × ParseIt.IterWithProgress ι τ) => match x with | (fst, fst_1, s) => s.it = it₀ ∧ s.rest = it ⦄ x ⦃ fun (x : α) (x_1 : ρ × σ × ParseIt.IterWithProgress ι τ) => match x_1 with | (fst, fst_1, s) => s.it = it₀ ∧ (s.rest = it ∨ ParseIt.Advanced s.rest it); fun (x : ε) => True ⦄

    Any x started at it (with parse start it₀) never moves backwards from it.

    @[reducible, inline]
    Instances For
      def Parser.fail {α : Type} (msg : String) :
      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 ε ι τ) α) :
            ∃ (rest : Std.Iter τ), ∃ (h : ParseIt.Progress rest it), ∃ (x : (Array α × Option ε) × σ), StateT.efoldlP.loop f p st it y cur hcur = ParseIt.Result.ok rest h x

            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 : α) :
            a ∈ z.fst.fst → P 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
                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 : α) :
                  a ∈ y.fst → P a

                  every element collected by takeMany p satisfies P if every successful p result does

                  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

                            exec check on current char and then exec p on success

                            Instances For

                              Spec.tryCharWithPos for the special case where the parse start is the current iterator.