Documentation

Lemmas.Char.Basic

Theorems for ParseIt.Char.Basic

theorem ParseIt.Char.Spec.char {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (c : Char) (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.char c ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ t = c ∧ Char.char c s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it (toString "expected " ++ toString (repr c)) ⦄

char c succeeds with c when the next character is c, consuming input; otherwise it fails with an unexpected error annotated with expected c.

theorem ParseIt.Char.Spec.string {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (tk : String) (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.string tk ⦃ fun (t : String) (s : IterWithProgress ι Char) => s.it = it ∧ t = tk ∧ Char.string t s.it = Result.ok s.rest s.p t ∧ (tk ≠ "" → Advanced s.rest s.it); fun (e : ε) => ∃ (it' : Std.Iter Char), ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it' t) it (toString "expected " ++ toString (repr tk)) ⦄

string tk succeeds with tk when the input starts with tk, consuming input if tk is non-empty; otherwise it fails with an unexpected error annotated with expected tk.

theorem ParseIt.Char.Spec.space {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.space ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ t = ' ' ∧ Char.space s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected space (U+0020)" ⦄

space succeeds with ' ' when the next character is a space (U+0020), consuming input; otherwise it fails with an unexpected error annotated with expected space (U+0020).

theorem ParseIt.Char.Spec.tab {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.tab ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ t = '\t' ∧ Char.tab s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected horizontal tab (U+0009)" ⦄

tab succeeds with '\t' when the next character is a horizontal tab (U+0009), consuming input; otherwise it fails with an unexpected error annotated with expected horizontal tab (U+0009).

theorem ParseIt.Char.Spec.ASCII.lf {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.lf ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ t = '\n' ∧ Char.ASCII.lf s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected line feed (U+000A)" ⦄

ASCII.lf succeeds with '\n' when the next character is a line feed (U+000A), consuming input; otherwise it fails with an unexpected error annotated with expected line feed (U+000A).

theorem ParseIt.Char.Spec.ASCII.cr {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.cr ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ t = '\x0d' ∧ Char.ASCII.cr s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected carriage return (U+000D)" ⦄

ASCII.cr succeeds with '\r' when the next character is a carriage return (U+000D), consuming input; otherwise it fails with an unexpected error annotated with expected carriage return (U+000D).

theorem ParseIt.Char.Spec.eol {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.eol ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ t = '\n' ∧ Char.eol s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (e₁ : ε), ∃ (t : Option Char), ((∃ (t' : Option Char), e₁ = Error.addMessage (Error.unexpected it t') it "expected carriage return (U+000D)") ∨ ∃ (it' : Std.Iter Char), ∃ (t' : Option Char), e₁ = Error.addMessage (Error.unexpected it' t') it' "expected line feed (U+000A)") ∧ e = Error.addMessage (Error.merge ι e₁ (Error.addMessage (Error.unexpected it t) it "expected line feed (U+000A)")) it "expected newline" ⦄

eol succeeds with '\n' on a line feed, optionally preceded by a carriage return, consuming input. Otherwise it fails with the error e₁ of cr *> lf (a failed cr at it, or a failed lf after a cr) merged with the error of lf at it, annotated with expected newline.

theorem ParseIt.Char.Spec.ASCII.whitespace {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.whitespace ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ (t = ' ' ∨ '\t' ≤ t ∧ t ≤ '\x0d') ∧ Char.ASCII.whitespace s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected whitespace character" ⦄

ASCII.whitespace succeeds with a whitespace character t (space or U+0009 to U+000D), consuming input; otherwise it fails with an unexpected error annotated with expected whitespace character.

theorem ParseIt.Char.Spec.ASCII.uppercase {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.uppercase ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ 'A' ≤ t ∧ t ≤ 'Z' ∧ Char.ASCII.uppercase s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected uppercase letter character" ⦄

ASCII.uppercase succeeds with an uppercase letter t (A to Z), consuming input; otherwise it fails with an unexpected error annotated with expected uppercase letter character.

theorem ParseIt.Char.Spec.ASCII.lowercase {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.lowercase ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ 'a' ≤ t ∧ t ≤ 'z' ∧ Char.ASCII.lowercase s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected lowercase letter character" ⦄

ASCII.lowercase succeeds with a lowercase letter t (a to z), consuming input; otherwise it fails with an unexpected error annotated with expected lowercase letter character.

theorem ParseIt.Char.Spec.ASCII.alpha {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.alpha ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ ('A' ≤ t ∧ t ≤ 'Z' ∨ 'a' ≤ t ∧ t ≤ 'z') ∧ Char.ASCII.alpha s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected alphabetic character" ⦄

ASCII.alpha succeeds with an alphabetic character t (A to Z or a to z), consuming input; otherwise it fails with an unexpected error annotated with expected alphabetic character.

theorem ParseIt.Char.Spec.ASCII.numeric {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.numeric ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ '0' ≤ t ∧ t ≤ '9' ∧ Char.ASCII.numeric s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected decimal digit character" ⦄

ASCII.numeric succeeds with a decimal digit character t (0 to 9), consuming input; otherwise it fails with an unexpected error annotated with expected decimal digit character.

theorem ParseIt.Char.Spec.ASCII.alphanum {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.alphanum ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ ('A' ≤ t ∧ t ≤ 'Z' ∨ 'a' ≤ t ∧ t ≤ 'z' ∨ '0' ≤ t ∧ t ≤ '9') ∧ Char.ASCII.alphanum s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected letter or digit character" ⦄

ASCII.alphanum succeeds with a letter or digit character t (A to Z, a to z or 0 to 9), consuming input; otherwise it fails with an unexpected error annotated with expected letter or digit character.

theorem ParseIt.Char.Spec.ASCII.control {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.control ⦃ fun (t : Char) (s : IterWithProgress ι Char) => s.it = it ∧ (t.val < 32 ∨ t.val = 127) ∧ Char.ASCII.control s.it = Result.ok s.rest s.p t ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected control character" ⦄

ASCII.control succeeds with a control character t (U+0000 to U+001F or U+007F), consuming input; otherwise it fails with an unexpected error annotated with expected control character.

theorem ParseIt.Char.Spec.withErrorMessage_tokenMap {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] {α : Type} (f : Char → Option α) (msg : String) (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ withErrorMessage msg (tokenMap f) ⦃ fun (a : α) (s : IterWithProgress ι Char) => s.it = it ∧ (∃ (t : Char), f t = some a) ∧ withErrorMessage msg (tokenMap f) s.it = Result.ok s.rest s.p a ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it msg ⦄

withErrorMessage msg (tokenMap f) reads one character t and succeeds with a when f t = some a, consuming input; otherwise it fails with an unexpected error annotated with msg.

theorem ParseIt.Char.Spec.ASCII.digit {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.digit ⦃ fun (d : Fin 10) (s : IterWithProgress ι Char) => s.it = it ∧ Char.ASCII.digit s.it = Result.ok s.rest s.p d ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected decimal digit" ⦄

ASCII.digit succeeds with the value of a decimal digit (0 to 9), consuming input; otherwise it fails with an unexpected error annotated with expected decimal digit.

theorem ParseIt.Char.Spec.ASCII.binDigit {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.binDigit ⦃ fun (d : Fin 2) (s : IterWithProgress ι Char) => s.it = it ∧ Char.ASCII.binDigit s.it = Result.ok s.rest s.p d ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected binary digit" ⦄

ASCII.binDigit succeeds with the value of a binary digit (0 or 1), consuming input; otherwise it fails with an unexpected error annotated with expected binary digit.

theorem ParseIt.Char.Spec.ASCII.octDigit {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.octDigit ⦃ fun (d : Fin 8) (s : IterWithProgress ι Char) => s.it = it ∧ Char.ASCII.octDigit s.it = Result.ok s.rest s.p d ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected octal digit" ⦄

ASCII.octDigit succeeds with the value of an octal digit (0 to 7), consuming input; otherwise it fails with an unexpected error annotated with expected octal digit.

theorem ParseIt.Char.Spec.ASCII.hexDigit {ε ι : Type} [Std.Iterator ι Id Char] [Std.Iterators.Productive ι Id] [Std.Iterators.Finite ι Id] [Error ε ι Char] (it : Std.Iter Char) :
⦃ fun (s : IterWithProgress ι Char) => s.it = it ∧ s.rest = it ⦄ Char.ASCII.hexDigit ⦃ fun (d : Fin 16) (s : IterWithProgress ι Char) => s.it = it ∧ Char.ASCII.hexDigit s.it = Result.ok s.rest s.p d ∧ Advanced s.rest s.it; fun (e : ε) => ∃ (t : Option Char), e = Error.addMessage (Error.unexpected it t) it "expected hexadecimal digit" ⦄

ASCII.hexDigit succeeds with the value of a hexadecimal digit (0 to 9, A to F or a to f), consuming input; otherwise it fails with an unexpected error annotated with expected hexadecimal digit.