Package parser: Stream parsers

Information

nameparser
version1.100
descriptionStream parsers
authorJoe Leslie-Hurd <joe@gilith.com>
licenseMIT
requiresbool
function
list
natural
option
pair
probability
relation
showData.Bool
Data.List
Data.Option
Data.Pair
Function
Number.Natural
Parser
Parser.Stream
Probability.Random
Relation

Files

Defined Type Operators

Defined Constants

Theorems

isParser parseAll.pa

isParser parseNone.pn

wellFounded isProperSuffix

¬(error = eof)

parseAll = mkParser parseAll.pa

parseNone = mkParser parseNone.pn

length eof = 0

length error = 0

toList error = none

destParser parseNone = parseNone.pn

x. isSuffix x x

p. isParser (destParser p)

toList eof = some []

s. ¬isProperSuffix s eof

s. ¬isProperSuffix s error

x. ¬isProperSuffix x x

inverse parseAll (λa. a :: [])

strongInverse parseAll (λa. a :: [])

s. append [] s = s

s. parse parseNone s = none

f. map f eof = eof

f. map f error = error

p. parseStream p eof = eof

p. parseStream p error = error

a. mkParser (destParser a) = a

p. parse p eof = none

p. parse p error = none

pb pc. isParser (parsePair.pbc pb pc)

f p. isParser (partialMap.pf f p)

l. fromList l = append l eof

l. length (fromList l) = length l

l. toList (fromList l) = some l

f. parseOption f = partialMap f parseAll

a s. parseNone.pn a s = none

a0' a1'. ¬(eof = cons a0' a1')

a0' a1'. ¬(error = cons a0' a1')

r. isParser r destParser (mkParser r) = r

x y. isProperSuffix x y isSuffix x y

p s. length (parseStream p s) length s

a s. parseAll.pa a s = some (a, s)

a s. length (cons a s) = suc (length s)

s. case toList s of none | some l length l = length 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 = case none none (λa s. some (a, s))

e b f. case e b f eof = b

e b f. case e b f error = e

x y. isProperSuffix x y length x < length y

x y. isSuffix x y length x 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

x s. parse parseAll (cons x s) = some (x, s)

l s. length (append l s) = length l + length s

f s. toList (map f s) = map (map f) (toList s)

f p. parseStream (map f p) = map f parseStream p

s s'. isSuffix s s' s = s' isProperSuffix s s'

f g p. mapToken f g p = mkParser (mapToken.pf f g p)

p a s. parse p (cons a s) = destParser p a s

h t s. append (h :: t) s = cons h (append t s)

x y z. append (x @ y) z = append x (append y z)

x y z. isProperSuffix x y isProperSuffix y z isProperSuffix x z

x y z. isSuffix x y isSuffix y z isSuffix x z

a s.
    toList (cons a s) =
    case toList s of none none | some l some (a :: l)

l s.
    toList (append l s) =
    case toList s of none none | some ls some (l @ ls)

f a s. map f (cons a s) = cons (f a) (map f s)

s a s'. isProperSuffix s (cons a s') s = s' isProperSuffix s s'

x. x = error x = eof a0 a1. x = cons a0 a1

p.
    parse (parseSome p) =
    case none none (λa s. if p a then some (a, s) else none)

f.
    parse (parseOption f) =
    case none none (λa s. case f a of none none | some b some (b, s))

p. (x. (y. isProperSuffix y x p y) p x) x. p x

e b f a s. case e b f (cons a s) = f a s

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 (fromList (concat (map e l))) = fromList l

f a s.
    destParser (parseOption f) a s =
    case f a of none none | some b some (b, s)

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') isSuffix s' s

a0 a1 a0' a1'. cons a0 a1 = cons a0' a1' a0 = a0' a1 = a1'

p e. inverse p e x s. parse p (append (e x) s) = some (x, s)

p e x s.
    inverse p e parseStream p (append (e x) s) = cons x (parseStream p s)

P. P error P eof (a0 a1. P a1 P (cons a0 a1)) x. P x

p e s.
    strongInverse p e
    case toList (parseStream p s) of
      none
    | some l toList s = some (concat (map e l))

p s.
    parse p s = none
    b s'. parse p s = some (b, s') 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 p x xs of none | some (y, xs') isSuffix xs' 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') isSuffix s' s

p a s.
    isParser p p a s = none b s'. p a s = some (b, s') isSuffix s' s

f0 f1 f2.
    fn.
      fn error = f0 fn eof = f1
      a0 a1. fn (cons a0 a1) = f2 a0 a1 (fn a1)

f p s.
    parse (map f p) s =
    case parse p s of none none | some (b, s') some (f b, s')

p e.
    strongInverse p e
    inverse p e s x s'. parse p s = some (x, s') s = append (e x) s'

p a s.
    parseStream p (cons a s) =
    case destParser p a s of
      none error
    | some (b, s') cons b (parseStream p 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 destParser p a s of none none | some (b, s') some (f b, s')

f p s.
    parse (partialMap f p) s =
    case parse p s of
      none none
    | some (b, s') case f b of none none | some c some (c, s')

h.
    (f g s. (s'. 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 destParser p a s of
      none none
    | some (b, s') case f b of none none | some c some (c, s')

f g p b s.
    mapToken.pf f g p b s =
    case destParser p (g b) (map g s) of
      none none
    | some (c, s') some (c, map f s')

d r.
    fromRandom d r =
    let (l, r') Geometric.fromRandom d r in
    let (b, r'') bit r' in
    (append l (if b then error else eof), r'')

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 parse pb s of
      none none
    | some (b, s')
        case parse pc s' of
          none none
        | some (c, s'') some ((b, c), 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 destParser pb a s of
      none none
    | some (b, s')
        case parse pc s' of
          none none
        | some (c, s'') some ((b, c), s'')

External Type Operators

External Constants

Assumptions

¬

¬

length [] = 0

bit0 0 = 0

concat [] = []

t. t t

n. 0 n

n. n n

m. wellFounded (measure m)

p. p

x. id x = x

(¬) = λp. p

() = λp. p ((select) p)

a. ∃!x. x = a

t. (x. t) t

t. (x. t) t

t. (λx. t x) = t

() = λp. p = λx.

a. ¬(some a = none)

t. ¬¬t t

t. ( t) t

t. (t ) t

t. t

t. t t

t. t

t. t t

t. t

t. t t

t. t

t. t t

t. t

t. t t

t. t

n. ¬(suc n = 0)

n. 0 + n = n

m. m + 0 = m

l. [] @ l = l

f. map f [] = []

f. map f none = none

r. wellFounded r irreflexive r

t. ( t) ¬t

t. (t ) ¬t

t. t ¬t

n. even (2 * n)

n. bit1 n = suc (bit0 n)

m. m 0 = 1

x. case none some x = x

() = λp q. p q p

t. (t ) (t )

n. even (suc n) ¬even n

m. m 0 m = 0

t1 t2. (if then t1 else t2) = t2

t1 t2. (if then t1 else t2) = t1

b f. case b f none = b

p x. p x p ((select) p)

n. bit0 (suc n) = suc (suc (bit0 n))

f y. (let x y in f x) = f y

x. a b. x = (a, b)

x y. x = y y = x

t1 t2. t1 t2 t2 t1

m n. m < n m n

r x. irreflexive r ¬r x x

n. 2 * n = n + n

h t. length (h :: t) = suc (length t)

m n. ¬(m < n n m)

m n. ¬(m n n < m)

m n. m < suc n m n

m n. suc m n m < n

x. x = none a. x = some a

f a. map f (some a) = some (f a)

() = λp q. (λf. f p q) = λf. f

p. ¬(x. p x) x. ¬p x

p. ¬(x. p x) x. ¬p x

() = λp. q. (x. p x q) q

a a'. some a = some a' a = a'

t1 t2. ¬(t1 t2) t1 ¬t2

m n. m + suc n = suc (m + n)

m n. suc m + n = suc (m + n)

m n. suc m = suc n m = n

m n. suc m suc n m n

h t. concat (h :: t) = h @ concat t

r s. subrelation r s wellFounded s wellFounded r

b f a. case b f (some a) = f a

f g x. (f g) x = f (g x)

t1 t2. ¬(t1 t2) ¬t1 ¬t2

m n. even (m * n) even m even n

m n. even (m + n) even m even n

m n. m suc n = m * m n

l. l = [] h t. l = h :: t

f g. (x. f x = g x) f = g

p a. (x. a = x p x) p a

() = λp q. r. (p r) (q r) r

m n. m n m < n m = n

m n. m n n m m = n

f. fn. a b. fn (a, b) = f a b

m x y. measure m x y m x < m y

p q. (x. p q x) p x. q x

p q. (x. p q x) p x. q x

p q. p (x. q x) x. p q x

p q. p (x. q x) x. p q x

p q. p (x. q x) x. p q x

p q. p (x. q x) x. p q x

p q. (x. p x) q x. p x q

p q. (x. p x) q x. p x q

t1 t2 t3. (t1 t2) t3 t1 t2 t3

t1 t2 t3. (t1 t2) t3 t1 t2 t3

m n p. m * (n * p) = m * n * p

p m n. m + p = n + p m = n

m n p. m n n p m p

l h t. (h :: t) @ l = h :: t @ l

p x. (y. p y y = x) (select) p = x

r. (x. y. r x y) f. x. r x (f x)

m n. m suc n m = suc n m n

m n. m * n = 0 m = 0 n = 0

f h t. map f (h :: t) = f h :: map f t

p. p 0 (n. p n p (suc n)) n. p n

m n. m n = 0 m = 0 ¬(n = 0)

r s. subrelation r s x y. r x y s x y

(∃!) = λp. () p x y. p x p y x = y

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 0 = e n. fn (suc n) = f (fn n) n

p. p [] (h t. p t p (h :: t)) l. p l

m n p. m * n = m * p m = 0 n = p

m n p. m * n m * p m = 0 n p

m n p. m * n < m * p ¬(m = 0) n < p

a b a' b'. (a, b) = (a', b') a = a' b = b'

p1 p2 q1 q2. (p1 p2) (q1 q2) p1 q1 p2 q2

p1 p2 q1 q2. (p1 p2) (q1 q2) p1 q1 p2 q2

p1 p2 q1 q2. (p2 p1) (q1 q2) (p1 q1) p2 q2

p. (x. ∃!y. p x y) f. x y. p x y f x = y

p c x y. p (if c then x else y) (c p x) (¬c p y)

b f. fn. fn [] = b h t. fn (h :: t) = f h t (fn t)

p. (∃!x. p x) (x. p x) x x'. p x p x' x = x'

r. wellFounded r p. (x. (y. r y x p y) p x) x. p x