<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--Rendered using the Haskell Html Library v0.2--> <HTML ><HEAD ><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" ><TITLE >Text.ParserCombinators.ReadP</TITLE ><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css" ><SCRIPT SRC="haddock-util.js" TYPE="text/javascript" ></SCRIPT ><SCRIPT TYPE="text/javascript" >window.onload = function () {setSynopsis("mini_Text-ParserCombinators-ReadP.html")};</SCRIPT ></HEAD ><BODY ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="topbar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" " ></TD ><TD CLASS="title" >base-4.2.0.2: Basic libraries</TD ><TD CLASS="topbut" ><A HREF="index.html" >Contents</A ></TD ><TD CLASS="topbut" ><A HREF="doc-index.html" >Index</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="modulebar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><FONT SIZE="6" >Text.ParserCombinators.ReadP</FONT ></TD ><TD ALIGN="right" ><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="infohead" >Portability</TD ><TD CLASS="infoval" >non-portable (local universal quantification)</TD ></TR ><TR ><TD CLASS="infohead" >Stability</TD ><TD CLASS="infoval" >provisional</TD ></TR ><TR ><TD CLASS="infohead" >Maintainer</TD ><TD CLASS="infoval" >libraries@haskell.org</TD ></TR ></TABLE ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="section4" ><B >Contents</B ></TD ></TR ><TR ><TD ><DL ><DT ><A HREF="#1" >The <TT ><A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TT > type </A ></DT ><DT ><A HREF="#2" >Primitive operations </A ></DT ><DT ><A HREF="#3" >Other operations </A ></DT ><DT ><A HREF="#4" >Running a parser </A ></DT ><DT ><A HREF="#5" >Properties </A ></DT ></DL ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Description</TD ></TR ><TR ><TD CLASS="doc" >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". </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Synopsis</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A HREF="#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aget" >get</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Alook" >look</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3A%2B%2B%2B" >(+++)</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3A%3C%2B%2B" >(<++)</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Agather" >gather</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (<A HREF="Data-Char.html#t%3AString" >String</A >, a)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Apfail" >pfail</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aeof" >eof</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Asatisfy" >satisfy</A > :: (<A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Achar" >char</A > :: <A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Astring" >string</A > :: <A HREF="Data-Char.html#t%3AString" >String</A > -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amunch" >munch</A > :: (<A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amunch1" >munch1</A > :: (<A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AskipSpaces" >skipSpaces</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Achoice" >choice</A > :: [<A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a] -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Acount" >count</A > :: <A HREF="Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Abetween" >between</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > open -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > close -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aoption" >option</A > :: a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aoptional" >optional</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amany" >many</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amany1" >many1</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AskipMany" >skipMany</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AskipMany1" >skipMany1</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AsepBy" >sepBy</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AsepBy1" >sepBy1</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AendBy" >endBy</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AendBy1" >endBy1</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Achainr" >chainr</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Achainl" >chainl</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Achainl1" >chainl1</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Achainr1" >chainr1</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AmanyTill" >manyTill</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > end -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >type</SPAN > <A HREF="#t%3AReadS" >ReadS</A > a = <A HREF="Data-Char.html#t%3AString" >String</A > -> [(a, <A HREF="Data-Char.html#t%3AString" >String</A >)]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AreadP_to_S" >readP_to_S</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadS" >ReadS</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AreadS_to_P" >readS_to_P</A > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadS" >ReadS</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="1" ><A NAME="1" >The <TT ><A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TT > type </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A NAME="t:ReadP" ><A NAME="t%3AReadP" ></A ></A ><B >ReadP</B > a </TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:ReadP')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:ReadP" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="Control-Monad.html#t%3AMonad" >Monad</A > <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad.html#t%3AFunctor" >Functor</A > <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad.html#t%3AMonadPlus" >MonadPlus</A > <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="2" ><A NAME="2" >Primitive operations </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:get" ><A NAME="v%3Aget" ></A ></A ><B >get</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="doc" >Consumes and returns the next character. Fails if there is no input left. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:look" ><A NAME="v%3Alook" ></A ></A ><B >look</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="doc" >Look-ahead: returns the part of the input that is left, without consuming it. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:+++" ><A NAME="v%3A%2B%2B%2B" ></A ></A ><B >(+++)</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Symmetric choice. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:<++" ><A NAME="v%3A%3C%2B%2B" ></A ></A ><B >(<++)</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Local, exclusive, left-biased choice: If left parser locally produces any result at all, then right parser is not used. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:gather" ><A NAME="v%3Agather" ></A ></A ><B >gather</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (<A HREF="Data-Char.html#t%3AString" >String</A >, a)</TD ></TR ><TR ><TD CLASS="doc" >Transforms a parser into one that does the same, but in addition returns the exact characters read. IMPORTANT NOTE: <TT ><A HREF="Text-ParserCombinators-ReadP.html#v%3Agather" >gather</A ></TT > gives a runtime error if its first argument is built using any occurrences of readS_to_P. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="3" ><A NAME="3" >Other operations </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:pfail" ><A NAME="v%3Apfail" ></A ></A ><B >pfail</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Always fails. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:eof" ><A NAME="v%3Aeof" ></A ></A ><B >eof</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" >Succeeds iff we are at the end of input </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:satisfy" ><A NAME="v%3Asatisfy" ></A ></A ><B >satisfy</B > :: (<A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="doc" >Consumes and returns the next character, if it satisfies the specified predicate. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:char" ><A NAME="v%3Achar" ></A ></A ><B >char</B > :: <A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="doc" >Parses and returns the specified character. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:string" ><A NAME="v%3Astring" ></A ></A ><B >string</B > :: <A HREF="Data-Char.html#t%3AString" >String</A > -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="doc" >Parses and returns the specified string. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:munch" ><A NAME="v%3Amunch" ></A ></A ><B >munch</B > :: (<A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="doc" >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)) </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:munch1" ><A NAME="v%3Amunch1" ></A ></A ><B >munch1</B > :: (<A HREF="Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="doc" >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)) </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:skipSpaces" ><A NAME="v%3AskipSpaces" ></A ></A ><B >skipSpaces</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" >Skips all whitespace. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:choice" ><A NAME="v%3Achoice" ></A ></A ><B >choice</B > :: [<A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a] -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Combines all parsers in the specified list. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:count" ><A NAME="v%3Acount" ></A ></A ><B >count</B > :: <A HREF="Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" ><TT >count n p</TT > parses <TT >n</TT > occurrences of <TT >p</TT > in sequence. A list of results is returned. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:between" ><A NAME="v%3Abetween" ></A ></A ><B >between</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > open -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > close -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" ><TT >between open close p</TT > parses <TT >open</TT >, followed by <TT >p</TT > and finally <TT >close</TT >. Only the value of <TT >p</TT > is returned. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:option" ><A NAME="v%3Aoption" ></A ></A ><B >option</B > :: a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" ><TT >option x p</TT > will either parse <TT >p</TT > or return <TT >x</TT > without consuming any input. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:optional" ><A NAME="v%3Aoptional" ></A ></A ><B >optional</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" ><TT >optional p</TT > optionally parses <TT >p</TT > and always returns <TT >()</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:many" ><A NAME="v%3Amany" ></A ></A ><B >many</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" >Parses zero or more occurrences of the given parser. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:many1" ><A NAME="v%3Amany1" ></A ></A ><B >many1</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" >Parses one or more occurrences of the given parser. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:skipMany" ><A NAME="v%3AskipMany" ></A ></A ><B >skipMany</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" >Like <TT ><A HREF="Text-ParserCombinators-ReadP.html#v%3Amany" >many</A ></TT >, but discards the result. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:skipMany1" ><A NAME="v%3AskipMany1" ></A ></A ><B >skipMany1</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > <A HREF="../ghc-prim-0.2.0.0/GHC-Unit.html#t%3A%28%29" >()</A ></TD ></TR ><TR ><TD CLASS="doc" >Like <TT ><A HREF="Text-ParserCombinators-ReadP.html#v%3Amany1" >many1</A ></TT >, but discards the result. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:sepBy" ><A NAME="v%3AsepBy" ></A ></A ><B >sepBy</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" ><TT >sepBy p sep</TT > parses zero or more occurrences of <TT >p</TT >, separated by <TT >sep</TT >. Returns a list of values returned by <TT >p</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:sepBy1" ><A NAME="v%3AsepBy1" ></A ></A ><B >sepBy1</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" ><TT >sepBy1 p sep</TT > parses one or more occurrences of <TT >p</TT >, separated by <TT >sep</TT >. Returns a list of values returned by <TT >p</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:endBy" ><A NAME="v%3AendBy" ></A ></A ><B >endBy</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" ><TT >endBy p sep</TT > parses zero or more occurrences of <TT >p</TT >, separated and ended by <TT >sep</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:endBy1" ><A NAME="v%3AendBy1" ></A ></A ><B >endBy1</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > sep -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" ><TT >endBy p sep</TT > parses one or more occurrences of <TT >p</TT >, separated and ended by <TT >sep</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:chainr" ><A NAME="v%3Achainr" ></A ></A ><B >chainr</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" ><TT >chainr p op x</TT > parses zero or more occurrences of <TT >p</TT >, separated by <TT >op</TT >. Returns a value produced by a <EM >right</EM > associative application of all functions returned by <TT >op</TT >. If there are no occurrences of <TT >p</TT >, <TT >x</TT > is returned. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:chainl" ><A NAME="v%3Achainl" ></A ></A ><B >chainl</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" ><TT >chainl p op x</TT > parses zero or more occurrences of <TT >p</TT >, separated by <TT >op</TT >. Returns a value produced by a <EM >left</EM > associative application of all functions returned by <TT >op</TT >. If there are no occurrences of <TT >p</TT >, <TT >x</TT > is returned. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:chainl1" ><A NAME="v%3Achainl1" ></A ></A ><B >chainl1</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Like <TT ><A HREF="Text-ParserCombinators-ReadP.html#v%3Achainl" >chainl</A ></TT >, but parses one or more occurrences of <TT >p</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:chainr1" ><A NAME="v%3Achainr1" ></A ></A ><B >chainr1</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > (a -> a -> a) -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Like <TT ><A HREF="Text-ParserCombinators-ReadP.html#v%3Achainr" >chainr</A ></TT >, but parses one or more occurrences of <TT >p</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:manyTill" ><A NAME="v%3AmanyTill" ></A ></A ><B >manyTill</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > end -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > [a]</TD ></TR ><TR ><TD CLASS="doc" ><TT >manyTill p end</TT > parses zero or more occurrences of <TT >p</TT >, until <TT >end</TT > succeeds. Returns a list of values returned by <TT >p</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="4" ><A NAME="4" >Running a parser </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >type</SPAN > <A NAME="t:ReadS" ><A NAME="t%3AReadS" ></A ></A ><B >ReadS</B > a = <A HREF="Data-Char.html#t%3AString" >String</A > -> [(a, <A HREF="Data-Char.html#t%3AString" >String</A >)]</TD ></TR ><TR ><TD CLASS="doc" ><P >A parser for a type <TT >a</TT >, represented as a function that takes a <TT ><A HREF="Data-Char.html#t%3AString" >String</A ></TT > and returns a list of possible parses as <TT >(a,<TT ><A HREF="Data-Char.html#t%3AString" >String</A ></TT >)</TT > pairs. </P ><P >Note that this kind of backtracking parser is very inefficient; reading a large structure may be quite slow (cf <TT ><A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TT >). </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:readP_to_S" ><A NAME="v%3AreadP_to_S" ></A ></A ><B >readP_to_S</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadS" >ReadS</A > a</TD ></TR ><TR ><TD CLASS="doc" >Converts a parser into a Haskell ReadS-style function. This is the main way in which you can "run" a <TT ><A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A ></TT > parser: the expanded type is <TT > readP_to_S :: ReadP a -> String -> [(a,String)] </TT > </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:readS_to_P" ><A NAME="v%3AreadS_to_P" ></A ></A ><B >readS_to_P</B > :: <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadS" >ReadS</A > a -> <A HREF="Text-ParserCombinators-ReadP.html#t%3AReadP" >ReadP</A > a</TD ></TR ><TR ><TD CLASS="doc" >Converts a Haskell ReadS-style function into a parser. Warning: This introduces local backtracking in the resulting parser, and therefore a possible inefficiency. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="5" ><A NAME="5" >Properties </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD 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 ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="botbar" >Produced by <A HREF="http://www.haskell.org/haddock/" >Haddock</A > version 2.6.1</TD ></TR ></TABLE ></BODY ></HTML >