<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Text.ParserCombinators.ReadP</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Text-ParserCombinators-ReadP.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.3.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>non-portable (local universal quantification)</td></tr><tr><th>Stability</th><td>provisional</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr></table><p class="caption">Text.ParserCombinators.ReadP</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">The <code><a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></code> type </a></li><li><a href="#g:2">Primitive operations </a></li><li><a href="#g:3">Other operations </a></li><li><a href="#g:4">Running a parser </a></li><li><a href="#g:5">Properties </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>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". </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:get">get</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:Char">Char</a></li><li class="src short"><a href="#v:look">look</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></li><li class="src short"><a href="#v:-43--43--43-">(+++)</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:-60--43--43-">(<++)</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:gather">gather</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (<a href="Data-Char.html#t:String">String</a>, a)</li><li class="src short"><a href="#v:pfail">pfail</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:eof">eof</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:satisfy">satisfy</a> :: (<a href="Data-Char.html#t:Char">Char</a> -> <a href="Data-Bool.html#t:Bool">Bool</a>) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:Char">Char</a></li><li class="src short"><a href="#v:char">char</a> :: <a href="Data-Char.html#t:Char">Char</a> -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:Char">Char</a></li><li class="src short"><a href="#v:string">string</a> :: <a href="Data-Char.html#t:String">String</a> -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></li><li class="src short"><a href="#v:munch">munch</a> :: (<a href="Data-Char.html#t:Char">Char</a> -> <a href="Data-Bool.html#t:Bool">Bool</a>) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></li><li class="src short"><a href="#v:munch1">munch1</a> :: (<a href="Data-Char.html#t:Char">Char</a> -> <a href="Data-Bool.html#t:Bool">Bool</a>) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></li><li class="src short"><a href="#v:skipSpaces">skipSpaces</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:choice">choice</a> :: [<a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a] -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:count">count</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:between">between</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> open -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> close -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:option">option</a> :: a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:optional">optional</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:many">many</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:many1">many1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:skipMany">skipMany</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:skipMany1">skipMany1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:sepBy">sepBy</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:sepBy1">sepBy1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:endBy">endBy</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:endBy1">endBy1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><a href="#v:chainr">chainr</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:chainl">chainl</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:chainl1">chainl1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:chainr1">chainr1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li><li class="src short"><a href="#v:manyTill">manyTill</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> end -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</li><li class="src short"><span class="keyword">type</span> <a href="#t:ReadS">ReadS</a> a = <a href="Data-Char.html#t:String">String</a> -> [(a, <a href="Data-Char.html#t:String">String</a>)]</li><li class="src short"><a href="#v:readP_to_S">readP_to_S</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadS">ReadS</a> a</li><li class="src short"><a href="#v:readS_to_P">readS_to_P</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadS">ReadS</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</li></ul></div><div id="interface"><h1 id="g:1">The <code><a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></code> type </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ReadP" class="def">ReadP</a> a </p><div class="subs instances"><p id="control.i:ReadP" class="caption collapser" onclick="toggleSection('i:ReadP')">Instances</p><div id="section.i:ReadP" class="show"><table><tr><td class="src"><a href="Control-Monad.html#t:Monad">Monad</a> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad.html#t:Functor">Functor</a> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad.html#t:MonadPlus">MonadPlus</a> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">Primitive operations </h1><div class="top"><p class="src"><a name="v:get" class="def">get</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Consumes and returns the next character. Fails if there is no input left. </p></div></div><div class="top"><p class="src"><a name="v:look" class="def">look</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></p><div class="doc"><p>Look-ahead: returns the part of the input that is left, without consuming it. </p></div></div><div class="top"><p class="src"><a name="v:-43--43--43-" class="def">(+++)</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Symmetric choice. </p></div></div><div class="top"><p class="src"><a name="v:-60--43--43-" class="def">(<++)</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Local, exclusive, left-biased choice: If left parser locally produces any result at all, then right parser is not used. </p></div></div><div class="top"><p class="src"><a name="v:gather" class="def">gather</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (<a href="Data-Char.html#t:String">String</a>, a)</p><div class="doc"><p>Transforms a parser into one that does the same, but in addition returns the exact characters read. IMPORTANT NOTE: <code><a href="Text-ParserCombinators-ReadP.html#v:gather">gather</a></code> gives a runtime error if its first argument is built using any occurrences of readS_to_P. </p></div></div><h1 id="g:3">Other operations </h1><div class="top"><p class="src"><a name="v:pfail" class="def">pfail</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Always fails. </p></div></div><div class="top"><p class="src"><a name="v:eof" class="def">eof</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Succeeds iff we are at the end of input </p></div></div><div class="top"><p class="src"><a name="v:satisfy" class="def">satisfy</a> :: (<a href="Data-Char.html#t:Char">Char</a> -> <a href="Data-Bool.html#t:Bool">Bool</a>) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Consumes and returns the next character, if it satisfies the specified predicate. </p></div></div><div class="top"><p class="src"><a name="v:char" class="def">char</a> :: <a href="Data-Char.html#t:Char">Char</a> -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Parses and returns the specified character. </p></div></div><div class="top"><p class="src"><a name="v:string" class="def">string</a> :: <a href="Data-Char.html#t:String">String</a> -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></p><div class="doc"><p>Parses and returns the specified string. </p></div></div><div class="top"><p class="src"><a name="v:munch" class="def">munch</a> :: (<a href="Data-Char.html#t:Char">Char</a> -> <a href="Data-Bool.html#t:Bool">Bool</a>) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></p><div class="doc"><p>Parses the first zero or more characters satisfying the predicate. Always succeds, exactly once having consumed all the characters Hence NOT the same as (many (satisfy p)) </p></div></div><div class="top"><p class="src"><a name="v:munch1" class="def">munch1</a> :: (<a href="Data-Char.html#t:Char">Char</a> -> <a href="Data-Bool.html#t:Bool">Bool</a>) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="Data-Char.html#t:String">String</a></p><div class="doc"><p>Parses the first one or more characters satisfying the predicate. Fails if none, else succeeds exactly once having consumed all the characters Hence NOT the same as (many1 (satisfy p)) </p></div></div><div class="top"><p class="src"><a name="v:skipSpaces" class="def">skipSpaces</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Skips all whitespace. </p></div></div><div class="top"><p class="src"><a name="v:choice" class="def">choice</a> :: [<a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a] -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Combines all parsers in the specified list. </p></div></div><div class="top"><p class="src"><a name="v:count" class="def">count</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p><code>count n p</code> parses <code>n</code> occurrences of <code>p</code> in sequence. A list of results is returned. </p></div></div><div class="top"><p class="src"><a name="v:between" class="def">between</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> open -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> close -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p><code>between open close p</code> parses <code>open</code>, followed by <code>p</code> and finally <code>close</code>. Only the value of <code>p</code> is returned. </p></div></div><div class="top"><p class="src"><a name="v:option" class="def">option</a> :: a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p><code>option x p</code> will either parse <code>p</code> or return <code>x</code> without consuming any input. </p></div></div><div class="top"><p class="src"><a name="v:optional" class="def">optional</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p><code>optional p</code> optionally parses <code>p</code> and always returns <code>()</code>. </p></div></div><div class="top"><p class="src"><a name="v:many" class="def">many</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p>Parses zero or more occurrences of the given parser. </p></div></div><div class="top"><p class="src"><a name="v:many1" class="def">many1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p>Parses one or more occurrences of the given parser. </p></div></div><div class="top"><p class="src"><a name="v:skipMany" class="def">skipMany</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Like <code><a href="Text-ParserCombinators-ReadP.html#v:many">many</a></code>, but discards the result. </p></div></div><div class="top"><p class="src"><a name="v:skipMany1" class="def">skipMany1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Like <code><a href="Text-ParserCombinators-ReadP.html#v:many1">many1</a></code>, but discards the result. </p></div></div><div class="top"><p class="src"><a name="v:sepBy" class="def">sepBy</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p><code>sepBy p sep</code> parses zero or more occurrences of <code>p</code>, separated by <code>sep</code>. Returns a list of values returned by <code>p</code>. </p></div></div><div class="top"><p class="src"><a name="v:sepBy1" class="def">sepBy1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p><code>sepBy1 p sep</code> parses one or more occurrences of <code>p</code>, separated by <code>sep</code>. Returns a list of values returned by <code>p</code>. </p></div></div><div class="top"><p class="src"><a name="v:endBy" class="def">endBy</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p><code>endBy p sep</code> parses zero or more occurrences of <code>p</code>, separated and ended by <code>sep</code>. </p></div></div><div class="top"><p class="src"><a name="v:endBy1" class="def">endBy1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> sep -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p><code>endBy p sep</code> parses one or more occurrences of <code>p</code>, separated and ended by <code>sep</code>. </p></div></div><div class="top"><p class="src"><a name="v:chainr" class="def">chainr</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p><code>chainr p op x</code> parses zero or more occurrences of <code>p</code>, separated by <code>op</code>. Returns a value produced by a <em>right</em> associative application of all functions returned by <code>op</code>. If there are no occurrences of <code>p</code>, <code>x</code> is returned. </p></div></div><div class="top"><p class="src"><a name="v:chainl" class="def">chainl</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p><code>chainl p op x</code> parses zero or more occurrences of <code>p</code>, separated by <code>op</code>. Returns a value produced by a <em>left</em> associative application of all functions returned by <code>op</code>. If there are no occurrences of <code>p</code>, <code>x</code> is returned. </p></div></div><div class="top"><p class="src"><a name="v:chainl1" class="def">chainl1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Like <code><a href="Text-ParserCombinators-ReadP.html#v:chainl">chainl</a></code>, but parses one or more occurrences of <code>p</code>. </p></div></div><div class="top"><p class="src"><a name="v:chainr1" class="def">chainr1</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> (a -> a -> a) -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Like <code><a href="Text-ParserCombinators-ReadP.html#v:chainr">chainr</a></code>, but parses one or more occurrences of <code>p</code>. </p></div></div><div class="top"><p class="src"><a name="v:manyTill" class="def">manyTill</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> end -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> [a]</p><div class="doc"><p><code>manyTill p end</code> parses zero or more occurrences of <code>p</code>, until <code>end</code> succeeds. Returns a list of values returned by <code>p</code>. </p></div></div><h1 id="g:4">Running a parser </h1><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:ReadS" class="def">ReadS</a> a = <a href="Data-Char.html#t:String">String</a> -> [(a, <a href="Data-Char.html#t:String">String</a>)]</p><div class="doc"><p>A parser for a type <code>a</code>, represented as a function that takes a <code><a href="Data-Char.html#t:String">String</a></code> and returns a list of possible parses as <code>(a,<code><a href="Data-Char.html#t:String">String</a></code>)</code> pairs. </p><p>Note that this kind of backtracking parser is very inefficient; reading a large structure may be quite slow (cf <code><a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:readP_to_S" class="def">readP_to_S</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadS">ReadS</a> a</p><div class="doc"><p>Converts a parser into a Haskell ReadS-style function. This is the main way in which you can "run" a <code><a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a></code> parser: the expanded type is <code> readP_to_S :: ReadP a -> String -> [(a,String)] </code> </p></div></div><div class="top"><p class="src"><a name="v:readS_to_P" class="def">readS_to_P</a> :: <a href="Text-ParserCombinators-ReadP.html#t:ReadS">ReadS</a> a -> <a href="Text-ParserCombinators-ReadP.html#t:ReadP">ReadP</a> a</p><div class="doc"><p>Converts a Haskell ReadS-style function into a parser. Warning: This introduces local backtracking in the resulting parser, and therefore a possible inefficiency. </p></div></div><h1 id="g:5">Properties </h1><div class="doc"><p>The following are QuickCheck specifications of what the combinators do. These can be seen as formal specifications of the behavior of the combinators. </p><p>We use bags to give semantics to the combinators. </p><pre> type Bag a = [a] </pre><p>Equality on bags does not care about the order of elements. </p><pre> (=~) :: Ord a => Bag a -> Bag a -> Bool xs =~ ys = sort xs == sort ys </pre><p>A special equality operator to avoid unresolved overloading when testing the properties. </p><pre> (=~.) :: Bag (Int,String) -> Bag (Int,String) -> Bool (=~.) = (=~) </pre><p>Here follow the properties: </p><pre> prop_Get_Nil = readP_to_S get [] =~ [] prop_Get_Cons c s = readP_to_S get (c:s) =~ [(c,s)] prop_Look s = readP_to_S look s =~ [(s,s)] prop_Fail s = readP_to_S pfail 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 =~. (readP_to_S p s ++ readP_to_S q s) prop_LeftPlus p q s = readP_to_S (p <++ q) s =~. (readP_to_S p s +<+ readP_to_S q s) where [] +<+ ys = ys xs +<+ _ = xs prop_Gather s = forAll readPWithoutReadS $ \p -> readP_to_S (gather p) 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 = readP_to_S (string this) s =~ [(this, drop (length this) s) | this `isPrefixOf` s] prop_Munch p s = readP_to_S (munch p) s =~ [(takeWhile p s, dropWhile p s)] prop_Munch1 p s = readP_to_S (munch1 p) s =~ [(res,s') | let (res,s') = (takeWhile p s, dropWhile p s), not (null res)] prop_Choice ps s = readP_to_S (choice ps) s =~. readP_to_S (foldr (+++) pfail ps) s prop_ReadS r s = readP_to_S (readS_to_P r) s =~. r s </pre></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>