Portability non-portable (local universal quantification) Stability provisional Maintainer libraries@haskell.org
 Contents The ReadP typePrimitive operationsOther operationsRunning a parserProperties
Description

This is a library of parser combinators, originally written by Koen Claessen. It parses all alternatives in parallel, so it never keeps hold of the beginning of the input string, a common source of space leaks with other parsers. The '(+++)' choice combinator is genuinely commutative; it makes no difference which branch is "shorter".

This version of ReadP has been locally hacked to make it H98, by Martin Sj&#xF6;gren mailto:msjogren@gmail.com

Synopsis
 type ReadP r a = Parser r Char a
type ReadP r a = Parser r Char a
Primitive operations
Other operations
Running a parser
Properties

The following are QuickCheck specifications of what the combinators do. These can be seen as formal specifications of the behavior of the combinators.

We use bags to give semantics to the combinators.

```  type Bag a = [a]
```

Equality on bags does not care about the order of elements.

```  (=~) :: Ord a => Bag a -> Bag a -> Bool
xs =~ ys = sort xs == sort ys
```

A special equality operator to avoid unresolved overloading when testing the properties.

```  (=~.) :: Bag (Int,String) -> Bag (Int,String) -> Bool
(=~.) = (=~)
```

```  prop_Get_Nil =

prop_Get_Cons c s =

prop_Look s =

prop_Fail s =

prop_Return x s =
readP_to_S (return x) s =~. [(x,s)]

prop_Bind p k s =
readP_to_S (p >>= k) s =~.
[ ys''
| (x,s') <- readP_to_S p s
, ys''   <- readP_to_S (k (x::Int)) s'
]

prop_Plus p q s =
readP_to_S (p +++ q) s =~.

prop_LeftPlus p q s =
readP_to_S (p <++ q) s =~.
where
[] +<+ ys = ys
xs +<+ _  = xs

prop_Gather s =
[ ((pre,x::Int),s')
| (x,s') <- readP_to_S p s
, let pre = take (length s - length s') s
]

prop_String_Yes this s =
readP_to_S (string this) (this ++ s) =~
[(this,s)]

prop_String_Maybe this s =
[(this, drop (length this) s) | this `isPrefixOf` s]

prop_Munch p s =
[(takeWhile p s, dropWhile p s)]

prop_Munch1 p s =