Package parser-all: Theory of the whole stream parser

Information

nameparser-all
version1.2
descriptionTheory of the whole stream parser
authorJoe Hurd <joe@gilith.com>
licenseMIT
show Data.Bool
Data.List
Data.Option
Data.Pair
Parser

Files

Defined Constant

Theorems

p s.
    Number.Natural.≤ (Stream.length (parseStream p s)) (Stream.length s)

p e l.
    inverse p e
    parseStream p (Stream.fromList (concat (map e l))) = Stream.fromList l

p e x s.
    inverse p e
    parseStream p (Stream.append (e x) s) =
    Stream.stream x (parseStream p s)

p e s.
    strongInverse p e
    case T (λl. Stream.toList s = some (concat (map e l)))
      (Stream.toList (parseStream p s))

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)

Input Type Operators

Input Constants

Assumptions

T

n. Number.Natural.≤ Number.Numeral.zero n

n. Number.Natural.≤ n n

F p. p

x. ¬Stream.isProperSuffix x x

(¬) = λp. p F

() = λP. P ((select) P)

t. (λx. t x) = t

() = λP. P = λx. T

a'. ¬(none = some a')

x. x = x T

l. Stream.fromList l = Stream.append l Stream.eof

() = λp q. p q p

P x. P x P ((select) P)

p. x y. p = (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'

m n.
    Number.Natural.≤ (Number.Natural.suc m) (Number.Natural.suc n)
    Number.Natural.≤ m n

x y.
    Stream.isSuffix x y
    Number.Natural.≤ (Stream.length x) (Stream.length y)

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

() = λ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

m n p.
    Number.Natural.≤ m n Number.Natural.≤ n p Number.Natural.≤ m p

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

P. (x. y. P x y) y. x. P x (y x)

l s.
    Stream.toList (Stream.append l s) =
    case none (λls. some (l @ ls)) (Stream.toList s)

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

x. x = Stream.error x = Stream.eof a0 a1. x = Stream.stream a0 a1

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

P. P [] (a0 a1. P a1 P (a0 :: a1)) x. P x

p a s b s'. destParser p a s = some (b, s') Stream.isSuffix s' s

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'

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)

(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)

p s.
    parse p s = none
    b s'. parse p s = some (b, s') Stream.isProperSuffix s' s

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

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. parse p Stream.error = none) (p. parse p Stream.eof = none)
  p a s. parse p (Stream.stream a s) = destParser p a s

t. (T t t) (t T t) (F t F) (t F F) (t t t)

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

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'

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

(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