name | parser-comb |
version | 1.0 |
description | Theory of the basic parser combinators |
author | Joe Hurd <joe@gilith.com> |
license | MIT |
show | Data.Bool Data.List Data.Option Data.Pair Parser |
⊦ isParser parseAll.pa
⊦ isParser parseNone.pn
⊦ parseAll = mkParser parseAll.pa
⊦ parseNone = mkParser parseNone.pn
⊦ destParser parseNone = parseNone.pn
⊦ ∀p. isParser (destParser p)
⊦ 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)
⊦ ∀f. parseOption f = partialMap f parseAll
⊦ ∀a s. parseNone.pn a s = none
⊦ ∀a s. parseAll.pa a s = some (a, 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))
⊦ ∀p. parseSome p = parseOption (λa. if p a then some a else none)
⊦ ∀f p. map f p = partialMap (λb. some (f b)) p
⊦ (∀a. mkParser (destParser a) = a) ∧
∀r. isParser r ⇔ destParser (mkParser r) = r
⊦ ∀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 a s. destParser (parseSome p) a s = if p a then some (a, s) else none
⊦ ∀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
⊦ ∀p e. inverse p e ⇔ ∀x s. parse p (Stream.append (e x) s) = some (x, s)
⊦ ∀p s.
parse p s = none ∨
∃b s'. parse p s = some (b, s') ∧ Stream.isProperSuffix s' s
⊦ ∀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
⊦ ∀p a s.
isParser p ⇒
p a s = none ∨ ∃b s'. p a s = some (b, s') ∧ Stream.isSuffix s' s
⊦ (∀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)
⊦ ∀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)
⊦ ∀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 :: [])
⊦ ∀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))
⊦ ∀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
⊦ ∀x. Stream.isSuffix x x
⊦ F ⇔ ∀p. p
⊦ (¬) = λp. p ⇒ F
⊦ (∃) = λP. P ((select) P)
⊦ ∀t. (∀x. t) ⇔ t
⊦ ∀t. (λx. t x) = t
⊦ (∀) = λP. P = λx. T
⊦ ∀a'. ¬(none = some a')
⊦ ∀x. x = x ⇔ T
⊦ (⇒) = λp q. p ∧ q ⇔ p
⊦ ∀t. (t ⇔ T) ∨ (t ⇔ F)
⊦ ∀P x. P x ⇒ P ((select) P)
⊦ (¬T ⇔ F) ∧ (¬F ⇔ T)
⊦ ∀p. ∃x y. p = (x, y)
⊦ ∀x y. Stream.isProperSuffix x y ⇒ Stream.isSuffix x y
⊦ ∀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'
⊦ ∀f g. f = g ⇔ ∀x. f x = g x
⊦ (∨) = λp q. ∀r. (p ⇒ r) ⇒ (q ⇒ r) ⇒ r
⊦ ∀s s'. Stream.isSuffix s s' ⇔ s = s' ∨ Stream.isProperSuffix s s'
⊦ ∀PAIR'. ∃fn. ∀a0 a1. fn (a0, a1) = PAIR' a0 a1
⊦ ∀t1 t2 t3. t1 ∨ t2 ∨ t3 ⇔ (t1 ∨ t2) ∨ t3
⊦ ∀x y z. Stream.append (x @ y) z = Stream.append x (Stream.append y z)
⊦ ∀x y z. Stream.isSuffix x y ∧ Stream.isSuffix y z ⇒ Stream.isSuffix x z
⊦ ∀t1 t2. (if T then t1 else t2) = t1 ∧ (if F then t1 else t2) = t2
⊦ (∀t. ¬¬t ⇔ t) ∧ (¬T ⇔ F) ∧ (¬F ⇔ T)
⊦ ∀x. x = Stream.error ∨ x = Stream.eof ∨ ∃a0 a1. x = Stream.stream a0 a1
⊦ ∀x y a b. (x, y) = (a, b) ⇔ x = a ∧ y = b
⊦ ∀a0 a1 a0' a1'.
Stream.stream a0 a1 = Stream.stream a0' a1' ⇔ a0 = a0' ∧ a1 = a1'
⊦ (∀b f. case b f none = b) ∧ ∀b f a. case b f (some a) = f a
⊦ (∀s. Stream.append [] s = s) ∧
∀h t s. Stream.append (h :: t) s = Stream.stream h (Stream.append t s)
⊦ ∀t. ((T ⇔ t) ⇔ t) ∧ ((t ⇔ T) ⇔ t) ∧ ((F ⇔ t) ⇔ ¬t) ∧ ((t ⇔ F) ⇔ ¬t)
⊦ ∀f0 f1 f2.
∃fn.
fn Stream.error = f0 ∧ fn Stream.eof = f1 ∧
∀a0 a1. fn (Stream.stream a0 a1) = f2 a0 a1 (fn a1)
⊦ ∀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)
⊦ (∀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'
⊦ (∀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
⊦ ∀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)