Documentation

Lemmas.Instances

WP instances for ParseIt.Parser

@[simp]
theorem ParseIt.Progress.refl_eq {ι τ : Type u} [Std.Iterator ι Id τ] {it : Std.Iter τ} :
refl it = stay ⋯

Progress.refl is the stay constructor.

@[simp]
theorem ParseIt.Progress.refl_trans' {ι τ : Type u} [Std.Iterator ι Id τ] {it' it : Std.Iter τ} (h : Progress it' it) :
(stay ⋯).trans h = h

Progress.stay rfl is a left identity for Progress.trans.

@[simp]
theorem ParseIt.Progress.trans_refl' {ι τ : Type u} [Std.Iterator ι Id τ] {it' it : Std.Iter τ} (h : Progress it' it) :
h.trans (stay ⋯) = h

Progress.stay rfl is a right identity for Progress.trans.

@[simp]
theorem ParseIt.Progress.trans_assoc' {ι τ : Type u} [Std.Iterator ι Id τ] {it''' it'' it' it : Std.Iter τ} (h₁ : Progress it''' it'') (h₂ : Progress it'' it') (h₃ : Progress it' it) :
(h₁.trans h₂).trans h₃ = h₁.trans (h₂.trans h₃)

Progress.trans is associative.

instance ParseIt.instLawfulMonadParser_lemmas {ε ι τ : Type u} [Std.Iterator ι Id τ] :
LawfulMonad (Parser ε ι τ)

Parser ε ι τ is a lawful monad.

def ParseIt.pushResult {ε ι τ α : Type u} [Std.Iterator ι Id τ] (it : Std.Iter τ) (post : α → (it' : Std.Iter τ) → Progress it' it → Prop) (epost : ε → Prop) :
Result ε it α → Prop

The postcondition for a ParseIt.Result

Instances For
    @[simp]
    theorem ParseIt.pushResult_ok {ε ι τ α : Type u} [Std.Iterator ι Id τ] (it : Std.Iter τ) (post : α → (it' : Std.Iter τ) → Progress it' it → Prop) (epost : ε → Prop) (s : Std.Iter τ) (h : Progress s it) (a : α) :
    pushResult it post epost (Result.ok s h a) = post a s h

    pushResult on a successful result applies the success postcondition.

    @[simp]
    theorem ParseIt.pushResult_error {ε ι τ α : Type u} [Std.Iterator ι Id τ] (it : Std.Iter τ) (post : α → (it' : Std.Iter τ) → Progress it' it → Prop) (epost : ε → Prop) (e : ε) :
    pushResult it post epost (Result.error e) = epost e

    pushResult on an error applies the error postcondition.

    @[instance_reducible]
    instance ParseIt.Result.instWP {ε ι τ α : Type u} [Std.Iterator ι Id τ] (it : Std.Iter τ) :
    Std.WP.WP ((it' : Std.Iter τ) → Progress it' it → Result ε it α) α ((it' : Std.Iter τ) → Progress it' it → Prop) (ε → Prop)

    Weakest-precondition interpretation of a function producing a ParseIt.Result from an iterator and a progress proof.

    structure ParseIt.IterWithProgress (ι τ : Type u) [Std.Iterator ι Id τ] :

    Parser state used in specifications: the iterator it where parsing started, the current iterator rest, and a proof that rest was reached from it.

    Instances For
      theorem ParseIt.IterWithProgress.ext_iff {ι τ : Type u} {inst✝ : Std.Iterator ι Id τ} {x y : IterWithProgress ι τ} :
      x = y ↔ x.it = y.it ∧ x.rest = y.rest ∧ x.p ≍ y.p
      theorem ParseIt.IterWithProgress.ext {ι τ : Type u} {inst✝ : Std.Iterator ι Id τ} {x y : IterWithProgress ι τ} (it : x.it = y.it) (rest : x.rest = y.rest) (p : x.p ≍ y.p) :
      x = y
      def ParseIt.IterWithProgress.trans {ι τ : Type u} [Std.Iterator ι Id τ] (it : IterWithProgress ι τ) (rest : Std.Iter τ) (h : Progress rest it.rest) :

      Extend the state it by further progress from it.rest to rest, keeping the start iterator.

      Instances For

        The state at it where no input has been consumed yet.

        Instances For
          @[instance_reducible]
          instance ParseIt.Parser.instWP {ε ι τ α : Type u} [Std.Iterator ι Id τ] :
          Std.WP.WP (Parser ε ι τ α) α (IterWithProgress ι τ → Prop) (ε → Prop)

          Weakest-precondition interpretation of Parser: run the parser from the current iterator it.rest and check the postcondition on the extended IterWithProgress state, or the error postcondition on failure.

          theorem ParseIt.Parser.of_wp_eq {ε ι τ α : Type u} [Std.Iterator ι Id τ] {pre : IterWithProgress ι τ → Prop} {post : α → IterWithProgress ι τ → Prop} {epost : ε → Prop} (x : Parser ε ι τ α) (h : ⦃ pre ⦄ x ⦃ post; epost ⦄) (it : Std.Iter τ) (hp : pre (IterWithProgress.refl it)) :
          match x it with | Result.ok s h a => post a { it := it, rest := s, p := h } | Result.error e => epost e

          Extract the concrete behaviour of x it from a Hoare triple whose precondition holds at the initial state IterWithProgress.refl it.

          @[instance_reducible]
          instance ParseIt.Parser.instWPMonad {ε ι τ : Type u} [Std.Iterator ι Id τ] :
          Std.WP.WPMonad (Parser ε ι τ) (IterWithProgress ι τ → Prop) (ε → Prop)

          Parser is a WPMonad: its weakest-precondition interpretation respects pure and bind.