packages feed

polyparse-1.0: docs/haddock/Text-Parse.html

<!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.Parse</TITLE
><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css"
><SCRIPT SRC="haddock.js" TYPE="text/javascript"
></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"
>polyparse</TD
><TD CLASS="topbut"
><A HREF="src/Text/Parse.html"
>Source code</A
></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.Parse</FONT
></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 Parse class is a replacement for the standard Read class. 
</A
></DT
><DD
><DL
><DT
><A HREF="#2"
>Combinators specific to string input, lexed haskell-style
</A
></DT
><DT
><A HREF="#3"
>Re-export all the more general combinators from Poly too
</A
></DT
></DL
></DD
></DL
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></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"
>type</SPAN
> <A HREF="#t%3ATextParser"
>TextParser</A
> a = <A HREF="Text-ParserCombinators-Poly.html#t%3AParser"
>Parser</A
> Char a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><SPAN CLASS="keyword"
>class</SPAN
> <A HREF="#t%3AParse"
>Parse</A
> a  <SPAN CLASS="keyword"
>where</SPAN
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="#v%3Aparse"
>parse</A
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AparseList"
>parseList</A
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> [a]</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AparseByRead"
>parseByRead</A
> :: Read a =&gt; String -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Aword"
>word</A
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> String</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AisWord"
>isWord</A
> :: String -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> String</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AoptionalParens"
>optionalParens</A
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Afield"
>field</A
> :: <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a =&gt; String -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Aconstructors"
>constructors</A
> :: [(String, <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a)] -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Aenumeration"
>enumeration</A
> :: Show a =&gt; String -&gt; [a] -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
>module <A HREF="Text-ParserCombinators-Poly.html"
>Text.ParserCombinators.Poly</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"
>The Parse class is a replacement for the standard Read class. 
</A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="doc"
>The Parse class is a replacement for the standard Read class.  It is a
 specialisation of the (poly) Parser monad for String input.
 There are instances defined for all Prelude types.
 For user-defined types, you can write your own instance, or use
 DrIFT to generate them automatically, e.g. {-! derive : Parse !-}
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><SPAN CLASS="keyword"
>type</SPAN
> <A NAME="t%3ATextParser"
></A
><B
>TextParser</B
> a = <A HREF="Text-ParserCombinators-Poly.html#t%3AParser"
>Parser</A
> Char a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#TextParser"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>A synonym for Parser Char, i.e. string input (no state)
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><SPAN CLASS="keyword"
>class</SPAN
> <A NAME="t%3AParse"
></A
><B
>Parse</B
> a  <SPAN CLASS="keyword"
>where</SPAN
></TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#Parse"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="ndoc"
>The class <TT
>Parse</TT
> is a replacement for <TT
>Read</TT
>, operating over String input.
   Essentially, it permits better error messages for why something failed to
   parse.  It is rather important that <TT
>parse</TT
> can read back exactly what
   is generated by the corresponding instance of <TT
>show</TT
>.  To apply a parser
   to some text, use <TT
>runParser</TT
>.
</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="section4"
>Methods</TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3Aparse"
></A
><B
>parse</B
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#parse"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3AparseList"
></A
><B
>parseList</B
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> [a]</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#parseList"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="section4"
><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Parse')" ALT="show/hide"
> Instances</TD
></TR
><TR
><TD CLASS="body"
><DIV ID="i:Parse" STYLE="display:block;"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Bool</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Char</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Double</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Float</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Int</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Integer</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> Ordering</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> ()</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a, <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> b) =&gt; <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> (a, b)</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a, <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> b, <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> c) =&gt; <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> (a, b, c)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a =&gt; <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> (Maybe a)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a =&gt; <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> [a]</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a, <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> b) =&gt; <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> (Either a b)</TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3AparseByRead"
></A
><B
>parseByRead</B
> :: Read a =&gt; String -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#parseByRead"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>If there already exists a Read instance for a type, then we can make
   a Parser for it, but with only poor error-reporting.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section2"
><A NAME="2"
>Combinators specific to string input, lexed haskell-style
</A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3Aword"
></A
><B
>word</B
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> String</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#word"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>One lexical chunk (Haskell-style lexing).
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3AisWord"
></A
><B
>isWord</B
> :: String -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> String</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#isWord"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Ensure that the next input word is the given string.  (Note the input
   is lexed as haskell, so wordbreaks at spaces, symbols, etc.)
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3AoptionalParens"
></A
><B
>optionalParens</B
> :: <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#optionalParens"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Allow true string parens around an item.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3Afield"
></A
><B
>field</B
> :: <A HREF="Text-Parse.html#t%3AParse"
>Parse</A
> a =&gt; String -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#field"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Deal with named field syntax.  The string argument is the field name,
   and the parser returns the value of the field.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3Aconstructors"
></A
><B
>constructors</B
> :: [(String, <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a)] -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#constructors"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Parse one of a bunch of alternative constructors.  In the list argument,
   the first element of the pair is the constructor name, and
   the second is the parser for the rest of the value.  The first matching
   parse is returned.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v%3Aenumeration"
></A
><B
>enumeration</B
> :: Show a =&gt; String -&gt; [a] -&gt; <A HREF="Text-Parse.html#t%3ATextParser"
>TextParser</A
> a</TD
><TD CLASS="declbut"
><A HREF="src/Text/Parse.html#enumeration"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Parse one of the given nullary constructors (an enumeration).
   The string argument is the name of the type, and the list argument
   should contain all of the possible enumeration values.
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section2"
><A NAME="3"
>Re-export all the more general combinators from Poly too
</A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
>module <A HREF="Text-ParserCombinators-Poly.html"
>Text.ParserCombinators.Poly</A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="botbar"
>Produced by <A HREF="http://www.haskell.org/haddock/"
>Haddock</A
> version 0.8</TD
></TR
></TABLE
></BODY
></HTML
>