name | parser |
version | 1.5 |
description | Basic theory of parsers |
author | Joe Hurd <joe@gilith.com> |
license | MIT |
show | Data.Bool Data.List Data.Option Data.Pair Parser Relation |
⊦ isParser parseAll.pa
⊦ isParser parseNone.pn
⊦ wellFounded Stream.isProperSuffix
⊦ parseAll = mkParser parseAll.pa
⊦ parseNone = mkParser parseNone.pn
⊦ destParser parseNone = parseNone.pn
⊦ ∀x. Stream.isSuffix x x
⊦ ∀p. isParser (destParser p)
⊦ ∀x. ¬Stream.isProperSuffix x x
⊦ inverse parseAll (λa. a :: [])
⊦ strongInverse parseAll (λa. a :: [])
⊦ ∀s. parse parseNone s = none
⊦ ∀pb pc. isParser (parsePair.pbc pb pc)
⊦ ∀f p. isParser (partialMap.pf f p)
⊦ ∀l. Stream.fromList l = Stream.append l Stream.eof
⊦ ∀l. Stream.length (Stream.fromList l) = length l
⊦ ∀l. Stream.toList (Stream.fromList l) = some l
⊦ ∀f. parseOption f = partialMap f parseAll
⊦ ∀a s. parseNone.pn a s = none
⊦ ∀x y. Stream.isProperSuffix x y ⇒ Stream.isSuffix x y
⊦ ∀p s.
Number.Natural.≤ (Stream.length (parseStream p s)) (Stream.length s)
⊦ ∀a s. parseAll.pa a s = some (a, s)
⊦ ∀s. case T (λl. length l = Stream.length s) (Stream.toList s)
⊦ ∀pb pc. parsePair pb pc = mkParser (parsePair.pbc pb pc)
⊦ ∀pb pc. destParser (parsePair pb pc) = parsePair.pbc pb pc
⊦ ∀f p. partialMap f p = mkParser (partialMap.pf f p)
⊦ ∀f p. destParser (partialMap f p) = partialMap.pf f p
⊦ parse parseAll = Stream.case none none (λa s. some (a, s))
⊦ ∀x y.
Stream.isProperSuffix x y ⇒
Number.Natural.< (Stream.length x) (Stream.length y)
⊦ ∀x y.
Stream.isSuffix x y ⇒
Number.Natural.≤ (Stream.length x) (Stream.length y)
⊦ ∀p. parseSome p = parseOption (λa. if p a then some a else none)
⊦ ∀f p. map f p = partialMap (λb. some (f b)) p
⊦ ∀l s.
Stream.length (Stream.append l s) =
Number.Natural.+ (length l) (Stream.length s)
⊦ ∀s s'. Stream.isSuffix s s' ⇔ s = s' ∨ Stream.isProperSuffix s s'
⊦ ∀x y z. Stream.append (x @ y) z = Stream.append x (Stream.append y z)
⊦ ∀x y z.
Stream.isProperSuffix x y ∧ Stream.isProperSuffix y z ⇒
Stream.isProperSuffix x z
⊦ ∀x y z. Stream.isSuffix x y ∧ Stream.isSuffix y z ⇒ Stream.isSuffix x z
⊦ ∀l s.
Stream.toList (Stream.append l s) =
case none (λls. some (l @ ls)) (Stream.toList s)
⊦ (∀a. mkParser (destParser a) = a) ∧
∀r. isParser r ⇔ destParser (mkParser r) = r
⊦ ∀x. x = Stream.error ∨ x = Stream.eof ∨ ∃a0 a1. x = Stream.stream a0 a1
⊦ ∀p.
parse (parseSome p) =
Stream.case none none (λa s. if p a then some (a, s) else none)
⊦ ∀f.
parse (parseOption f) =
Stream.case none none (λa s. case none (λb. some (b, s)) (f a))
⊦ ∀p. (∀x. (∀y. Stream.isProperSuffix y x ⇒ p y) ⇒ p x) ⇒ ∀x. p x
⊦ ∀p a s. destParser (parseSome p) a s = if p a then some (a, s) else none
⊦ ∀p e l.
inverse p e ⇒
parseStream p (Stream.fromList (concat (map e l))) = Stream.fromList l
⊦ ∀f a s.
destParser (parseOption f) a s = case none (λb. some (b, s)) (f a)
⊦ ∀f e. (∀b. f (e b) = some b) ⇒ inverse (parseOption f) (λb. e b :: [])
⊦ ∀p a s b s'. destParser p a s = some (b, s') ⇒ Stream.isSuffix s' s
⊦ ∀a0 a1 a0' a1'.
Stream.stream a0 a1 = Stream.stream a0' a1' ⇔ a0 = a0' ∧ a1 = a1'
⊦ ∀p e. inverse p e ⇔ ∀x s. parse p (Stream.append (e x) s) = some (x, s)
⊦ Stream.length Stream.error = Number.Numeral.zero ∧
Stream.length Stream.eof = Number.Numeral.zero ∧
∀a s.
Stream.length (Stream.stream a s) =
Number.Natural.suc (Stream.length s)
⊦ ∀p e x s.
inverse p e ⇒
parseStream p (Stream.append (e x) s) =
Stream.stream x (parseStream p s)
⊦ ∀P.
P Stream.error ∧ P Stream.eof ∧
(∀a0 a1. P a1 ⇒ P (Stream.stream a0 a1)) ⇒ ∀x. P x
⊦ ∀p e s.
strongInverse p e ⇒
case T (λl. Stream.toList s = some (concat (map e l)))
(Stream.toList (parseStream p s))
⊦ (∀s. Stream.append [] s = s) ∧
∀h t s. Stream.append (h :: t) s = Stream.stream h (Stream.append t s)
⊦ ∀p s.
parse p s = none ∨
∃b s'. parse p s = some (b, s') ∧ Stream.isProperSuffix s' s
⊦ ¬(Stream.error = Stream.eof) ∧
(∀a0' a1'. ¬(Stream.error = Stream.stream a0' a1')) ∧
∀a0' a1'. ¬(Stream.eof = Stream.stream a0' a1')
⊦ ∀f p g e.
inverse p e ∧ (∀b. f (g b) = b) ⇒ inverse (map f p) (λc. e (g c))
⊦ ∀p.
isParser p ⇔ ∀x xs. case T (λ(y, xs'). Stream.isSuffix xs' xs) (p x xs)
⊦ ∀f p g e.
inverse p e ∧ (∀b. f (g b) = some b) ⇒
inverse (partialMap f p) (λc. e (g c))
⊦ ∀p a s.
destParser p a s = none ∨
∃b s'. destParser p a s = some (b, s') ∧ Stream.isSuffix s' s
⊦ Stream.toList Stream.error = none ∧ Stream.toList Stream.eof = some [] ∧
∀a s.
Stream.toList (Stream.stream a s) =
case none (λl. some (a :: l)) (Stream.toList s)
⊦ ∀p a s.
isParser p ⇒
p a s = none ∨ ∃b s'. p a s = some (b, s') ∧ Stream.isSuffix s' s
⊦ ∀f0 f1 f2.
∃fn.
fn Stream.error = f0 ∧ fn Stream.eof = f1 ∧
∀a0 a1. fn (Stream.stream a0 a1) = f2 a0 a1 (fn a1)
⊦ (∀p. parse p Stream.error = none) ∧ (∀p. parse p Stream.eof = none) ∧
∀p a s. parse p (Stream.stream a s) = destParser p a s
⊦ ∀f p s.
parse (map f p) s = case none (λ(b, s'). some (f b, s')) (parse p s)
⊦ ∀p e.
strongInverse p e ⇔
inverse p e ∧
∀s x s'. parse p s = some (x, s') ⇒ s = Stream.append (e x) s'
⊦ ∀pb pc eb ec.
inverse pb eb ∧ inverse pc ec ⇒
inverse (parsePair pb pc) (λ(b, c). eb b @ ec c)
⊦ ∀pb pc eb ec.
strongInverse pb eb ∧ strongInverse pc ec ⇒
strongInverse (parsePair pb pc) (λ(b, c). eb b @ ec c)
⊦ (∀s. Stream.isProperSuffix s Stream.error ⇔ F) ∧
(∀s. Stream.isProperSuffix s Stream.eof ⇔ F) ∧
∀s a s'.
Stream.isProperSuffix s (Stream.stream a s') ⇔
s = s' ∨ Stream.isProperSuffix s s'
⊦ ∀f p a s.
destParser (map f p) a s =
case none (λ(b, s'). some (f b, s')) (destParser p a s)
⊦ ∀f p s.
parse (partialMap f p) s =
case none (λ(b, s'). case none (λc. some (c, s')) (f b)) (parse p s)
⊦ ∀h.
(∀f g s.
(∀s'. Stream.isProperSuffix s' s ⇒ f s' = g s') ⇒ h f s = h g s) ⇒
∃f. ∀s. f s = h f s
⊦ ∀f p a s.
partialMap.pf f p a s =
case none (λ(b, s'). case none (λc. some (c, s')) (f b))
(destParser p a s)
⊦ ∀f e.
(∀b. f (e b) = some b) ∧
(∀a1 a2 b. f a1 = some b ∧ f a2 = some b ⇒ a1 = a2) ⇒
strongInverse (parseOption f) (λb. e b :: [])
⊦ ∀p.
parseStream p Stream.error = Stream.error ∧
parseStream p Stream.eof = Stream.eof ∧
∀a s.
parseStream p (Stream.stream a s) =
case Stream.error (λ(b, s'). Stream.stream b (parseStream p s'))
(destParser p a s)
⊦ ∀f p g e.
strongInverse p e ∧ (∀b. f (g b) = b) ∧
(∀b1 b2 c. f b1 = c ∧ f b2 = c ⇒ b1 = b2) ⇒
strongInverse (map f p) (λc. e (g c))
⊦ (∀e b f. Stream.case e b f Stream.error = e) ∧
(∀e b f. Stream.case e b f Stream.eof = b) ∧
∀e b f a s. Stream.case e b f (Stream.stream a s) = f a s
⊦ ∀pb pc s.
parse (parsePair pb pc) s =
case none
(λ(b, s'). case none (λ(c, s''). some ((b, c), s'')) (parse pc s'))
(parse pb s)
⊦ ∀f p g e.
strongInverse p e ∧ (∀b. f (g b) = some b) ∧
(∀b1 b2 c. f b1 = some c ∧ f b2 = some c ⇒ b1 = b2) ⇒
strongInverse (partialMap f p) (λc. e (g c))
⊦ ∀pb pc a s.
parsePair.pbc pb pc a s =
case none
(λ(b, s'). case none (λ(c, s''). some ((b, c), s'')) (parse pc s'))
(destParser pb a s)
⊦ T
⊦ ∀n. Number.Natural.≤ Number.Numeral.zero n
⊦ ∀n. Number.Natural.≤ n n
⊦ ∀m. wellFounded (measure m)
⊦ F ⇔ ∀p. p
⊦ (¬) = λp. p ⇒ F
⊦ (∃) = λP. P ((select) P)
⊦ ∀a. ∃!x. x = a
⊦ ∀t. (∀x. t) ⇔ t
⊦ ∀t. (∃x. t) ⇔ t
⊦ ∀t. (λx. t x) = t
⊦ (∀) = λP. P = λx. T
⊦ ∀a'. ¬(none = some a')
⊦ ∀x. x = x ⇔ T
⊦ ∀n. ¬(Number.Natural.suc n = Number.Numeral.zero)
⊦ ∀m. Number.Natural.+ m Number.Numeral.zero = m
⊦ ∀n.
Number.Natural.even
(Number.Natural.*
(Number.Numeral.bit0 (Number.Numeral.bit1 Number.Numeral.zero)) n)
⊦ ∀n. Number.Numeral.bit0 n = Number.Natural.+ n n
⊦ ∀x. case none some x = x
⊦ (⇒) = λp q. p ∧ q ⇔ p
⊦ ∀t. (t ⇔ T) ∨ (t ⇔ F)
⊦ ∀n. Number.Numeral.bit1 n = Number.Natural.suc (Number.Natural.+ n n)
⊦ ∀P x. P x ⇒ P ((select) P)
⊦ (¬T ⇔ F) ∧ (¬F ⇔ T)
⊦ ∀p. ∃x y. p = (x, y)
⊦ ∀t1 t2. t1 ∨ t2 ⇔ t2 ∨ t1
⊦ ∀m n. Number.Natural.< m n ⇒ Number.Natural.≤ m n
⊦ ∀<< x. wellFounded << ⇒ ¬<< x x
⊦ ∀n.
Number.Natural.*
(Number.Numeral.bit0 (Number.Numeral.bit1 Number.Numeral.zero)) n =
Number.Natural.+ n n
⊦ ∀m. measure m = λx y. Number.Natural.< (m x) (m y)
⊦ ∀m n. ¬(Number.Natural.< m n ∧ Number.Natural.≤ n m)
⊦ ∀m n. ¬(Number.Natural.≤ m n ∧ Number.Natural.< n m)
⊦ ∀m n. Number.Natural.< m (Number.Natural.suc n) ⇔ Number.Natural.≤ m n
⊦ ∀m n. Number.Natural.≤ (Number.Natural.suc m) n ⇔ Number.Natural.< m n
⊦ ∀x. x = none ∨ ∃a. x = some a
⊦ (∧) = λp q. (λf. f p q) = λf. f T T
⊦ (∃) = λP. ∀q. (∀x. P x ⇒ q) ⇒ q
⊦ ∀a a'. some a = some a' ⇔ a = a'
⊦ ∀m n. Number.Natural.suc m = Number.Natural.suc n ⇔ m = n
⊦ ∀m n.
Number.Natural.≤ (Number.Natural.suc m) (Number.Natural.suc n) ⇔
Number.Natural.≤ m n
⊦ ∀m n.
Number.Natural.even (Number.Natural.* m n) ⇔
Number.Natural.even m ∨ Number.Natural.even n
⊦ ∀m n.
Number.Natural.even (Number.Natural.+ m n) ⇔ Number.Natural.even m ⇔
Number.Natural.even n
⊦ ∀l. l = [] ∨ ∃h t. l = h :: t
⊦ ∀f g. f = g ⇔ ∀x. f x = g x
⊦ ∀P a. (∃x. a = x ∧ P x) ⇔ P a
⊦ (∨) = λp q. ∀r. (p ⇒ r) ⇒ (q ⇒ r) ⇒ r
⊦ (Number.Natural.even Number.Numeral.zero ⇔ T) ∧
∀n. Number.Natural.even (Number.Natural.suc n) ⇔ ¬Number.Natural.even n
⊦ ∀m n. Number.Natural.≤ m n ⇔ Number.Natural.< m n ∨ m = n
⊦ ∀m n. Number.Natural.≤ m n ∧ Number.Natural.≤ n m ⇔ m = n
⊦ ∀PAIR'. ∃fn. ∀a0 a1. fn (a0, a1) = PAIR' a0 a1
⊦ ∀P Q. (∃x. P ∧ Q x) ⇔ P ∧ ∃x. Q x
⊦ ∀t1 t2 t3. t1 ∧ t2 ∧ t3 ⇔ (t1 ∧ t2) ∧ t3
⊦ ∀t1 t2 t3. t1 ∨ t2 ∨ t3 ⇔ (t1 ∨ t2) ∨ t3
⊦ ∀m n p.
Number.Natural.* m (Number.Natural.* n p) =
Number.Natural.* (Number.Natural.* m n) p
⊦ ∀m n p. Number.Natural.+ m p = Number.Natural.+ n p ⇔ m = n
⊦ ∀m n p.
Number.Natural.≤ m n ∧ Number.Natural.≤ n p ⇒ Number.Natural.≤ m p
⊦ ∀P x. (∀y. P y ⇔ y = x) ⇒ (select) P = x
⊦ ∀P. (∀x. ∃y. P x y) ⇔ ∃y. ∀x. P x (y x)
⊦ ∀t1 t2. (if T then t1 else t2) = t1 ∧ (if F then t1 else t2) = t2
⊦ ∀m n.
Number.Natural.* m n = Number.Numeral.zero ⇔
m = Number.Numeral.zero ∨ n = Number.Numeral.zero
⊦ length [] = Number.Numeral.zero ∧
∀h t. length (h :: t) = Number.Natural.suc (length t)
⊦ ∀P.
P Number.Numeral.zero ∧ (∀n. P n ⇒ P (Number.Natural.suc n)) ⇒ ∀n. P n
⊦ (∀t. ¬¬t ⇔ t) ∧ (¬T ⇔ F) ∧ (¬F ⇔ T)
⊦ ∀m n.
Number.Natural.exp m n = Number.Numeral.zero ⇔
m = Number.Numeral.zero ∧ ¬(n = Number.Numeral.zero)
⊦ concat [] = [] ∧ ∀h t. concat (h :: t) = h @ concat t
⊦ ∀P Q. (∀x. P x ∧ Q x) ⇔ (∀x. P x) ∧ ∀x. Q x
⊦ ∀P Q. (∀x. P x ⇒ Q x) ⇒ (∀x. P x) ⇒ ∀x. Q x
⊦ ∀P Q. (∀x. P x ⇒ Q x) ⇒ (∃x. P x) ⇒ ∃x. Q x
⊦ ∀P Q. (∀x. P x) ∧ (∀x. Q x) ⇔ ∀x. P x ∧ Q x
⊦ ∀e f.
∃fn.
fn Number.Numeral.zero = e ∧
∀n. fn (Number.Natural.suc n) = f (fn n) n
⊦ ∀P. P [] ∧ (∀a0 a1. P a1 ⇒ P (a0 :: a1)) ⇒ ∀x. P x
⊦ ∀<< <<<. (∀x y. << x y ⇒ <<< x y) ∧ wellFounded <<< ⇒ wellFounded <<
⊦ ∀m n p.
Number.Natural.* m n = Number.Natural.* m p ⇔
m = Number.Numeral.zero ∨ n = p
⊦ ∀m n p.
Number.Natural.≤ (Number.Natural.* m n) (Number.Natural.* m p) ⇔
m = Number.Numeral.zero ∨ Number.Natural.≤ n p
⊦ ∀m n p.
Number.Natural.< (Number.Natural.* m n) (Number.Natural.* m p) ⇔
¬(m = Number.Numeral.zero) ∧ Number.Natural.< n p
⊦ ∀x y a b. (x, y) = (a, b) ⇔ x = a ∧ y = b
⊦ ∀A B C D. (A ⇒ B) ∧ (C ⇒ D) ⇒ A ∧ C ⇒ B ∧ D
⊦ ∀A B C D. (A ⇒ B) ∧ (C ⇒ D) ⇒ A ∨ C ⇒ B ∨ D
⊦ ∀P. (∀x. ∃!y. P x y) ⇔ ∃f. ∀x y. P x y ⇔ f x = y
⊦ (∀m.
Number.Natural.exp m Number.Numeral.zero =
Number.Numeral.bit1 Number.Numeral.zero) ∧
∀m n.
Number.Natural.exp m (Number.Natural.suc n) =
Number.Natural.* m (Number.Natural.exp m n)
⊦ ∀P c x y. P (if c then x else y) ⇔ (c ⇒ P x) ∧ (¬c ⇒ P y)
⊦ ∀NIL' CONS'.
∃fn. fn [] = NIL' ∧ ∀a0 a1. fn (a0 :: a1) = CONS' a0 a1 (fn a1)
⊦ ∀P. (∃!x. P x) ⇔ (∃x. P x) ∧ ∀x x'. P x ∧ P x' ⇒ x = x'
⊦ ∀<<. wellFounded << ⇔ ∀P. (∀x. (∀y. << y x ⇒ P y) ⇒ P x) ⇒ ∀x. P x
⊦ (∀b f. case b f none = b) ∧ ∀b f a. case b f (some a) = f a
⊦ (∀l. [] @ l = l) ∧ ∀h t l. (h :: t) @ l = h :: t @ l
⊦ (∀f. map f [] = []) ∧ ∀f h t. map f (h :: t) = f h :: map f t
⊦ (∀m. Number.Natural.≤ m Number.Numeral.zero ⇔ m = Number.Numeral.zero) ∧
∀m n.
Number.Natural.≤ m (Number.Natural.suc n) ⇔
m = Number.Natural.suc n ∨ Number.Natural.≤ m n
⊦ ∀t. ((T ⇔ t) ⇔ t) ∧ ((t ⇔ T) ⇔ t) ∧ ((F ⇔ t) ⇔ ¬t) ∧ ((t ⇔ F) ⇔ ¬t)
⊦ ∀t. (T ∧ t ⇔ t) ∧ (t ∧ T ⇔ t) ∧ (F ∧ t ⇔ F) ∧ (t ∧ F ⇔ F) ∧ (t ∧ t ⇔ t)
⊦ ∀t. (T ∨ t ⇔ T) ∧ (t ∨ T ⇔ T) ∧ (F ∨ t ⇔ t) ∧ (t ∨ F ⇔ t) ∧ (t ∨ t ⇔ t)
⊦ ∀t. (T ⇒ t ⇔ t) ∧ (t ⇒ T ⇔ T) ∧ (F ⇒ t ⇔ T) ∧ (t ⇒ t ⇔ T) ∧ (t ⇒ F ⇔ ¬t)
⊦ ∀<<.
wellFounded << ⇒
∀H.
(∀f g x. (∀z. << z x ⇒ f z = g z) ⇒ H f x = H g x) ⇒
∃f. ∀x. f x = H f x
⊦ (∀n. Number.Natural.+ Number.Numeral.zero n = n) ∧
(∀m. Number.Natural.+ m Number.Numeral.zero = m) ∧
(∀m n.
Number.Natural.+ (Number.Natural.suc m) n =
Number.Natural.suc (Number.Natural.+ m n)) ∧
∀m n.
Number.Natural.+ m (Number.Natural.suc n) =
Number.Natural.suc (Number.Natural.+ m n)
⊦ ∀p q r.
(p ∨ q ⇔ q ∨ p) ∧ ((p ∨ q) ∨ r ⇔ p ∨ q ∨ r) ∧ (p ∨ q ∨ r ⇔ q ∨ p ∨ r) ∧
(p ∨ p ⇔ p) ∧ (p ∨ p ∨ q ⇔ p ∨ q)