Safe Haskell | Safe-Infered |
---|
- data K7 a b c d = K7 {}
- newtype Sym a b = Sym {}
- type C r = (String -> r) -> String -> r
- type PP a = forall r r'. K7 (C (a -> r)) (C r) (C (a -> r')) (C r')
- type PP0 = forall r r'. K7 (C r) (C r) (C r') (C r')
- (<>) :: K7 b c b' c' -> K7 a b a' b' -> K7 a c a' c'
- (-->) :: K7 a b a' b' -> K7 b c b' c' -> K7 a c a' c'
- (<|>) :: PP a -> PP a -> PP a
- play :: K7 a b c d -> a -> b
- flip :: K7 a b c d -> K7 d c b a
- parse :: PP a -> String -> Maybe a
- pretty :: PP a -> a -> Maybe String
- empty :: PP0
- nothing :: PP0
- shift :: a -> PP0 -> PP a
- unshift :: a -> PP a -> PP0
- string :: String -> PP0
- satisfy :: (Char -> Bool) -> PP Char
- lookAhead :: PP a -> PP a
- eof :: PP0
Datatypes
A cassette consists of two tracks, represented by functions. The functions on each track are not necessarily inverses of each other, and do not necessarily connect the same start and end types.
type C r = (String -> r) -> String -> rSource
The type of string transformers in CPS, i.e. functions from strings to strings.
type PP a = forall r r'. K7 (C (a -> r)) (C r) (C (a -> r')) (C r')Source
The type of cassettes with a string transformer on each side. The A-side produces a value in addition to transforming the string, i.e. it is a parser. The B-side consumes a value to transform the string, i.e. it is a printer.
Composition
(<>) :: K7 b c b' c' -> K7 a b a' b' -> K7 a c a' c'Source
Tape splicing operator. Functions on each track are composed pairwise.
(<|>) :: PP a -> PP a -> PP aSource
Choice operator. If the first cassette fails, then try the second parser. Note that this is an unrestricted backtracking operator: it never commits to any particular choice.
Extraction
Primitive combinators
shift :: a -> PP0 -> PP aSource
Turn the given pure transformer into a parsing/printing pair. That is,
return a cassette that produces and output on the one side, and consumes an
input on the other, in addition to the string transformations of the given
pure transformer. shift x p
produces x
as the output of p
on the
parsing side, and on the printing side accepts an input that is ignored.