-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Monadic parser combinators
°5u
°5uParsec is designed from scratch as an industrial-strength parser
°5ulibrary. It is simple, safe, well documented (on the package
°5uhomepage), has extensive libraries, good error messages, and is fast.
°5uIt is defined as a monad transformer that can be stacked on arbitrary
°5umonads, and it is also parametric in the input stream type.
@package parsec
@version 3.1.12


-- | Textual source positions.
module Text.Parsec.Pos
type SourceName = String
type Line = Int
type Column = Int

-- | The abstract data type <tt>SourcePos</tt> represents source positions.
°5uIt contains the name of the source (i.e. file name), a line number and
°5ua column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
°5u<a>Eq</a> and <a>Ord</a> class.
data SourcePos

-- | Extracts the line number from a source position.
sourceLine :: SourcePos -> Line

-- | Extracts the column number from a source position.
sourceColumn :: SourcePos -> Column

-- | Extracts the name of the source from a source position.
sourceName :: SourcePos -> SourceName

-- | Increments the line number of a source position.
incSourceLine :: SourcePos -> Line -> SourcePos

-- | Increments the column number of a source position.
incSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the line number of a source position.
setSourceLine :: SourcePos -> Line -> SourcePos

-- | Set the column number of a source position.
setSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the name of the source.
setSourceName :: SourcePos -> SourceName -> SourcePos

-- | Create a new <a>SourcePos</a> with the given source name, line number
°5uand column number.
newPos :: SourceName -> Line -> Column -> SourcePos

-- | Create a new <a>SourcePos</a> with the given source name, and line
°5unumber and column number set to 1, the upper left.
initialPos :: SourceName -> SourcePos

-- | Update a source position given a character. If the character is a
°5unewline ('\n') or carriage return ('\r') the line number is
°5uincremented by 1. If the character is a tab ('t') the column number is
°5uincremented to the nearest 8'th column, ie. <tt>column + 8 -
°5u((column-1) `mod` 8)</tt>. In all other cases, the column is
°5uincremented by 1.
updatePosChar :: SourcePos -> Char -> SourcePos

-- | The expression <tt>updatePosString pos s</tt> updates the source
°5uposition <tt>pos</tt> by calling <a>updatePosChar</a> on every
°5ucharacter in <tt>s</tt>, ie. <tt>foldl updatePosChar pos string</tt>.
updatePosString :: SourcePos -> String -> SourcePos
instance Data.Data.Data Text.Parsec.Pos.SourcePos
instance GHC.Classes.Ord Text.Parsec.Pos.SourcePos
instance GHC.Classes.Eq Text.Parsec.Pos.SourcePos
instance GHC.Show.Show Text.Parsec.Pos.SourcePos


-- | Parse errors
module Text.Parsec.Error

-- | This abstract data type represents parse error messages. There are
°5ufour kinds of messages:
°5u
°5u<pre>
°5udata Message = SysUnExpect String
°5u             | UnExpect String
°5u             | Expect String
°5u             | Message String
°5u</pre>
°5u
°5uThe fine distinction between different kinds of parse errors allows
°5uthe system to generate quite good error messages for the user. It also
°5uallows error messages that are formatted in different languages. Each
°5ukind of message is generated by different combinators:
°5u
°5u<ul>
°5u<li>A <a>SysUnExpect</a> message is automatically generated by the
°5u<a>satisfy</a> combinator. The argument is the unexpected input.</li>
°5u<li>A <a>UnExpect</a> message is generated by the <a>unexpected</a>
°5ucombinator. The argument describes the unexpected item.</li>
°5u<li>A <a>Expect</a> message is generated by the <a>&lt;?&gt;</a>
°5ucombinator. The argument describes the expected item.</li>
°5u<li>A <a>Message</a> message is generated by the <a>fail</a>
°5ucombinator. The argument is some general parser message.</li>
°5u</ul>
data Message
SysUnExpect :: !String -> Message
UnExpect :: !String -> Message
Expect :: !String -> Message
Message :: !String -> Message

-- | Extract the message string from an error message
messageString :: Message -> String

-- | The abstract data type <tt>ParseError</tt> represents parse errors. It
°5uprovides the source position (<a>SourcePos</a>) of the error and a
°5ulist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
°5ureturned by the function <a>parse</a>. <tt>ParseError</tt> is an
°5uinstance of the <a>Show</a> and <a>Eq</a> classes.
data ParseError

-- | Extracts the source position from the parse error
errorPos :: ParseError -> SourcePos

-- | Extracts the list of error messages from the parse error
errorMessages :: ParseError -> [Message]
errorIsUnknown :: ParseError -> Bool
showErrorMessages :: String -> String -> String -> String -> String -> [Message] -> String
newErrorMessage :: Message -> SourcePos -> ParseError
newErrorUnknown :: SourcePos -> ParseError
addErrorMessage :: Message -> ParseError -> ParseError
setErrorPos :: SourcePos -> ParseError -> ParseError
setErrorMessage :: Message -> ParseError -> ParseError
mergeError :: ParseError -> ParseError -> ParseError
instance GHC.Show.Show Text.Parsec.Error.ParseError
instance GHC.Classes.Eq Text.Parsec.Error.ParseError
instance GHC.Enum.Enum Text.Parsec.Error.Message
instance GHC.Classes.Eq Text.Parsec.Error.Message
instance GHC.Classes.Ord Text.Parsec.Error.Message


-- | The primitive parser combinators.
module Text.Parsec.Prim
unknownError :: State s u -> ParseError
sysUnExpectError :: String -> SourcePos -> Reply s u a

-- | The parser <tt>unexpected msg</tt> always fails with an unexpected
°5uerror message <tt>msg</tt> without consuming any input.
°5u
°5uThe parsers <a>fail</a>, (<a>&lt;?&gt;</a>) and <tt>unexpected</tt>
°5uare the three parsers used to generate error messages. Of these, only
°5u(<a>&lt;?&gt;</a>) is commonly used. For an example of the use of
°5u<tt>unexpected</tt>, see the definition of <a>notFollowedBy</a>.
unexpected :: (Stream s m t) => String -> ParsecT s u m a

-- | ParserT monad transformer and Parser type
°5u
°5u<tt>ParsecT s u m a</tt> is a parser with stream type <tt>s</tt>, user
°5ustate type <tt>u</tt>, underlying monad <tt>m</tt> and return type
°5u<tt>a</tt>. Parsec is strict in the user state. If this is
°5uundesirable, simply used a data type like <tt>data Box a = Box a</tt>
°5uand the state type <tt>Box YourStateType</tt> to add a level of
°5uindirection.
data ParsecT s u m a

-- | Low-level unpacking of the ParsecT type. To run your parser, please
°5ulook to runPT, runP, runParserT, runParser and other such functions.
runParsecT :: Monad m => ParsecT s u m a -> State s u -> m (Consumed (m (Reply s u a)))

-- | Low-level creation of the ParsecT type. You really shouldn't have to
°5udo this.
mkPT :: Monad m => (State s u -> m (Consumed (m (Reply s u a)))) -> ParsecT s u m a
type Parsec s u = ParsecT s u Identity
data Consumed a
Consumed :: a -> Consumed a
Empty :: !a -> Consumed a
data Reply s u a
Ok :: a -> !(State s u) -> ParseError -> Reply s u a
Error :: ParseError -> Reply s u a
data State s u
State :: s -> !SourcePos -> !u -> State s u
[stateInput] :: State s u -> s
[statePos] :: State s u -> !SourcePos
[stateUser] :: State s u -> !u
parsecMap :: (a -> b) -> ParsecT s u m a -> ParsecT s u m b
parserReturn :: a -> ParsecT s u m a
parserBind :: ParsecT s u m a -> (a -> ParsecT s u m b) -> ParsecT s u m b
mergeErrorReply :: ParseError -> Reply s u a -> Reply s u a
parserFail :: String -> ParsecT s u m a

-- | <tt>parserZero</tt> always fails without consuming any input.
°5u<tt>parserZero</tt> is defined equal to the <a>mzero</a> member of the
°5u<a>MonadPlus</a> class and to the <a>empty</a> member of the
°5u<a>Alternative</a> class.
parserZero :: ParsecT s u m a
parserPlus :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>p &lt;?&gt; msg</tt> behaves as parser <tt>p</tt>, but
°5uwhenever the parser <tt>p</tt> fails <i>without consuming any
°5uinput</i>, it replaces expect error messages with the expect error
°5umessage <tt>msg</tt>.
°5u
°5uThis is normally used at the end of a set alternatives where we want
°5uto return an error message in terms of a higher level construct rather
°5uthan returning all possible characters. For example, if the
°5u<tt>expr</tt> parser from the <a>try</a> example would fail, the error
°5umessage is: '...: expecting expression'. Without the
°5u<tt>(&lt;?&gt;)</tt> combinator, the message would be like '...:
°5uexpecting "let" or letter', which is less friendly.
(<?>) :: (ParsecT s u m a) -> String -> (ParsecT s u m a)
infix 0 <?>

-- | This combinator implements choice. The parser <tt>p &lt;|&gt; q</tt>
°5ufirst applies <tt>p</tt>. If it succeeds, the value of <tt>p</tt> is
°5ureturned. If <tt>p</tt> fails <i>without consuming any input</i>,
°5uparser <tt>q</tt> is tried. This combinator is defined equal to the
°5u<a>mplus</a> member of the <a>MonadPlus</a> class and the
°5u(<a>&lt;|&gt;</a>) member of <a>Alternative</a>.
°5u
°5uThe parser is called <i>predictive</i> since <tt>q</tt> is only tried
°5uwhen parser <tt>p</tt> didn't consume any input (i.e.. the look ahead
°5uis 1). This non-backtracking behaviour allows for both an efficient
°5uimplementation of the parser combinators and the generation of good
°5uerror messages.
(<|>) :: (ParsecT s u m a) -> (ParsecT s u m a) -> (ParsecT s u m a)
infixr 1 <|>

-- | A synonym for <tt>&lt;?&gt;</tt>, but as a function instead of an
°5uoperator.
label :: ParsecT s u m a -> String -> ParsecT s u m a
labels :: ParsecT s u m a -> [String] -> ParsecT s u m a

-- | <tt>lookAhead p</tt> parses <tt>p</tt> without consuming any input.
°5u
°5uIf <tt>p</tt> fails and consumes some input, so does
°5u<tt>lookAhead</tt>. Combine with <a>try</a> if this is undesirable.
lookAhead :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m a

-- | An instance of <tt>Stream</tt> has stream type <tt>s</tt>, underlying
°5umonad <tt>m</tt> and token type <tt>t</tt> determined by the stream
°5u
°5uSome rough guidelines for a "correct" instance of Stream:
°5u
°5u<ul>
°5u<li>unfoldM uncons gives the [t] corresponding to the stream</li>
°5u<li>A <tt>Stream</tt> instance is responsible for maintaining the
°5u"position within the stream" in the stream state <tt>s</tt>. This is
°5utrivial unless you are using the monad in a non-trivial way.</li>
°5u</ul>
class (Monad m) => Stream s m t | s -> t
uncons :: Stream s m t => s -> m (Maybe (t, s))
tokens :: (Stream s m t, Eq t) => ([t] -> String) -> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t]

-- | The parser <tt>try p</tt> behaves like parser <tt>p</tt>, except that
°5uit pretends that it hasn't consumed any input when an error occurs.
°5u
°5uThis combinator is used whenever arbitrary look ahead is needed. Since
°5uit pretends that it hasn't consumed any input when <tt>p</tt> fails,
°5uthe (<a>&lt;|&gt;</a>) combinator will try its second alternative even
°5uwhen the first parser failed while consuming input.
°5u
°5uThe <tt>try</tt> combinator can for example be used to distinguish
°5uidentifiers and reserved words. Both reserved words and identifiers
°5uare a sequence of letters. Whenever we expect a certain reserved word
°5uwhere we can also expect an identifier we have to use the <tt>try</tt>
°5ucombinator. Suppose we write:
°5u
°5u<pre>
°5uexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
°5u
°5uletExpr     = do{ string "let"; ... }
°5uidentifier  = many1 letter
°5u</pre>
°5u
°5uIf the user writes "lexical", the parser fails with: <tt>unexpected
°5u'x', expecting 't' in "let"</tt>. Indeed, since the (<a>&lt;|&gt;</a>)
°5ucombinator only tries alternatives when the first alternative hasn't
°5uconsumed input, the <tt>identifier</tt> parser is never tried (because
°5uthe prefix "le" of the <tt>string "let"</tt> parser is already
°5uconsumed). The right behaviour can be obtained by adding the
°5u<tt>try</tt> combinator:
°5u
°5u<pre>
°5uexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
°5u
°5uletExpr     = do{ try (string "let"); ... }
°5uidentifier  = many1 letter
°5u</pre>
try :: ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>token showTok posFromTok testTok</tt> accepts a token
°5u<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
°5ureturns <tt><a>Just</a> x</tt>. The source position of the <tt>t</tt>
°5ushould be returned by <tt>posFromTok t</tt> and the token can be shown
°5uusing <tt>showTok t</tt>.
°5u
°5uThis combinator is expressed in terms of <a>tokenPrim</a>. It is used
°5uto accept user defined token streams. For example, suppose that we
°5uhave a stream of basic tokens tupled with source positions. We can
°5uthan define a parser that accepts single tokens as:
°5u
°5u<pre>
°5umytoken x
°5u  = token showTok posFromTok testTok
°5u  where
°5u    showTok (pos,t)     = show t
°5u    posFromTok (pos,t)  = pos
°5u    testTok (pos,t)     = if x == t then Just t else Nothing
°5u</pre>
token :: (Stream s Identity t) => (t -> String) -> (t -> SourcePos) -> (t -> Maybe a) -> Parsec s u a

-- | The parser <tt>tokenPrim showTok nextPos testTok</tt> accepts a token
°5u<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
°5ureturns <tt><a>Just</a> x</tt>. The token can be shown using
°5u<tt>showTok t</tt>. The position of the <i>next</i> token should be
°5ureturned when <tt>nextPos</tt> is called with the current source
°5uposition <tt>pos</tt>, the current token <tt>t</tt> and the rest of
°5uthe tokens <tt>toks</tt>, <tt>nextPos pos t toks</tt>.
°5u
°5uThis is the most primitive combinator for accepting tokens. For
°5uexample, the <a>char</a> parser could be implemented as:
°5u
°5u<pre>
°5uchar c
°5u  = tokenPrim showChar nextPos testChar
°5u  where
°5u    showChar x        = "'" ++ x ++ "'"
°5u    testChar x        = if x == c then Just x else Nothing
°5u    nextPos pos x xs  = updatePosChar pos x
°5u</pre>
tokenPrim :: (Stream s m t) => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> (t -> Maybe a) -> ParsecT s u m a
tokenPrimEx :: (Stream s m t) => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> Maybe (SourcePos -> t -> s -> u -> u) -> (t -> Maybe a) -> ParsecT s u m a

-- | <tt>many p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
°5utimes. Returns a list of the returned values of <tt>p</tt>.
°5u
°5u<pre>
°5uidentifier  = do{ c  &lt;- letter
°5u                ; cs &lt;- many (alphaNum &lt;|&gt; char '_')
°5u                ; return (c:cs)
°5u                }
°5u</pre>
many :: ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>skipMany p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
°5utimes, skipping its result.
°5u
°5u<pre>
°5uspaces  = skipMany space
°5u</pre>
skipMany :: ParsecT s u m a -> ParsecT s u m ()
manyAccum :: (a -> [a] -> [a]) -> ParsecT s u m a -> ParsecT s u m [a]
runPT :: (Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runP :: (Stream s Identity t) => Parsec s u a -> u -> SourceName -> s -> Either ParseError a

-- | The most general way to run a parser. <tt>runParserT p state filePath
°5uinput</tt> runs parser <tt>p</tt> on the input list of tokens
°5u<tt>input</tt>, obtained from source <tt>filePath</tt> with the
°5uinitial user state <tt>st</tt>. The <tt>filePath</tt> is only used in
°5uerror messages and may be the empty string. Returns a computation in
°5uthe underlying monad <tt>m</tt> that return either a <a>ParseError</a>
°5u(<a>Left</a>) or a value of type <tt>a</tt> (<a>Right</a>).
runParserT :: (Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)

-- | The most general way to run a parser over the Identity monad.
°5u<tt>runParser p state filePath input</tt> runs parser <tt>p</tt> on
°5uthe input list of tokens <tt>input</tt>, obtained from source
°5u<tt>filePath</tt> with the initial user state <tt>st</tt>. The
°5u<tt>filePath</tt> is only used in error messages and may be the empty
°5ustring. Returns either a <a>ParseError</a> (<a>Left</a>) or a value of
°5utype <tt>a</tt> (<a>Right</a>).
°5u
°5u<pre>
°5uparseFromFile p fname
°5u  = do{ input &lt;- readFile fname
°5u      ; return (runParser p () fname input)
°5u      }
°5u</pre>
runParser :: (Stream s Identity t) => Parsec s u a -> u -> SourceName -> s -> Either ParseError a

-- | <tt>parse p filePath input</tt> runs a parser <tt>p</tt> over Identity
°5uwithout user state. The <tt>filePath</tt> is only used in error
°5umessages and may be the empty string. Returns either a
°5u<a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
°5u(<a>Right</a>).
°5u
°5u<pre>
°5umain    = case (parse numbers "" "11, 2, 43") of
°5u           Left err  -&gt; print err
°5u           Right xs  -&gt; print (sum xs)
°5u
°5unumbers = commaSep integer
°5u</pre>
parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError a

-- | The expression <tt>parseTest p input</tt> applies a parser <tt>p</tt>
°5uagainst input <tt>input</tt> and prints the result to stdout. Used for
°5utesting parsers.
parseTest :: (Stream s Identity t, Show a) => Parsec s () a -> s -> IO ()

-- | Returns the current source position. See also <a>SourcePos</a>.
getPosition :: (Monad m) => ParsecT s u m SourcePos

-- | Returns the current input
getInput :: (Monad m) => ParsecT s u m s

-- | <tt>setPosition pos</tt> sets the current source position to
°5u<tt>pos</tt>.
setPosition :: (Monad m) => SourcePos -> ParsecT s u m ()

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
°5u<a>getInput</a> and <tt>setInput</tt> functions can for example be
°5uused to deal with #include files.
setInput :: (Monad m) => s -> ParsecT s u m ()

-- | Returns the full parser state as a <a>State</a> record.
getParserState :: (Monad m) => ParsecT s u m (State s u)

-- | <tt>setParserState st</tt> set the full parser state to <tt>st</tt>.
setParserState :: (Monad m) => State s u -> ParsecT s u m (State s u)

-- | <tt>updateParserState f</tt> applies function <tt>f</tt> to the parser
°5ustate.
updateParserState :: (State s u -> State s u) -> ParsecT s u m (State s u)

-- | Returns the current user state.
getState :: (Monad m) => ParsecT s u m u

-- | <tt>putState st</tt> set the user state to <tt>st</tt>.
putState :: (Monad m) => u -> ParsecT s u m ()

-- | <tt>modifyState f</tt> applies function <tt>f</tt> to the user state.
°5uSuppose that we want to count identifiers in a source, we could use
°5uthe user state as:
°5u
°5u<pre>
°5uexpr  = do{ x &lt;- identifier
°5u          ; modifyState (+1)
°5u          ; return (Id x)
°5u          }
°5u</pre>
modifyState :: (Monad m) => (u -> u) -> ParsecT s u m ()

-- | An alias for putState for backwards compatibility.
setState :: (Monad m) => u -> ParsecT s u m ()

-- | An alias for modifyState for backwards compatibility.
updateState :: (Monad m) => (u -> u) -> ParsecT s u m ()
instance GHC.Base.Monad m => Text.Parsec.Prim.Stream [tok] m tok
instance GHC.Base.Monad m => Text.Parsec.Prim.Stream Data.ByteString.Lazy.Internal.ByteString m GHC.Types.Char
instance GHC.Base.Monad m => Text.Parsec.Prim.Stream Data.ByteString.Internal.ByteString m GHC.Types.Char
instance GHC.Base.Monad m => Text.Parsec.Prim.Stream Data.Text.Internal.Text m GHC.Types.Char
instance GHC.Base.Monad m => Text.Parsec.Prim.Stream Data.Text.Internal.Lazy.Text m GHC.Types.Char
instance GHC.Base.Functor (Text.Parsec.Prim.ParsecT s u m)
instance GHC.Base.Applicative (Text.Parsec.Prim.ParsecT s u m)
instance GHC.Base.Alternative (Text.Parsec.Prim.ParsecT s u m)
instance GHC.Base.Monad (Text.Parsec.Prim.ParsecT s u m)
instance Control.Monad.Fail.MonadFail (Text.Parsec.Prim.ParsecT s u m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Text.Parsec.Prim.ParsecT s u m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Text.Parsec.Prim.ParsecT s u m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Text.Parsec.Prim.ParsecT s' u m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Text.Parsec.Prim.ParsecT s u m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Text.Parsec.Prim.ParsecT s u m)
instance GHC.Base.MonadPlus (Text.Parsec.Prim.ParsecT s u m)
instance Control.Monad.Trans.Class.MonadTrans (Text.Parsec.Prim.ParsecT s u)
instance GHC.Base.Functor (Text.Parsec.Prim.Reply s u)
instance GHC.Base.Functor Text.Parsec.Prim.Consumed


-- | Commonly used generic combinators
module Text.Parsec.Combinator

-- | <tt>choice ps</tt> tries to apply the parsers in the list <tt>ps</tt>
°5uin order, until one of them succeeds. Returns the value of the
°5usucceeding parser.
choice :: (Stream s m t) => [ParsecT s u m a] -> ParsecT s u m a

-- | <tt>count n p</tt> parses <tt>n</tt> occurrences of <tt>p</tt>. If
°5u<tt>n</tt> is smaller or equal to zero, the parser equals to
°5u<tt>return []</tt>. Returns a list of <tt>n</tt> values returned by
°5u<tt>p</tt>.
count :: (Stream s m t) => Int -> ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>between open close p</tt> parses <tt>open</tt>, followed by
°5u<tt>p</tt> and <tt>close</tt>. Returns the value returned by
°5u<tt>p</tt>.
°5u
°5u<pre>
°5ubraces  = between (symbol "{") (symbol "}")
°5u</pre>
between :: (Stream s m t) => ParsecT s u m open -> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a

-- | <tt>option x p</tt> tries to apply parser <tt>p</tt>. If <tt>p</tt>
°5ufails without consuming input, it returns the value <tt>x</tt>,
°5uotherwise the value returned by <tt>p</tt>.
°5u
°5u<pre>
°5upriority  = option 0 (do{ d &lt;- digit
°5u                        ; return (digitToInt d)
°5u                        })
°5u</pre>
option :: (Stream s m t) => a -> ParsecT s u m a -> ParsecT s u m a

-- | <tt>optionMaybe p</tt> tries to apply parser <tt>p</tt>. If <tt>p</tt>
°5ufails without consuming input, it return <a>Nothing</a>, otherwise it
°5ureturns <a>Just</a> the value returned by <tt>p</tt>.
optionMaybe :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (Maybe a)

-- | <tt>optional p</tt> tries to apply parser <tt>p</tt>. It will parse
°5u<tt>p</tt> or nothing. It only fails if <tt>p</tt> fails after
°5uconsuming input. It discards the result of <tt>p</tt>.
optional :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>skipMany1 p</tt> applies the parser <tt>p</tt> <i>one</i> or more
°5utimes, skipping its result.
skipMany1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>many1 p</tt> applies the parser <tt>p</tt> <i>one</i> or more
°5utimes. Returns a list of the returned values of <tt>p</tt>.
°5u
°5u<pre>
°5uword  = many1 letter
°5u</pre>
many1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>sepBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
°5ureturned by <tt>p</tt>.
°5u
°5u<pre>
°5ucommaSep p  = p `sepBy` (symbol ",")
°5u</pre>
sepBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
°5ureturned by <tt>p</tt>.
sepBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>endBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
°5uvalues returned by <tt>p</tt>.
°5u
°5u<pre>
°5ucStatements  = cStatement `endBy` semi
°5u</pre>
endBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>endBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
°5uvalues returned by <tt>p</tt>.
endBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepEndBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated and optionally ended by <tt>sep</tt>, ie.
°5uhaskell style statements. Returns a list of values returned by
°5u<tt>p</tt>.
°5u
°5u<pre>
°5uhaskellStatements  = haskellStatement `sepEndBy` semi
°5u</pre>
sepEndBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepEndBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
°5ulist of values returned by <tt>p</tt>.
sepEndBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>chainl p op x</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt>. Returns a value obtained by a
°5u<i>left</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. If there are zero
°5uoccurrences of <tt>p</tt>, the value <tt>x</tt> is returned.
chainl :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> a -> ParsecT s u m a

-- | <tt>chainl1 p op</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
°5u<i>left</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. . This parser can
°5ufor example be used to eliminate left recursion which typically occurs
°5uin expression grammars.
°5u
°5u<pre>
°5uexpr    = term   `chainl1` addop
°5uterm    = factor `chainl1` mulop
°5ufactor  = parens expr &lt;|&gt; integer
°5u
°5umulop   =   do{ symbol "*"; return (*)   }
°5u        &lt;|&gt; do{ symbol "/"; return (div) }
°5u
°5uaddop   =   do{ symbol "+"; return (+) }
°5u        &lt;|&gt; do{ symbol "-"; return (-) }
°5u</pre>
chainl1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a

-- | <tt>chainr p op x</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
°5u<i>right</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. If there are no
°5uoccurrences of <tt>p</tt>, the value <tt>x</tt> is returned.
chainr :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> a -> ParsecT s u m a

-- | <tt>chainr1 p op x</tt> parses <i>one</i> or more occurrences of |p|,
°5useparated by <tt>op</tt> Returns a value obtained by a <i>right</i>
°5uassociative application of all functions returned by <tt>op</tt> to
°5uthe values returned by <tt>p</tt>.
chainr1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a

-- | This parser only succeeds at the end of the input. This is not a
°5uprimitive parser but it is defined using <a>notFollowedBy</a>.
°5u
°5u<pre>
°5ueof  = notFollowedBy anyToken &lt;?&gt; "end of input"
°5u</pre>
eof :: (Stream s m t, Show t) => ParsecT s u m ()

-- | <tt>notFollowedBy p</tt> only succeeds when parser <tt>p</tt> fails.
°5uThis parser does not consume any input. This parser can be used to
°5uimplement the 'longest match' rule. For example, when recognizing
°5ukeywords (for example <tt>let</tt>), we want to make sure that a
°5ukeyword is not followed by a legal identifier character, in which case
°5uthe keyword is actually an identifier (for example <tt>lets</tt>). We
°5ucan program this behaviour as follows:
°5u
°5u<pre>
°5ukeywordLet  = try (do{ string "let"
°5u                     ; notFollowedBy alphaNum
°5u                     })
°5u</pre>
notFollowedBy :: (Stream s m t, Show a) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>manyTill p end</tt> applies parser <tt>p</tt> <i>zero</i> or more
°5utimes until parser <tt>end</tt> succeeds. Returns the list of values
°5ureturned by <tt>p</tt>. This parser can be used to scan comments:
°5u
°5u<pre>
°5usimpleComment   = do{ string "&lt;!--"
°5u                    ; manyTill anyChar (try (string "--&gt;"))
°5u                    }
°5u</pre>
°5u
°5uNote the overlapping parsers <tt>anyChar</tt> and <tt>string
°5u"--&gt;"</tt>, and therefore the use of the <a>try</a> combinator.
manyTill :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]

-- | <tt>lookAhead p</tt> parses <tt>p</tt> without consuming any input.
°5u
°5uIf <tt>p</tt> fails and consumes some input, so does
°5u<tt>lookAhead</tt>. Combine with <a>try</a> if this is undesirable.
lookAhead :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>anyToken</tt> accepts any kind of token. It is for
°5uexample used to implement <a>eof</a>. Returns the accepted token.
anyToken :: (Stream s m t, Show t) => ParsecT s u m t


-- | A helper module to parse "expressions". Builds a parser given a table
°5uof operators and associativities.
module Text.Parsec.Expr

-- | This data type specifies the associativity of operators: left, right
°5uor none.
data Assoc
AssocNone :: Assoc
AssocLeft :: Assoc
AssocRight :: Assoc

-- | This data type specifies operators that work on values of type
°5u<tt>a</tt>. An operator is either binary infix or unary prefix or
°5upostfix. A binary operator has also an associated associativity.
data Operator s u m a
Infix :: (ParsecT s u m (a -> a -> a)) -> Assoc -> Operator s u m a
Prefix :: (ParsecT s u m (a -> a)) -> Operator s u m a
Postfix :: (ParsecT s u m (a -> a)) -> Operator s u m a

-- | An <tt>OperatorTable s u m a</tt> is a list of <tt>Operator s u m
°5ua</tt> lists. The list is ordered in descending precedence. All
°5uoperators in one list have the same precedence (but may have a
°5udifferent associativity).
type OperatorTable s u m a = [[Operator s u m a]]

-- | <tt>buildExpressionParser table term</tt> builds an expression parser
°5ufor terms <tt>term</tt> with operators from <tt>table</tt>, taking the
°5uassociativity and precedence specified in <tt>table</tt> into account.
°5uPrefix and postfix operators of the same precedence can only occur
°5uonce (i.e. <tt>--2</tt> is not allowed if <tt>-</tt> is prefix
°5unegate). Prefix and postfix operators of the same precedence associate
°5uto the left (i.e. if <tt>++</tt> is postfix increment, than
°5u<tt>-2++</tt> equals <tt>-1</tt>, not <tt>-3</tt>).
°5u
°5uThe <tt>buildExpressionParser</tt> takes care of all the complexity
°5uinvolved in building expression parser. Here is an example of an
°5uexpression parser that handles prefix signs, postfix increment and
°5ubasic arithmetic.
°5u
°5u<pre>
°5uexpr    = buildExpressionParser table term
°5u        &lt;?&gt; "expression"
°5u
°5uterm    =  parens expr
°5u        &lt;|&gt; natural
°5u        &lt;?&gt; "simple expression"
°5u
°5utable   = [ [prefix "-" negate, prefix "+" id ]
°5u          , [postfix "++" (+1)]
°5u          , [binary "*" (*) AssocLeft, binary "/" (div) AssocLeft ]
°5u          , [binary "+" (+) AssocLeft, binary "-" (-)   AssocLeft ]
°5u          ]
°5u
°5ubinary  name fun assoc = Infix (do{ reservedOp name; return fun }) assoc
°5uprefix  name fun       = Prefix (do{ reservedOp name; return fun })
°5upostfix name fun       = Postfix (do{ reservedOp name; return fun })
°5u</pre>
buildExpressionParser :: (Stream s m t) => OperatorTable s u m a -> ParsecT s u m a -> ParsecT s u m a


-- | Commonly used character parsers.
module Text.Parsec.Char

-- | <tt>oneOf cs</tt> succeeds if the current character is in the supplied
°5ulist of characters <tt>cs</tt>. Returns the parsed character. See also
°5u<a>satisfy</a>.
°5u
°5u<pre>
°5uvowel  = oneOf "aeiou"
°5u</pre>
oneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char

-- | As the dual of <a>oneOf</a>, <tt>noneOf cs</tt> succeeds if the
°5ucurrent character <i>not</i> in the supplied list of characters
°5u<tt>cs</tt>. Returns the parsed character.
°5u
°5u<pre>
°5uconsonant = noneOf "aeiou"
°5u</pre>
noneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char

-- | Skips <i>zero</i> or more white space characters. See also
°5u<a>skipMany</a>.
spaces :: (Stream s m Char) => ParsecT s u m ()

-- | Parses a white space character (any character which satisfies
°5u<a>isSpace</a>) Returns the parsed character.
space :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a newline character ('\n'). Returns a newline character.
newline :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a carriage return character ('\r') followed by a newline
°5ucharacter ('\n'). Returns a newline character.
crlf :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a CRLF (see <a>crlf</a>) or LF (see <a>newline</a>)
°5uend-of-line. Returns a newline character ('\n').
°5u
°5u<pre>
°5uendOfLine = newline &lt;|&gt; crlf
°5u</pre>
endOfLine :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a tab character ('\t'). Returns a tab character.
tab :: (Stream s m Char) => ParsecT s u m Char

-- | Parses an upper case letter (a character between 'A' and 'Z'). Returns
°5uthe parsed character.
upper :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a lower case character (a character between 'a' and 'z').
°5uReturns the parsed character.
lower :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a letter or digit (a character between '0' and '9'). Returns
°5uthe parsed character.
alphaNum :: (Stream s m Char => ParsecT s u m Char)

-- | Parses a letter (an upper case or lower case character). Returns the
°5uparsed character.
letter :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a digit. Returns the parsed character.
digit :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a hexadecimal digit (a digit or a letter between 'a' and 'f' or
°5u'A' and 'F'). Returns the parsed character.
hexDigit :: (Stream s m Char) => ParsecT s u m Char

-- | Parses an octal digit (a character between '0' and '7'). Returns the
°5uparsed character.
octDigit :: (Stream s m Char) => ParsecT s u m Char

-- | <tt>char c</tt> parses a single character <tt>c</tt>. Returns the
°5uparsed character (i.e. <tt>c</tt>).
°5u
°5u<pre>
°5usemiColon  = char ';'
°5u</pre>
char :: (Stream s m Char) => Char -> ParsecT s u m Char

-- | This parser succeeds for any character. Returns the parsed character.
anyChar :: (Stream s m Char) => ParsecT s u m Char

-- | The parser <tt>satisfy f</tt> succeeds for any character for which the
°5usupplied function <tt>f</tt> returns <a>True</a>. Returns the
°5ucharacter that is actually parsed.
satisfy :: (Stream s m Char) => (Char -> Bool) -> ParsecT s u m Char

-- | <tt>string s</tt> parses a sequence of characters given by <tt>s</tt>.
°5uReturns the parsed string (i.e. <tt>s</tt>).
°5u
°5u<pre>
°5udivOrMod    =   string "div"
°5u            &lt;|&gt; string "mod"
°5u</pre>
string :: (Stream s m Char) => String -> ParsecT s u m String


-- | Convinience definitions for working with lazy <a>ByteString</a>s.
module Text.Parsec.ByteString.Lazy
type Parser = Parsec ByteString ()
type GenParser t st = Parsec ByteString st

-- | <tt>parseFromFile p filePath</tt> runs a lazy bytestring parser
°5u<tt>p</tt> on the input read from <tt>filePath</tt> using
°5u<a>readFile</a>. Returns either a <a>ParseError</a> (<a>Left</a>) or a
°5uvalue of type <tt>a</tt> (<a>Right</a>).
°5u
°5u<pre>
°5umain    = do{ result &lt;- parseFromFile numbers "digits.txt"
°5u            ; case result of
°5u                Left err  -&gt; print err
°5u                Right xs  -&gt; print (sum xs)
°5u            }
°5u</pre>
parseFromFile :: Parser a -> String -> IO (Either ParseError a)


-- | Convinience definitions for working with <a>ByteString</a>s.
module Text.Parsec.ByteString
type Parser = Parsec ByteString ()
type GenParser t st = Parsec ByteString st

-- | <tt>parseFromFile p filePath</tt> runs a strict bytestring parser
°5u<tt>p</tt> on the input read from <tt>filePath</tt> using
°5u<a>readFile</a>. Returns either a <a>ParseError</a> (<a>Left</a>) or a
°5uvalue of type <tt>a</tt> (<a>Right</a>).
°5u
°5u<pre>
°5umain    = do{ result &lt;- parseFromFile numbers "digits.txt"
°5u            ; case result of
°5u                Left err  -&gt; print err
°5u                Right xs  -&gt; print (sum xs)
°5u            }
°5u</pre>
parseFromFile :: Parser a -> String -> IO (Either ParseError a)


-- | This module includes everything you need to get started writing a
°5uparser.
°5u
°5uBy default this module is set up to parse character data. If you'd
°5ulike to parse the result of your own tokenizer you should start with
°5uthe following imports:
°5u
°5u<pre>
°5uimport Text.Parsec.Prim
°5uimport Text.Parsec.Combinator
°5u</pre>
°5u
°5uThen you can implement your own version of <a>satisfy</a> on top of
°5uthe <a>tokenPrim</a> primitive.
module Text.Parsec

-- | ParserT monad transformer and Parser type
°5u
°5u<tt>ParsecT s u m a</tt> is a parser with stream type <tt>s</tt>, user
°5ustate type <tt>u</tt>, underlying monad <tt>m</tt> and return type
°5u<tt>a</tt>. Parsec is strict in the user state. If this is
°5uundesirable, simply used a data type like <tt>data Box a = Box a</tt>
°5uand the state type <tt>Box YourStateType</tt> to add a level of
°5uindirection.
data ParsecT s u m a
type Parsec s u = ParsecT s u Identity

-- | The parser <tt>token showTok posFromTok testTok</tt> accepts a token
°5u<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
°5ureturns <tt><a>Just</a> x</tt>. The source position of the <tt>t</tt>
°5ushould be returned by <tt>posFromTok t</tt> and the token can be shown
°5uusing <tt>showTok t</tt>.
°5u
°5uThis combinator is expressed in terms of <a>tokenPrim</a>. It is used
°5uto accept user defined token streams. For example, suppose that we
°5uhave a stream of basic tokens tupled with source positions. We can
°5uthan define a parser that accepts single tokens as:
°5u
°5u<pre>
°5umytoken x
°5u  = token showTok posFromTok testTok
°5u  where
°5u    showTok (pos,t)     = show t
°5u    posFromTok (pos,t)  = pos
°5u    testTok (pos,t)     = if x == t then Just t else Nothing
°5u</pre>
token :: (Stream s Identity t) => (t -> String) -> (t -> SourcePos) -> (t -> Maybe a) -> Parsec s u a
tokens :: (Stream s m t, Eq t) => ([t] -> String) -> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t]

-- | The most general way to run a parser. <tt>runParserT p state filePath
°5uinput</tt> runs parser <tt>p</tt> on the input list of tokens
°5u<tt>input</tt>, obtained from source <tt>filePath</tt> with the
°5uinitial user state <tt>st</tt>. The <tt>filePath</tt> is only used in
°5uerror messages and may be the empty string. Returns a computation in
°5uthe underlying monad <tt>m</tt> that return either a <a>ParseError</a>
°5u(<a>Left</a>) or a value of type <tt>a</tt> (<a>Right</a>).
runParserT :: (Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)

-- | The most general way to run a parser over the Identity monad.
°5u<tt>runParser p state filePath input</tt> runs parser <tt>p</tt> on
°5uthe input list of tokens <tt>input</tt>, obtained from source
°5u<tt>filePath</tt> with the initial user state <tt>st</tt>. The
°5u<tt>filePath</tt> is only used in error messages and may be the empty
°5ustring. Returns either a <a>ParseError</a> (<a>Left</a>) or a value of
°5utype <tt>a</tt> (<a>Right</a>).
°5u
°5u<pre>
°5uparseFromFile p fname
°5u  = do{ input &lt;- readFile fname
°5u      ; return (runParser p () fname input)
°5u      }
°5u</pre>
runParser :: (Stream s Identity t) => Parsec s u a -> u -> SourceName -> s -> Either ParseError a

-- | <tt>parse p filePath input</tt> runs a parser <tt>p</tt> over Identity
°5uwithout user state. The <tt>filePath</tt> is only used in error
°5umessages and may be the empty string. Returns either a
°5u<a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
°5u(<a>Right</a>).
°5u
°5u<pre>
°5umain    = case (parse numbers "" "11, 2, 43") of
°5u           Left err  -&gt; print err
°5u           Right xs  -&gt; print (sum xs)
°5u
°5unumbers = commaSep integer
°5u</pre>
parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError a

-- | The expression <tt>parseTest p input</tt> applies a parser <tt>p</tt>
°5uagainst input <tt>input</tt> and prints the result to stdout. Used for
°5utesting parsers.
parseTest :: (Stream s Identity t, Show a) => Parsec s () a -> s -> IO ()

-- | Returns the current source position. See also <a>SourcePos</a>.
getPosition :: (Monad m) => ParsecT s u m SourcePos

-- | Returns the current input
getInput :: (Monad m) => ParsecT s u m s

-- | Returns the current user state.
getState :: (Monad m) => ParsecT s u m u

-- | <tt>putState st</tt> set the user state to <tt>st</tt>.
putState :: (Monad m) => u -> ParsecT s u m ()

-- | <tt>modifyState f</tt> applies function <tt>f</tt> to the user state.
°5uSuppose that we want to count identifiers in a source, we could use
°5uthe user state as:
°5u
°5u<pre>
°5uexpr  = do{ x &lt;- identifier
°5u          ; modifyState (+1)
°5u          ; return (Id x)
°5u          }
°5u</pre>
modifyState :: (Monad m) => (u -> u) -> ParsecT s u m ()

-- | This combinator implements choice. The parser <tt>p &lt;|&gt; q</tt>
°5ufirst applies <tt>p</tt>. If it succeeds, the value of <tt>p</tt> is
°5ureturned. If <tt>p</tt> fails <i>without consuming any input</i>,
°5uparser <tt>q</tt> is tried. This combinator is defined equal to the
°5u<a>mplus</a> member of the <a>MonadPlus</a> class and the
°5u(<a>&lt;|&gt;</a>) member of <a>Alternative</a>.
°5u
°5uThe parser is called <i>predictive</i> since <tt>q</tt> is only tried
°5uwhen parser <tt>p</tt> didn't consume any input (i.e.. the look ahead
°5uis 1). This non-backtracking behaviour allows for both an efficient
°5uimplementation of the parser combinators and the generation of good
°5uerror messages.
(<|>) :: (ParsecT s u m a) -> (ParsecT s u m a) -> (ParsecT s u m a)
infixr 1 <|>

-- | The parser <tt>p &lt;?&gt; msg</tt> behaves as parser <tt>p</tt>, but
°5uwhenever the parser <tt>p</tt> fails <i>without consuming any
°5uinput</i>, it replaces expect error messages with the expect error
°5umessage <tt>msg</tt>.
°5u
°5uThis is normally used at the end of a set alternatives where we want
°5uto return an error message in terms of a higher level construct rather
°5uthan returning all possible characters. For example, if the
°5u<tt>expr</tt> parser from the <a>try</a> example would fail, the error
°5umessage is: '...: expecting expression'. Without the
°5u<tt>(&lt;?&gt;)</tt> combinator, the message would be like '...:
°5uexpecting "let" or letter', which is less friendly.
(<?>) :: (ParsecT s u m a) -> String -> (ParsecT s u m a)
infix 0 <?>

-- | A synonym for <tt>&lt;?&gt;</tt>, but as a function instead of an
°5uoperator.
label :: ParsecT s u m a -> String -> ParsecT s u m a
labels :: ParsecT s u m a -> [String] -> ParsecT s u m a

-- | The parser <tt>try p</tt> behaves like parser <tt>p</tt>, except that
°5uit pretends that it hasn't consumed any input when an error occurs.
°5u
°5uThis combinator is used whenever arbitrary look ahead is needed. Since
°5uit pretends that it hasn't consumed any input when <tt>p</tt> fails,
°5uthe (<a>&lt;|&gt;</a>) combinator will try its second alternative even
°5uwhen the first parser failed while consuming input.
°5u
°5uThe <tt>try</tt> combinator can for example be used to distinguish
°5uidentifiers and reserved words. Both reserved words and identifiers
°5uare a sequence of letters. Whenever we expect a certain reserved word
°5uwhere we can also expect an identifier we have to use the <tt>try</tt>
°5ucombinator. Suppose we write:
°5u
°5u<pre>
°5uexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
°5u
°5uletExpr     = do{ string "let"; ... }
°5uidentifier  = many1 letter
°5u</pre>
°5u
°5uIf the user writes "lexical", the parser fails with: <tt>unexpected
°5u'x', expecting 't' in "let"</tt>. Indeed, since the (<a>&lt;|&gt;</a>)
°5ucombinator only tries alternatives when the first alternative hasn't
°5uconsumed input, the <tt>identifier</tt> parser is never tried (because
°5uthe prefix "le" of the <tt>string "let"</tt> parser is already
°5uconsumed). The right behaviour can be obtained by adding the
°5u<tt>try</tt> combinator:
°5u
°5u<pre>
°5uexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
°5u
°5uletExpr     = do{ try (string "let"); ... }
°5uidentifier  = many1 letter
°5u</pre>
try :: ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>unexpected msg</tt> always fails with an unexpected
°5uerror message <tt>msg</tt> without consuming any input.
°5u
°5uThe parsers <a>fail</a>, (<a>&lt;?&gt;</a>) and <tt>unexpected</tt>
°5uare the three parsers used to generate error messages. Of these, only
°5u(<a>&lt;?&gt;</a>) is commonly used. For an example of the use of
°5u<tt>unexpected</tt>, see the definition of <a>notFollowedBy</a>.
unexpected :: (Stream s m t) => String -> ParsecT s u m a

-- | <tt>choice ps</tt> tries to apply the parsers in the list <tt>ps</tt>
°5uin order, until one of them succeeds. Returns the value of the
°5usucceeding parser.
choice :: (Stream s m t) => [ParsecT s u m a] -> ParsecT s u m a

-- | <tt>many p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
°5utimes. Returns a list of the returned values of <tt>p</tt>.
°5u
°5u<pre>
°5uidentifier  = do{ c  &lt;- letter
°5u                ; cs &lt;- many (alphaNum &lt;|&gt; char '_')
°5u                ; return (c:cs)
°5u                }
°5u</pre>
many :: ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>many1 p</tt> applies the parser <tt>p</tt> <i>one</i> or more
°5utimes. Returns a list of the returned values of <tt>p</tt>.
°5u
°5u<pre>
°5uword  = many1 letter
°5u</pre>
many1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>skipMany p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
°5utimes, skipping its result.
°5u
°5u<pre>
°5uspaces  = skipMany space
°5u</pre>
skipMany :: ParsecT s u m a -> ParsecT s u m ()

-- | <tt>skipMany1 p</tt> applies the parser <tt>p</tt> <i>one</i> or more
°5utimes, skipping its result.
skipMany1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>count n p</tt> parses <tt>n</tt> occurrences of <tt>p</tt>. If
°5u<tt>n</tt> is smaller or equal to zero, the parser equals to
°5u<tt>return []</tt>. Returns a list of <tt>n</tt> values returned by
°5u<tt>p</tt>.
count :: (Stream s m t) => Int -> ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>between open close p</tt> parses <tt>open</tt>, followed by
°5u<tt>p</tt> and <tt>close</tt>. Returns the value returned by
°5u<tt>p</tt>.
°5u
°5u<pre>
°5ubraces  = between (symbol "{") (symbol "}")
°5u</pre>
between :: (Stream s m t) => ParsecT s u m open -> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a

-- | <tt>option x p</tt> tries to apply parser <tt>p</tt>. If <tt>p</tt>
°5ufails without consuming input, it returns the value <tt>x</tt>,
°5uotherwise the value returned by <tt>p</tt>.
°5u
°5u<pre>
°5upriority  = option 0 (do{ d &lt;- digit
°5u                        ; return (digitToInt d)
°5u                        })
°5u</pre>
option :: (Stream s m t) => a -> ParsecT s u m a -> ParsecT s u m a

-- | <tt>optionMaybe p</tt> tries to apply parser <tt>p</tt>. If <tt>p</tt>
°5ufails without consuming input, it return <a>Nothing</a>, otherwise it
°5ureturns <a>Just</a> the value returned by <tt>p</tt>.
optionMaybe :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (Maybe a)

-- | <tt>optional p</tt> tries to apply parser <tt>p</tt>. It will parse
°5u<tt>p</tt> or nothing. It only fails if <tt>p</tt> fails after
°5uconsuming input. It discards the result of <tt>p</tt>.
optional :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>sepBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
°5ureturned by <tt>p</tt>.
°5u
°5u<pre>
°5ucommaSep p  = p `sepBy` (symbol ",")
°5u</pre>
sepBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
°5ureturned by <tt>p</tt>.
sepBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>endBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
°5uvalues returned by <tt>p</tt>.
°5u
°5u<pre>
°5ucStatements  = cStatement `endBy` semi
°5u</pre>
endBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>endBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
°5uvalues returned by <tt>p</tt>.
endBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepEndBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated and optionally ended by <tt>sep</tt>, ie.
°5uhaskell style statements. Returns a list of values returned by
°5u<tt>p</tt>.
°5u
°5u<pre>
°5uhaskellStatements  = haskellStatement `sepEndBy` semi
°5u</pre>
sepEndBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepEndBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
°5ulist of values returned by <tt>p</tt>.
sepEndBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>chainl p op x</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt>. Returns a value obtained by a
°5u<i>left</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. If there are zero
°5uoccurrences of <tt>p</tt>, the value <tt>x</tt> is returned.
chainl :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> a -> ParsecT s u m a

-- | <tt>chainl1 p op</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
°5u<i>left</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. . This parser can
°5ufor example be used to eliminate left recursion which typically occurs
°5uin expression grammars.
°5u
°5u<pre>
°5uexpr    = term   `chainl1` addop
°5uterm    = factor `chainl1` mulop
°5ufactor  = parens expr &lt;|&gt; integer
°5u
°5umulop   =   do{ symbol "*"; return (*)   }
°5u        &lt;|&gt; do{ symbol "/"; return (div) }
°5u
°5uaddop   =   do{ symbol "+"; return (+) }
°5u        &lt;|&gt; do{ symbol "-"; return (-) }
°5u</pre>
chainl1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a

-- | <tt>chainr p op x</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
°5u<i>right</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. If there are no
°5uoccurrences of <tt>p</tt>, the value <tt>x</tt> is returned.
chainr :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> a -> ParsecT s u m a

-- | <tt>chainr1 p op x</tt> parses <i>one</i> or more occurrences of |p|,
°5useparated by <tt>op</tt> Returns a value obtained by a <i>right</i>
°5uassociative application of all functions returned by <tt>op</tt> to
°5uthe values returned by <tt>p</tt>.
chainr1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a

-- | This parser only succeeds at the end of the input. This is not a
°5uprimitive parser but it is defined using <a>notFollowedBy</a>.
°5u
°5u<pre>
°5ueof  = notFollowedBy anyToken &lt;?&gt; "end of input"
°5u</pre>
eof :: (Stream s m t, Show t) => ParsecT s u m ()

-- | <tt>notFollowedBy p</tt> only succeeds when parser <tt>p</tt> fails.
°5uThis parser does not consume any input. This parser can be used to
°5uimplement the 'longest match' rule. For example, when recognizing
°5ukeywords (for example <tt>let</tt>), we want to make sure that a
°5ukeyword is not followed by a legal identifier character, in which case
°5uthe keyword is actually an identifier (for example <tt>lets</tt>). We
°5ucan program this behaviour as follows:
°5u
°5u<pre>
°5ukeywordLet  = try (do{ string "let"
°5u                     ; notFollowedBy alphaNum
°5u                     })
°5u</pre>
notFollowedBy :: (Stream s m t, Show a) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>manyTill p end</tt> applies parser <tt>p</tt> <i>zero</i> or more
°5utimes until parser <tt>end</tt> succeeds. Returns the list of values
°5ureturned by <tt>p</tt>. This parser can be used to scan comments:
°5u
°5u<pre>
°5usimpleComment   = do{ string "&lt;!--"
°5u                    ; manyTill anyChar (try (string "--&gt;"))
°5u                    }
°5u</pre>
°5u
°5uNote the overlapping parsers <tt>anyChar</tt> and <tt>string
°5u"--&gt;"</tt>, and therefore the use of the <a>try</a> combinator.
manyTill :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]

-- | <tt>lookAhead p</tt> parses <tt>p</tt> without consuming any input.
°5u
°5uIf <tt>p</tt> fails and consumes some input, so does
°5u<tt>lookAhead</tt>. Combine with <a>try</a> if this is undesirable.
lookAhead :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>anyToken</tt> accepts any kind of token. It is for
°5uexample used to implement <a>eof</a>. Returns the accepted token.
anyToken :: (Stream s m t, Show t) => ParsecT s u m t

-- | The abstract data type <tt>ParseError</tt> represents parse errors. It
°5uprovides the source position (<a>SourcePos</a>) of the error and a
°5ulist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
°5ureturned by the function <a>parse</a>. <tt>ParseError</tt> is an
°5uinstance of the <a>Show</a> and <a>Eq</a> classes.
data ParseError

-- | Extracts the source position from the parse error
errorPos :: ParseError -> SourcePos

-- | The abstract data type <tt>SourcePos</tt> represents source positions.
°5uIt contains the name of the source (i.e. file name), a line number and
°5ua column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
°5u<a>Eq</a> and <a>Ord</a> class.
data SourcePos
type SourceName = String
type Line = Int
type Column = Int

-- | Extracts the name of the source from a source position.
sourceName :: SourcePos -> SourceName

-- | Extracts the line number from a source position.
sourceLine :: SourcePos -> Line

-- | Extracts the column number from a source position.
sourceColumn :: SourcePos -> Column

-- | Increments the line number of a source position.
incSourceLine :: SourcePos -> Line -> SourcePos

-- | Increments the column number of a source position.
incSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the line number of a source position.
setSourceLine :: SourcePos -> Line -> SourcePos

-- | Set the column number of a source position.
setSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the name of the source.
setSourceName :: SourcePos -> SourceName -> SourcePos
manyAccum :: (a -> [a] -> [a]) -> ParsecT s u m a -> ParsecT s u m [a]

-- | The parser <tt>tokenPrim showTok nextPos testTok</tt> accepts a token
°5u<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
°5ureturns <tt><a>Just</a> x</tt>. The token can be shown using
°5u<tt>showTok t</tt>. The position of the <i>next</i> token should be
°5ureturned when <tt>nextPos</tt> is called with the current source
°5uposition <tt>pos</tt>, the current token <tt>t</tt> and the rest of
°5uthe tokens <tt>toks</tt>, <tt>nextPos pos t toks</tt>.
°5u
°5uThis is the most primitive combinator for accepting tokens. For
°5uexample, the <a>char</a> parser could be implemented as:
°5u
°5u<pre>
°5uchar c
°5u  = tokenPrim showChar nextPos testChar
°5u  where
°5u    showChar x        = "'" ++ x ++ "'"
°5u    testChar x        = if x == c then Just x else Nothing
°5u    nextPos pos x xs  = updatePosChar pos x
°5u</pre>
tokenPrim :: (Stream s m t) => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> (t -> Maybe a) -> ParsecT s u m a
tokenPrimEx :: (Stream s m t) => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> Maybe (SourcePos -> t -> s -> u -> u) -> (t -> Maybe a) -> ParsecT s u m a
runPT :: (Stream s m t) => ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
unknownError :: State s u -> ParseError
sysUnExpectError :: String -> SourcePos -> Reply s u a
mergeErrorReply :: ParseError -> Reply s u a -> Reply s u a

-- | Returns the full parser state as a <a>State</a> record.
getParserState :: (Monad m) => ParsecT s u m (State s u)

-- | <tt>setParserState st</tt> set the full parser state to <tt>st</tt>.
setParserState :: (Monad m) => State s u -> ParsecT s u m (State s u)

-- | <tt>updateParserState f</tt> applies function <tt>f</tt> to the parser
°5ustate.
updateParserState :: (State s u -> State s u) -> ParsecT s u m (State s u)

-- | An instance of <tt>Stream</tt> has stream type <tt>s</tt>, underlying
°5umonad <tt>m</tt> and token type <tt>t</tt> determined by the stream
°5u
°5uSome rough guidelines for a "correct" instance of Stream:
°5u
°5u<ul>
°5u<li>unfoldM uncons gives the [t] corresponding to the stream</li>
°5u<li>A <tt>Stream</tt> instance is responsible for maintaining the
°5u"position within the stream" in the stream state <tt>s</tt>. This is
°5utrivial unless you are using the monad in a non-trivial way.</li>
°5u</ul>
class (Monad m) => Stream s m t | s -> t
uncons :: Stream s m t => s -> m (Maybe (t, s))

-- | Low-level unpacking of the ParsecT type. To run your parser, please
°5ulook to runPT, runP, runParserT, runParser and other such functions.
runParsecT :: Monad m => ParsecT s u m a -> State s u -> m (Consumed (m (Reply s u a)))

-- | Low-level creation of the ParsecT type. You really shouldn't have to
°5udo this.
mkPT :: Monad m => (State s u -> m (Consumed (m (Reply s u a)))) -> ParsecT s u m a
runP :: (Stream s Identity t) => Parsec s u a -> u -> SourceName -> s -> Either ParseError a
data Consumed a
Consumed :: a -> Consumed a
Empty :: !a -> Consumed a
data Reply s u a
Ok :: a -> !(State s u) -> ParseError -> Reply s u a
Error :: ParseError -> Reply s u a
data State s u
State :: s -> !SourcePos -> !u -> State s u
[stateInput] :: State s u -> s
[statePos] :: State s u -> !SourcePos
[stateUser] :: State s u -> !u

-- | <tt>setPosition pos</tt> sets the current source position to
°5u<tt>pos</tt>.
setPosition :: (Monad m) => SourcePos -> ParsecT s u m ()

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
°5u<a>getInput</a> and <tt>setInput</tt> functions can for example be
°5uused to deal with #include files.
setInput :: (Monad m) => s -> ParsecT s u m ()

-- | An alias for putState for backwards compatibility.
setState :: (Monad m) => u -> ParsecT s u m ()

-- | An alias for modifyState for backwards compatibility.
updateState :: (Monad m) => (u -> u) -> ParsecT s u m ()
parsecMap :: (a -> b) -> ParsecT s u m a -> ParsecT s u m b
parserReturn :: a -> ParsecT s u m a
parserBind :: ParsecT s u m a -> (a -> ParsecT s u m b) -> ParsecT s u m b
parserFail :: String -> ParsecT s u m a

-- | <tt>parserZero</tt> always fails without consuming any input.
°5u<tt>parserZero</tt> is defined equal to the <a>mzero</a> member of the
°5u<a>MonadPlus</a> class and to the <a>empty</a> member of the
°5u<a>Alternative</a> class.
parserZero :: ParsecT s u m a
parserPlus :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a


-- | This module implements permutation parsers. The algorithm used is
°5ufairly complex since we push the type system to its limits :-) The
°5ualgorithm is described in:
°5u
°5u<i>Parsing Permutation Phrases,</i> by Arthur Baars, Andres Loh and
°5uDoaitse Swierstra. Published as a functional pearl at the Haskell
°5uWorkshop 2001.
module Text.Parsec.Perm

-- | Provided for backwards compatibility. The tok type is ignored.
type PermParser tok st a = StreamPermParser String st a

-- | The type <tt>StreamPermParser s st a</tt> denotes a permutation parser
°5uthat, when converted by the <a>permute</a> function, parses <tt>s</tt>
°5ustreams with user state <tt>st</tt> and returns a value of type
°5u<tt>a</tt> on success.
°5u
°5uNormally, a permutation parser is first build with special operators
°5ulike (<a>&lt;||&gt;</a>) and than transformed into a normal parser
°5uusing <a>permute</a>.
data StreamPermParser s st a

-- | The parser <tt>permute perm</tt> parses a permutation of parser
°5udescribed by <tt>perm</tt>. For example, suppose we want to parse a
°5upermutation of: an optional string of <tt>a</tt>'s, the character
°5u<tt>b</tt> and an optional <tt>c</tt>. This can be described by:
°5u
°5u<pre>
°5utest  = permute (tuple &lt;$?&gt; ("",many1 (char 'a'))
°5u                       &lt;||&gt; char 'b'
°5u                       &lt;|?&gt; ('_',char 'c'))
°5u      where
°5u        tuple a b c  = (a,b,c)
°5u</pre>
permute :: (Stream s Identity tok) => StreamPermParser s st a -> Parsec s st a

-- | The expression <tt>perm &lt;||&gt; p</tt> adds parser <tt>p</tt> to
°5uthe permutation parser <tt>perm</tt>. The parser <tt>p</tt> is not
°5uallowed to accept empty input - use the optional combinator
°5u(<a>&lt;|?&gt;</a>) instead. Returns a new permutation parser that
°5uincludes <tt>p</tt>.
(<||>) :: (Stream s Identity tok) => StreamPermParser s st (a -> b) -> Parsec s st a -> StreamPermParser s st b
infixl 1 <||>

-- | The expression <tt>f &lt;$$&gt; p</tt> creates a fresh permutation
°5uparser consisting of parser <tt>p</tt>. The the final result of the
°5upermutation parser is the function <tt>f</tt> applied to the return
°5uvalue of <tt>p</tt>. The parser <tt>p</tt> is not allowed to accept
°5uempty input - use the optional combinator (<a>&lt;$?&gt;</a>) instead.
°5u
°5uIf the function <tt>f</tt> takes more than one parameter, the type
°5uvariable <tt>b</tt> is instantiated to a functional type which
°5ucombines nicely with the adds parser <tt>p</tt> to the
°5u(<a>&lt;||&gt;</a>) combinator. This results in stylized code where a
°5upermutation parser starts with a combining function <tt>f</tt>
°5ufollowed by the parsers. The function <tt>f</tt> gets its parameters
°5uin the order in which the parsers are specified, but actual input can
°5ube in any order.
(<$$>) :: (Stream s Identity tok) => (a -> b) -> Parsec s st a -> StreamPermParser s st b
infixl 2 <$$>

-- | The expression <tt>perm &lt;||&gt; (x,p)</tt> adds parser <tt>p</tt>
°5uto the permutation parser <tt>perm</tt>. The parser <tt>p</tt> is
°5uoptional - if it can not be applied, the default value <tt>x</tt> will
°5ube used instead. Returns a new permutation parser that includes the
°5uoptional parser <tt>p</tt>.
(<|?>) :: (Stream s Identity tok) => StreamPermParser s st (a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
infixl 1 <|?>

-- | The expression <tt>f &lt;$?&gt; (x,p)</tt> creates a fresh permutation
°5uparser consisting of parser <tt>p</tt>. The the final result of the
°5upermutation parser is the function <tt>f</tt> applied to the return
°5uvalue of <tt>p</tt>. The parser <tt>p</tt> is optional - if it can not
°5ube applied, the default value <tt>x</tt> will be used instead.
(<$?>) :: (Stream s Identity tok) => (a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
infixl 2 <$?>


-- | Make Strings an instance of <a>Stream</a> with <a>Char</a> token type.
module Text.Parsec.String
type Parser = Parsec String ()
type GenParser tok st = Parsec [tok] st

-- | <tt>parseFromFile p filePath</tt> runs a string parser <tt>p</tt> on
°5uthe input read from <tt>filePath</tt> using <a>readFile</a>. Returns
°5ueither a <a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
°5u(<a>Right</a>).
°5u
°5u<pre>
°5umain    = do{ result &lt;- parseFromFile numbers "digits.txt"
°5u            ; case result of
°5u                Left err  -&gt; print err
°5u                Right xs  -&gt; print (sum xs)
°5u            }
°5u</pre>
parseFromFile :: Parser a -> String -> IO (Either ParseError a)


-- | Convinience definitions for working with <a>Text</a>.
module Text.Parsec.Text
type Parser = Parsec Text ()
type GenParser st = Parsec Text st


-- | Convenience definitions for working with lazy <a>Text</a>.
module Text.Parsec.Text.Lazy
type Parser = Parsec Text ()
type GenParser st = Parsec Text st


-- | A helper module to parse lexical elements (tokens). See
°5u<a>makeTokenParser</a> for a description of how to use it.
module Text.Parsec.Token
type LanguageDef st = GenLanguageDef String st Identity

-- | The <tt>GenLanguageDef</tt> type is a record that contains all
°5uparameterizable features of the <a>Text.Parsec.Token</a> module. The
°5umodule <a>Text.Parsec.Language</a> contains some default definitions.
data GenLanguageDef s u m
LanguageDef :: String -> String -> String -> Bool -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> [String] -> [String] -> Bool -> GenLanguageDef s u m

-- | Describes the start of a block comment. Use the empty string if the
°5ulanguage doesn't support block comments. For example "/*".
[commentStart] :: GenLanguageDef s u m -> String

-- | Describes the end of a block comment. Use the empty string if the
°5ulanguage doesn't support block comments. For example "*/".
[commentEnd] :: GenLanguageDef s u m -> String

-- | Describes the start of a line comment. Use the empty string if the
°5ulanguage doesn't support line comments. For example "//".
[commentLine] :: GenLanguageDef s u m -> String

-- | Set to <a>True</a> if the language supports nested block comments.
[nestedComments] :: GenLanguageDef s u m -> Bool

-- | This parser should accept any start characters of identifiers. For
°5uexample <tt>letter &lt;|&gt; char '_'</tt>.
[identStart] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any legal tail characters of identifiers.
°5uFor example <tt>alphaNum &lt;|&gt; char '_'</tt>.
[identLetter] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any start characters of operators. For
°5uexample <tt>oneOf ":!#$%&amp;*+./&lt;=&gt;?@\\^|-~"</tt>
[opStart] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any legal tail characters of operators. Note
°5uthat this parser should even be defined if the language doesn't
°5usupport user-defined operators, or otherwise the <a>reservedOp</a>
°5uparser won't work correctly.
[opLetter] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | The list of reserved identifiers.
[reservedNames] :: GenLanguageDef s u m -> [String]

-- | The list of reserved operators.
[reservedOpNames] :: GenLanguageDef s u m -> [String]

-- | Set to <a>True</a> if the language is case sensitive.
[caseSensitive] :: GenLanguageDef s u m -> Bool
type TokenParser st = GenTokenParser String st Identity

-- | The type of the record that holds lexical parsers that work on
°5u<tt>s</tt> streams with state <tt>u</tt> over a monad <tt>m</tt>.
data GenTokenParser s u m
TokenParser :: ParsecT s u m String -> String -> ParsecT s u m () -> ParsecT s u m String -> String -> ParsecT s u m () -> ParsecT s u m Char -> ParsecT s u m String -> ParsecT s u m Integer -> ParsecT s u m Integer -> ParsecT s u m Double -> ParsecT s u m (Either Integer Double) -> ParsecT s u m Integer -> ParsecT s u m Integer -> ParsecT s u m Integer -> String -> ParsecT s u m String -> forall a. ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m () -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m String -> ParsecT s u m String -> ParsecT s u m String -> ParsecT s u m String -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> GenTokenParser s u m

-- | This lexeme parser parses a legal identifier. Returns the identifier
°5ustring. This parser will fail on identifiers that are reserved words.
°5uLegal identifier (start) characters and reserved words are defined in
°5uthe <a>LanguageDef</a> that is passed to <a>makeTokenParser</a>. An
°5u<tt>identifier</tt> is treated as a single token using <a>try</a>.
[identifier] :: GenTokenParser s u m -> ParsecT s u m String

-- | The lexeme parser <tt>reserved name</tt> parses <tt>symbol name</tt>,
°5ubut it also checks that the <tt>name</tt> is not a prefix of a valid
°5uidentifier. A <tt>reserved</tt> word is treated as a single token
°5uusing <a>try</a>.
[reserved] :: GenTokenParser s u m -> String -> ParsecT s u m ()

-- | This lexeme parser parses a legal operator. Returns the name of the
°5uoperator. This parser will fail on any operators that are reserved
°5uoperators. Legal operator (start) characters and reserved operators
°5uare defined in the <a>LanguageDef</a> that is passed to
°5u<a>makeTokenParser</a>. An <tt>operator</tt> is treated as a single
°5utoken using <a>try</a>.
[operator] :: GenTokenParser s u m -> ParsecT s u m String

-- | The lexeme parser <tt>reservedOp name</tt> parses <tt>symbol
°5uname</tt>, but it also checks that the <tt>name</tt> is not a prefix
°5uof a valid operator. A <tt>reservedOp</tt> is treated as a single
°5utoken using <a>try</a>.
[reservedOp] :: GenTokenParser s u m -> String -> ParsecT s u m ()

-- | This lexeme parser parses a single literal character. Returns the
°5uliteral character value. This parsers deals correctly with escape
°5usequences. The literal character is parsed according to the grammar
°5urules defined in the Haskell report (which matches most programming
°5ulanguages quite closely).
[charLiteral] :: GenTokenParser s u m -> ParsecT s u m Char

-- | This lexeme parser parses a literal string. Returns the literal string
°5uvalue. This parsers deals correctly with escape sequences and gaps.
°5uThe literal string is parsed according to the grammar rules defined in
°5uthe Haskell report (which matches most programming languages quite
°5uclosely).
[stringLiteral] :: GenTokenParser s u m -> ParsecT s u m String

-- | This lexeme parser parses a natural number (a positive whole number).
°5uReturns the value of the number. The number can be specified in
°5u<a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
°5uparsed according to the grammar rules in the Haskell report.
[natural] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | This lexeme parser parses an integer (a whole number). This parser is
°5ulike <a>natural</a> except that it can be prefixed with sign (i.e. '-'
°5uor '+'). Returns the value of the number. The number can be specified
°5uin <a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
°5uparsed according to the grammar rules in the Haskell report.
[integer] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | This lexeme parser parses a floating point value. Returns the value of
°5uthe number. The number is parsed according to the grammar rules
°5udefined in the Haskell report.
[float] :: GenTokenParser s u m -> ParsecT s u m Double

-- | This lexeme parser parses either <a>natural</a> or a <a>float</a>.
°5uReturns the value of the number. This parsers deals with any overlap
°5uin the grammar rules for naturals and floats. The number is parsed
°5uaccording to the grammar rules defined in the Haskell report.
[naturalOrFloat] :: GenTokenParser s u m -> ParsecT s u m (Either Integer Double)

-- | Parses a positive whole number in the decimal system. Returns the
°5uvalue of the number.
[decimal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Parses a positive whole number in the hexadecimal system. The number
°5ushould be prefixed with "0x" or "0X". Returns the value of the number.
[hexadecimal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Parses a positive whole number in the octal system. The number should
°5ube prefixed with "0o" or "0O". Returns the value of the number.
[octal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Lexeme parser <tt>symbol s</tt> parses <a>string</a> <tt>s</tt> and
°5uskips trailing white space.
[symbol] :: GenTokenParser s u m -> String -> ParsecT s u m String

-- | <tt>lexeme p</tt> first applies parser <tt>p</tt> and then the
°5u<a>whiteSpace</a> parser, returning the value of <tt>p</tt>. Every
°5ulexical token (lexeme) is defined using <tt>lexeme</tt>, this way
°5uevery parse starts at a point without white space. Parsers that use
°5u<tt>lexeme</tt> are called <i>lexeme</i> parsers in this document.
°5u
°5uThe only point where the <a>whiteSpace</a> parser should be called
°5uexplicitly is the start of the main parser in order to skip any
°5uleading white space.
°5u
°5u<pre>
°5umainParser  = do{ whiteSpace
°5u                 ; ds &lt;- many (lexeme digit)
°5u                 ; eof
°5u                 ; return (sum ds)
°5u                 }
°5u</pre>
[lexeme] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Parses any white space. White space consists of <i>zero</i> or more
°5uoccurrences of a <a>space</a>, a line comment or a block (multi line)
°5ucomment. Block comments may be nested. How comments are started and
°5uended is defined in the <a>LanguageDef</a> that is passed to
°5u<a>makeTokenParser</a>.
[whiteSpace] :: GenTokenParser s u m -> ParsecT s u m ()

-- | Lexeme parser <tt>parens p</tt> parses <tt>p</tt> enclosed in
°5uparenthesis, returning the value of <tt>p</tt>.
[parens] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser <tt>braces p</tt> parses <tt>p</tt> enclosed in braces
°5u('{' and '}'), returning the value of <tt>p</tt>.
[braces] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser <tt>angles p</tt> parses <tt>p</tt> enclosed in angle
°5ubrackets ('&lt;' and '&gt;'), returning the value of <tt>p</tt>.
[angles] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser <tt>brackets p</tt> parses <tt>p</tt> enclosed in
°5ubrackets ('[' and ']'), returning the value of <tt>p</tt>.
[brackets] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | DEPRECATED: Use <a>brackets</a>.
[squares] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser |semi| parses the character ';' and skips any trailing
°5uwhite space. Returns the string ";".
[semi] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>comma</tt> parses the character ',' and skips any
°5utrailing white space. Returns the string ",".
[comma] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>colon</tt> parses the character ':' and skips any
°5utrailing white space. Returns the string ":".
[colon] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>dot</tt> parses the character '.' and skips any
°5utrailing white space. Returns the string ".".
[dot] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>semiSep p</tt> parses <i>zero</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[semiSep] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | Lexeme parser <tt>semiSep1 p</tt> parses <i>one</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[semiSep1] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | Lexeme parser <tt>commaSep p</tt> parses <i>zero</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[commaSep] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | Lexeme parser <tt>commaSep1 p</tt> parses <i>one</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[commaSep1] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | The expression <tt>makeTokenParser language</tt> creates a
°5u<a>GenTokenParser</a> record that contains lexical parsers that are
°5udefined using the definitions in the <tt>language</tt> record.
°5u
°5uThe use of this function is quite stylized - one imports the
°5uappropiate language definition and selects the lexical parsers that
°5uare needed from the resulting <a>GenTokenParser</a>.
°5u
°5u<pre>
°5umodule Main where
°5u
°5uimport Text.Parsec
°5uimport qualified Text.Parsec.Token as P
°5uimport Text.Parsec.Language (haskellDef)
°5u
°5u-- The parser
°5u...
°5u
°5uexpr  =   parens expr
°5u      &lt;|&gt; identifier
°5u      &lt;|&gt; ...
°5u
°5u
°5u-- The lexer
°5ulexer       = P.makeTokenParser haskellDef
°5u
°5uparens      = P.parens lexer
°5ubraces      = P.braces lexer
°5uidentifier  = P.identifier lexer
°5ureserved    = P.reserved lexer
°5u...
°5u</pre>
makeTokenParser :: (Stream s m Char) => GenLanguageDef s u m -> GenTokenParser s u m


-- | A helper module that defines some language definitions that can be
°5uused to instantiate a token parser (see <a>Text.Parsec.Token</a>).
module Text.Parsec.Language

-- | The language definition for the Haskell language.
haskellDef :: LanguageDef st

-- | A lexer for the haskell language.
haskell :: TokenParser st

-- | The language definition for the language Mondrian.
mondrianDef :: LanguageDef st

-- | A lexer for the mondrian language.
mondrian :: TokenParser st

-- | This is the most minimal token definition. It is recommended to use
°5uthis definition as the basis for other definitions. <tt>emptyDef</tt>
°5uhas no reserved names or operators, is case sensitive and doesn't
°5uaccept comments, identifiers or operators.
emptyDef :: LanguageDef st

-- | This is a minimal token definition for Haskell style languages. It
°5udefines the style of comments, valid identifiers and case sensitivity.
°5uIt does not define any reserved words or operators.
haskellStyle :: LanguageDef st

-- | This is a minimal token definition for Java style languages. It
°5udefines the style of comments, valid identifiers and case sensitivity.
°5uIt does not define any reserved words or operators.
javaStyle :: LanguageDef st
type LanguageDef st = GenLanguageDef String st Identity

-- | The <tt>GenLanguageDef</tt> type is a record that contains all
°5uparameterizable features of the <a>Text.Parsec.Token</a> module. The
°5umodule <a>Text.Parsec.Language</a> contains some default definitions.
data GenLanguageDef s u m


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Char
type CharParser st = GenParser Char st

-- | Skips <i>zero</i> or more white space characters. See also
°5u<a>skipMany</a>.
spaces :: (Stream s m Char) => ParsecT s u m ()

-- | Parses a white space character (any character which satisfies
°5u<a>isSpace</a>) Returns the parsed character.
space :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a newline character ('\n'). Returns a newline character.
newline :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a tab character ('\t'). Returns a tab character.
tab :: (Stream s m Char) => ParsecT s u m Char

-- | Parses an upper case letter (a character between 'A' and 'Z'). Returns
°5uthe parsed character.
upper :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a lower case character (a character between 'a' and 'z').
°5uReturns the parsed character.
lower :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a letter or digit (a character between '0' and '9'). Returns
°5uthe parsed character.
alphaNum :: (Stream s m Char => ParsecT s u m Char)

-- | Parses a letter (an upper case or lower case character). Returns the
°5uparsed character.
letter :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a digit. Returns the parsed character.
digit :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a hexadecimal digit (a digit or a letter between 'a' and 'f' or
°5u'A' and 'F'). Returns the parsed character.
hexDigit :: (Stream s m Char) => ParsecT s u m Char

-- | Parses an octal digit (a character between '0' and '7'). Returns the
°5uparsed character.
octDigit :: (Stream s m Char) => ParsecT s u m Char

-- | <tt>char c</tt> parses a single character <tt>c</tt>. Returns the
°5uparsed character (i.e. <tt>c</tt>).
°5u
°5u<pre>
°5usemiColon  = char ';'
°5u</pre>
char :: (Stream s m Char) => Char -> ParsecT s u m Char

-- | <tt>string s</tt> parses a sequence of characters given by <tt>s</tt>.
°5uReturns the parsed string (i.e. <tt>s</tt>).
°5u
°5u<pre>
°5udivOrMod    =   string "div"
°5u            &lt;|&gt; string "mod"
°5u</pre>
string :: (Stream s m Char) => String -> ParsecT s u m String

-- | This parser succeeds for any character. Returns the parsed character.
anyChar :: (Stream s m Char) => ParsecT s u m Char

-- | <tt>oneOf cs</tt> succeeds if the current character is in the supplied
°5ulist of characters <tt>cs</tt>. Returns the parsed character. See also
°5u<a>satisfy</a>.
°5u
°5u<pre>
°5uvowel  = oneOf "aeiou"
°5u</pre>
oneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char

-- | As the dual of <a>oneOf</a>, <tt>noneOf cs</tt> succeeds if the
°5ucurrent character <i>not</i> in the supplied list of characters
°5u<tt>cs</tt>. Returns the parsed character.
°5u
°5u<pre>
°5uconsonant = noneOf "aeiou"
°5u</pre>
noneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char

-- | The parser <tt>satisfy f</tt> succeeds for any character for which the
°5usupplied function <tt>f</tt> returns <a>True</a>. Returns the
°5ucharacter that is actually parsed.
satisfy :: (Stream s m Char) => (Char -> Bool) -> ParsecT s u m Char


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Combinator

-- | <tt>choice ps</tt> tries to apply the parsers in the list <tt>ps</tt>
°5uin order, until one of them succeeds. Returns the value of the
°5usucceeding parser.
choice :: (Stream s m t) => [ParsecT s u m a] -> ParsecT s u m a

-- | <tt>count n p</tt> parses <tt>n</tt> occurrences of <tt>p</tt>. If
°5u<tt>n</tt> is smaller or equal to zero, the parser equals to
°5u<tt>return []</tt>. Returns a list of <tt>n</tt> values returned by
°5u<tt>p</tt>.
count :: (Stream s m t) => Int -> ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>between open close p</tt> parses <tt>open</tt>, followed by
°5u<tt>p</tt> and <tt>close</tt>. Returns the value returned by
°5u<tt>p</tt>.
°5u
°5u<pre>
°5ubraces  = between (symbol "{") (symbol "}")
°5u</pre>
between :: (Stream s m t) => ParsecT s u m open -> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a

-- | <tt>option x p</tt> tries to apply parser <tt>p</tt>. If <tt>p</tt>
°5ufails without consuming input, it returns the value <tt>x</tt>,
°5uotherwise the value returned by <tt>p</tt>.
°5u
°5u<pre>
°5upriority  = option 0 (do{ d &lt;- digit
°5u                        ; return (digitToInt d)
°5u                        })
°5u</pre>
option :: (Stream s m t) => a -> ParsecT s u m a -> ParsecT s u m a

-- | <tt>optionMaybe p</tt> tries to apply parser <tt>p</tt>. If <tt>p</tt>
°5ufails without consuming input, it return <a>Nothing</a>, otherwise it
°5ureturns <a>Just</a> the value returned by <tt>p</tt>.
optionMaybe :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (Maybe a)

-- | <tt>optional p</tt> tries to apply parser <tt>p</tt>. It will parse
°5u<tt>p</tt> or nothing. It only fails if <tt>p</tt> fails after
°5uconsuming input. It discards the result of <tt>p</tt>.
optional :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>skipMany1 p</tt> applies the parser <tt>p</tt> <i>one</i> or more
°5utimes, skipping its result.
skipMany1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>many1 p</tt> applies the parser <tt>p</tt> <i>one</i> or more
°5utimes. Returns a list of the returned values of <tt>p</tt>.
°5u
°5u<pre>
°5uword  = many1 letter
°5u</pre>
many1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>sepBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
°5ureturned by <tt>p</tt>.
°5u
°5u<pre>
°5ucommaSep p  = p `sepBy` (symbol ",")
°5u</pre>
sepBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
°5ureturned by <tt>p</tt>.
sepBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>endBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
°5uvalues returned by <tt>p</tt>.
°5u
°5u<pre>
°5ucStatements  = cStatement `endBy` semi
°5u</pre>
endBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>endBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
°5uvalues returned by <tt>p</tt>.
endBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepEndBy p sep</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated and optionally ended by <tt>sep</tt>, ie.
°5uhaskell style statements. Returns a list of values returned by
°5u<tt>p</tt>.
°5u
°5u<pre>
°5uhaskellStatements  = haskellStatement `sepEndBy` semi
°5u</pre>
sepEndBy :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>sepEndBy1 p sep</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
°5ulist of values returned by <tt>p</tt>.
sepEndBy1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]

-- | <tt>chainl p op x</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt>. Returns a value obtained by a
°5u<i>left</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. If there are zero
°5uoccurrences of <tt>p</tt>, the value <tt>x</tt> is returned.
chainl :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> a -> ParsecT s u m a

-- | <tt>chainl1 p op</tt> parses <i>one</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
°5u<i>left</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. . This parser can
°5ufor example be used to eliminate left recursion which typically occurs
°5uin expression grammars.
°5u
°5u<pre>
°5uexpr    = term   `chainl1` addop
°5uterm    = factor `chainl1` mulop
°5ufactor  = parens expr &lt;|&gt; integer
°5u
°5umulop   =   do{ symbol "*"; return (*)   }
°5u        &lt;|&gt; do{ symbol "/"; return (div) }
°5u
°5uaddop   =   do{ symbol "+"; return (+) }
°5u        &lt;|&gt; do{ symbol "-"; return (-) }
°5u</pre>
chainl1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a

-- | <tt>chainr p op x</tt> parses <i>zero</i> or more occurrences of
°5u<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
°5u<i>right</i> associative application of all functions returned by
°5u<tt>op</tt> to the values returned by <tt>p</tt>. If there are no
°5uoccurrences of <tt>p</tt>, the value <tt>x</tt> is returned.
chainr :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> a -> ParsecT s u m a

-- | <tt>chainr1 p op x</tt> parses <i>one</i> or more occurrences of |p|,
°5useparated by <tt>op</tt> Returns a value obtained by a <i>right</i>
°5uassociative application of all functions returned by <tt>op</tt> to
°5uthe values returned by <tt>p</tt>.
chainr1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m (a -> a -> a) -> ParsecT s u m a

-- | This parser only succeeds at the end of the input. This is not a
°5uprimitive parser but it is defined using <a>notFollowedBy</a>.
°5u
°5u<pre>
°5ueof  = notFollowedBy anyToken &lt;?&gt; "end of input"
°5u</pre>
eof :: (Stream s m t, Show t) => ParsecT s u m ()

-- | <tt>notFollowedBy p</tt> only succeeds when parser <tt>p</tt> fails.
°5uThis parser does not consume any input. This parser can be used to
°5uimplement the 'longest match' rule. For example, when recognizing
°5ukeywords (for example <tt>let</tt>), we want to make sure that a
°5ukeyword is not followed by a legal identifier character, in which case
°5uthe keyword is actually an identifier (for example <tt>lets</tt>). We
°5ucan program this behaviour as follows:
°5u
°5u<pre>
°5ukeywordLet  = try (do{ string "let"
°5u                     ; notFollowedBy alphaNum
°5u                     })
°5u</pre>
notFollowedBy :: (Stream s m t, Show a) => ParsecT s u m a -> ParsecT s u m ()

-- | <tt>manyTill p end</tt> applies parser <tt>p</tt> <i>zero</i> or more
°5utimes until parser <tt>end</tt> succeeds. Returns the list of values
°5ureturned by <tt>p</tt>. This parser can be used to scan comments:
°5u
°5u<pre>
°5usimpleComment   = do{ string "&lt;!--"
°5u                    ; manyTill anyChar (try (string "--&gt;"))
°5u                    }
°5u</pre>
°5u
°5uNote the overlapping parsers <tt>anyChar</tt> and <tt>string
°5u"--&gt;"</tt>, and therefore the use of the <a>try</a> combinator.
manyTill :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]

-- | <tt>lookAhead p</tt> parses <tt>p</tt> without consuming any input.
°5u
°5uIf <tt>p</tt> fails and consumes some input, so does
°5u<tt>lookAhead</tt>. Combine with <a>try</a> if this is undesirable.
lookAhead :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>anyToken</tt> accepts any kind of token. It is for
°5uexample used to implement <a>eof</a>. Returns the accepted token.
anyToken :: (Stream s m t, Show t) => ParsecT s u m t


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Error

-- | This abstract data type represents parse error messages. There are
°5ufour kinds of messages:
°5u
°5u<pre>
°5udata Message = SysUnExpect String
°5u             | UnExpect String
°5u             | Expect String
°5u             | Message String
°5u</pre>
°5u
°5uThe fine distinction between different kinds of parse errors allows
°5uthe system to generate quite good error messages for the user. It also
°5uallows error messages that are formatted in different languages. Each
°5ukind of message is generated by different combinators:
°5u
°5u<ul>
°5u<li>A <a>SysUnExpect</a> message is automatically generated by the
°5u<a>satisfy</a> combinator. The argument is the unexpected input.</li>
°5u<li>A <a>UnExpect</a> message is generated by the <a>unexpected</a>
°5ucombinator. The argument describes the unexpected item.</li>
°5u<li>A <a>Expect</a> message is generated by the <a>&lt;?&gt;</a>
°5ucombinator. The argument describes the expected item.</li>
°5u<li>A <a>Message</a> message is generated by the <a>fail</a>
°5ucombinator. The argument is some general parser message.</li>
°5u</ul>
data Message
SysUnExpect :: !String -> Message
UnExpect :: !String -> Message
Expect :: !String -> Message
Message :: !String -> Message

-- | Extract the message string from an error message
messageString :: Message -> String
messageCompare :: Message -> Message -> Ordering
messageEq :: Message -> Message -> Bool

-- | The abstract data type <tt>ParseError</tt> represents parse errors. It
°5uprovides the source position (<a>SourcePos</a>) of the error and a
°5ulist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
°5ureturned by the function <a>parse</a>. <tt>ParseError</tt> is an
°5uinstance of the <a>Show</a> and <a>Eq</a> classes.
data ParseError

-- | Extracts the source position from the parse error
errorPos :: ParseError -> SourcePos

-- | Extracts the list of error messages from the parse error
errorMessages :: ParseError -> [Message]
errorIsUnknown :: ParseError -> Bool
showErrorMessages :: String -> String -> String -> String -> String -> [Message] -> String
newErrorMessage :: Message -> SourcePos -> ParseError
newErrorUnknown :: SourcePos -> ParseError
addErrorMessage :: Message -> ParseError -> ParseError
setErrorPos :: SourcePos -> ParseError -> ParseError
setErrorMessage :: Message -> ParseError -> ParseError
mergeError :: ParseError -> ParseError -> ParseError


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Language

-- | The language definition for the Haskell language.
haskellDef :: LanguageDef st

-- | A lexer for the haskell language.
haskell :: TokenParser st

-- | The language definition for the language Mondrian.
mondrianDef :: LanguageDef st

-- | A lexer for the mondrian language.
mondrian :: TokenParser st

-- | This is the most minimal token definition. It is recommended to use
°5uthis definition as the basis for other definitions. <tt>emptyDef</tt>
°5uhas no reserved names or operators, is case sensitive and doesn't
°5uaccept comments, identifiers or operators.
emptyDef :: LanguageDef st

-- | This is a minimal token definition for Haskell style languages. It
°5udefines the style of comments, valid identifiers and case sensitivity.
°5uIt does not define any reserved words or operators.
haskellStyle :: LanguageDef st

-- | This is a minimal token definition for Java style languages. It
°5udefines the style of comments, valid identifiers and case sensitivity.
°5uIt does not define any reserved words or operators.
javaStyle :: LanguageDef st
type LanguageDef st = GenLanguageDef String st Identity

-- | The <tt>GenLanguageDef</tt> type is a record that contains all
°5uparameterizable features of the <a>Text.Parsec.Token</a> module. The
°5umodule <a>Text.Parsec.Language</a> contains some default definitions.
data GenLanguageDef s u m
LanguageDef :: String -> String -> String -> Bool -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> [String] -> [String] -> Bool -> GenLanguageDef s u m

-- | Describes the start of a block comment. Use the empty string if the
°5ulanguage doesn't support block comments. For example "/*".
[commentStart] :: GenLanguageDef s u m -> String

-- | Describes the end of a block comment. Use the empty string if the
°5ulanguage doesn't support block comments. For example "*/".
[commentEnd] :: GenLanguageDef s u m -> String

-- | Describes the start of a line comment. Use the empty string if the
°5ulanguage doesn't support line comments. For example "//".
[commentLine] :: GenLanguageDef s u m -> String

-- | Set to <a>True</a> if the language supports nested block comments.
[nestedComments] :: GenLanguageDef s u m -> Bool

-- | This parser should accept any start characters of identifiers. For
°5uexample <tt>letter &lt;|&gt; char '_'</tt>.
[identStart] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any legal tail characters of identifiers.
°5uFor example <tt>alphaNum &lt;|&gt; char '_'</tt>.
[identLetter] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any start characters of operators. For
°5uexample <tt>oneOf ":!#$%&amp;*+./&lt;=&gt;?@\\^|-~"</tt>
[opStart] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any legal tail characters of operators. Note
°5uthat this parser should even be defined if the language doesn't
°5usupport user-defined operators, or otherwise the <a>reservedOp</a>
°5uparser won't work correctly.
[opLetter] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | The list of reserved identifiers.
[reservedNames] :: GenLanguageDef s u m -> [String]

-- | The list of reserved operators.
[reservedOpNames] :: GenLanguageDef s u m -> [String]

-- | Set to <a>True</a> if the language is case sensitive.
[caseSensitive] :: GenLanguageDef s u m -> Bool


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Perm

-- | Provided for backwards compatibility. The tok type is ignored.
type PermParser tok st a = StreamPermParser String st a

-- | The parser <tt>permute perm</tt> parses a permutation of parser
°5udescribed by <tt>perm</tt>. For example, suppose we want to parse a
°5upermutation of: an optional string of <tt>a</tt>'s, the character
°5u<tt>b</tt> and an optional <tt>c</tt>. This can be described by:
°5u
°5u<pre>
°5utest  = permute (tuple &lt;$?&gt; ("",many1 (char 'a'))
°5u                       &lt;||&gt; char 'b'
°5u                       &lt;|?&gt; ('_',char 'c'))
°5u      where
°5u        tuple a b c  = (a,b,c)
°5u</pre>
permute :: (Stream s Identity tok) => StreamPermParser s st a -> Parsec s st a

-- | The expression <tt>perm &lt;||&gt; p</tt> adds parser <tt>p</tt> to
°5uthe permutation parser <tt>perm</tt>. The parser <tt>p</tt> is not
°5uallowed to accept empty input - use the optional combinator
°5u(<a>&lt;|?&gt;</a>) instead. Returns a new permutation parser that
°5uincludes <tt>p</tt>.
(<||>) :: (Stream s Identity tok) => StreamPermParser s st (a -> b) -> Parsec s st a -> StreamPermParser s st b
infixl 1 <||>

-- | The expression <tt>f &lt;$$&gt; p</tt> creates a fresh permutation
°5uparser consisting of parser <tt>p</tt>. The the final result of the
°5upermutation parser is the function <tt>f</tt> applied to the return
°5uvalue of <tt>p</tt>. The parser <tt>p</tt> is not allowed to accept
°5uempty input - use the optional combinator (<a>&lt;$?&gt;</a>) instead.
°5u
°5uIf the function <tt>f</tt> takes more than one parameter, the type
°5uvariable <tt>b</tt> is instantiated to a functional type which
°5ucombines nicely with the adds parser <tt>p</tt> to the
°5u(<a>&lt;||&gt;</a>) combinator. This results in stylized code where a
°5upermutation parser starts with a combining function <tt>f</tt>
°5ufollowed by the parsers. The function <tt>f</tt> gets its parameters
°5uin the order in which the parsers are specified, but actual input can
°5ube in any order.
(<$$>) :: (Stream s Identity tok) => (a -> b) -> Parsec s st a -> StreamPermParser s st b
infixl 2 <$$>

-- | The expression <tt>perm &lt;||&gt; (x,p)</tt> adds parser <tt>p</tt>
°5uto the permutation parser <tt>perm</tt>. The parser <tt>p</tt> is
°5uoptional - if it can not be applied, the default value <tt>x</tt> will
°5ube used instead. Returns a new permutation parser that includes the
°5uoptional parser <tt>p</tt>.
(<|?>) :: (Stream s Identity tok) => StreamPermParser s st (a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
infixl 1 <|?>

-- | The expression <tt>f &lt;$?&gt; (x,p)</tt> creates a fresh permutation
°5uparser consisting of parser <tt>p</tt>. The the final result of the
°5upermutation parser is the function <tt>f</tt> applied to the return
°5uvalue of <tt>p</tt>. The parser <tt>p</tt> is optional - if it can not
°5ube applied, the default value <tt>x</tt> will be used instead.
(<$?>) :: (Stream s Identity tok) => (a -> b) -> (a, Parsec s st a) -> StreamPermParser s st b
infixl 2 <$?>


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Pos
type SourceName = String
type Line = Int
type Column = Int

-- | The abstract data type <tt>SourcePos</tt> represents source positions.
°5uIt contains the name of the source (i.e. file name), a line number and
°5ua column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
°5u<a>Eq</a> and <a>Ord</a> class.
data SourcePos

-- | Extracts the line number from a source position.
sourceLine :: SourcePos -> Line

-- | Extracts the column number from a source position.
sourceColumn :: SourcePos -> Column

-- | Extracts the name of the source from a source position.
sourceName :: SourcePos -> SourceName

-- | Increments the line number of a source position.
incSourceLine :: SourcePos -> Line -> SourcePos

-- | Increments the column number of a source position.
incSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the line number of a source position.
setSourceLine :: SourcePos -> Line -> SourcePos

-- | Set the column number of a source position.
setSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the name of the source.
setSourceName :: SourcePos -> SourceName -> SourcePos

-- | Create a new <a>SourcePos</a> with the given source name, line number
°5uand column number.
newPos :: SourceName -> Line -> Column -> SourcePos

-- | Create a new <a>SourcePos</a> with the given source name, and line
°5unumber and column number set to 1, the upper left.
initialPos :: SourceName -> SourcePos

-- | Update a source position given a character. If the character is a
°5unewline ('\n') or carriage return ('\r') the line number is
°5uincremented by 1. If the character is a tab ('t') the column number is
°5uincremented to the nearest 8'th column, ie. <tt>column + 8 -
°5u((column-1) `mod` 8)</tt>. In all other cases, the column is
°5uincremented by 1.
updatePosChar :: SourcePos -> Char -> SourcePos

-- | The expression <tt>updatePosString pos s</tt> updates the source
°5uposition <tt>pos</tt> by calling <a>updatePosChar</a> on every
°5ucharacter in <tt>s</tt>, ie. <tt>foldl updatePosChar pos string</tt>.
updatePosString :: SourcePos -> String -> SourcePos


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Prim

-- | The parser <tt>p &lt;?&gt; msg</tt> behaves as parser <tt>p</tt>, but
°5uwhenever the parser <tt>p</tt> fails <i>without consuming any
°5uinput</i>, it replaces expect error messages with the expect error
°5umessage <tt>msg</tt>.
°5u
°5uThis is normally used at the end of a set alternatives where we want
°5uto return an error message in terms of a higher level construct rather
°5uthan returning all possible characters. For example, if the
°5u<tt>expr</tt> parser from the <a>try</a> example would fail, the error
°5umessage is: '...: expecting expression'. Without the
°5u<tt>(&lt;?&gt;)</tt> combinator, the message would be like '...:
°5uexpecting "let" or letter', which is less friendly.
(<?>) :: (ParsecT s u m a) -> String -> (ParsecT s u m a)
infix 0 <?>

-- | This combinator implements choice. The parser <tt>p &lt;|&gt; q</tt>
°5ufirst applies <tt>p</tt>. If it succeeds, the value of <tt>p</tt> is
°5ureturned. If <tt>p</tt> fails <i>without consuming any input</i>,
°5uparser <tt>q</tt> is tried. This combinator is defined equal to the
°5u<a>mplus</a> member of the <a>MonadPlus</a> class and the
°5u(<a>&lt;|&gt;</a>) member of <a>Alternative</a>.
°5u
°5uThe parser is called <i>predictive</i> since <tt>q</tt> is only tried
°5uwhen parser <tt>p</tt> didn't consume any input (i.e.. the look ahead
°5uis 1). This non-backtracking behaviour allows for both an efficient
°5uimplementation of the parser combinators and the generation of good
°5uerror messages.
(<|>) :: (ParsecT s u m a) -> (ParsecT s u m a) -> (ParsecT s u m a)
infixr 1 <|>
type Parser = Parsec String ()
type GenParser tok st = Parsec [tok] st
runParser :: GenParser tok st a -> st -> SourceName -> [tok] -> Either ParseError a

-- | <tt>parse p filePath input</tt> runs a parser <tt>p</tt> over Identity
°5uwithout user state. The <tt>filePath</tt> is only used in error
°5umessages and may be the empty string. Returns either a
°5u<a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
°5u(<a>Right</a>).
°5u
°5u<pre>
°5umain    = case (parse numbers "" "11, 2, 43") of
°5u           Left err  -&gt; print err
°5u           Right xs  -&gt; print (sum xs)
°5u
°5unumbers = commaSep integer
°5u</pre>
parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError a

-- | <tt>parseFromFile p filePath</tt> runs a string parser <tt>p</tt> on
°5uthe input read from <tt>filePath</tt> using <a>readFile</a>. Returns
°5ueither a <a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
°5u(<a>Right</a>).
°5u
°5u<pre>
°5umain    = do{ result &lt;- parseFromFile numbers "digits.txt"
°5u            ; case result of
°5u                Left err  -&gt; print err
°5u                Right xs  -&gt; print (sum xs)
°5u            }
°5u</pre>
parseFromFile :: Parser a -> String -> IO (Either ParseError a)

-- | The expression <tt>parseTest p input</tt> applies a parser <tt>p</tt>
°5uagainst input <tt>input</tt> and prints the result to stdout. Used for
°5utesting parsers.
parseTest :: (Stream s Identity t, Show a) => Parsec s () a -> s -> IO ()

-- | The parser <tt>token showTok posFromTok testTok</tt> accepts a token
°5u<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
°5ureturns <tt><a>Just</a> x</tt>. The source position of the <tt>t</tt>
°5ushould be returned by <tt>posFromTok t</tt> and the token can be shown
°5uusing <tt>showTok t</tt>.
°5u
°5uThis combinator is expressed in terms of <a>tokenPrim</a>. It is used
°5uto accept user defined token streams. For example, suppose that we
°5uhave a stream of basic tokens tupled with source positions. We can
°5uthan define a parser that accepts single tokens as:
°5u
°5u<pre>
°5umytoken x
°5u  = token showTok posFromTok testTok
°5u  where
°5u    showTok (pos,t)     = show t
°5u    posFromTok (pos,t)  = pos
°5u    testTok (pos,t)     = if x == t then Just t else Nothing
°5u</pre>
token :: (Stream s Identity t) => (t -> String) -> (t -> SourcePos) -> (t -> Maybe a) -> Parsec s u a
tokens :: (Stream s m t, Eq t) => ([t] -> String) -> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t]

-- | The parser <tt>tokenPrim showTok nextPos testTok</tt> accepts a token
°5u<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
°5ureturns <tt><a>Just</a> x</tt>. The token can be shown using
°5u<tt>showTok t</tt>. The position of the <i>next</i> token should be
°5ureturned when <tt>nextPos</tt> is called with the current source
°5uposition <tt>pos</tt>, the current token <tt>t</tt> and the rest of
°5uthe tokens <tt>toks</tt>, <tt>nextPos pos t toks</tt>.
°5u
°5uThis is the most primitive combinator for accepting tokens. For
°5uexample, the <a>char</a> parser could be implemented as:
°5u
°5u<pre>
°5uchar c
°5u  = tokenPrim showChar nextPos testChar
°5u  where
°5u    showChar x        = "'" ++ x ++ "'"
°5u    testChar x        = if x == c then Just x else Nothing
°5u    nextPos pos x xs  = updatePosChar pos x
°5u</pre>
tokenPrim :: (Stream s m t) => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> (t -> Maybe a) -> ParsecT s u m a
tokenPrimEx :: (Stream s m t) => (t -> String) -> (SourcePos -> t -> s -> SourcePos) -> Maybe (SourcePos -> t -> s -> u -> u) -> (t -> Maybe a) -> ParsecT s u m a
try :: GenParser tok st a -> GenParser tok st a

-- | A synonym for <tt>&lt;?&gt;</tt>, but as a function instead of an
°5uoperator.
label :: ParsecT s u m a -> String -> ParsecT s u m a
labels :: ParsecT s u m a -> [String] -> ParsecT s u m a

-- | The parser <tt>unexpected msg</tt> always fails with an unexpected
°5uerror message <tt>msg</tt> without consuming any input.
°5u
°5uThe parsers <a>fail</a>, (<a>&lt;?&gt;</a>) and <tt>unexpected</tt>
°5uare the three parsers used to generate error messages. Of these, only
°5u(<a>&lt;?&gt;</a>) is commonly used. For an example of the use of
°5u<tt>unexpected</tt>, see the definition of <a>notFollowedBy</a>.
unexpected :: (Stream s m t) => String -> ParsecT s u m a
pzero :: GenParser tok st a

-- | <tt>many p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
°5utimes. Returns a list of the returned values of <tt>p</tt>.
°5u
°5u<pre>
°5uidentifier  = do{ c  &lt;- letter
°5u                ; cs &lt;- many (alphaNum &lt;|&gt; char '_')
°5u                ; return (c:cs)
°5u                }
°5u</pre>
many :: ParsecT s u m a -> ParsecT s u m [a]

-- | <tt>skipMany p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
°5utimes, skipping its result.
°5u
°5u<pre>
°5uspaces  = skipMany space
°5u</pre>
skipMany :: ParsecT s u m a -> ParsecT s u m ()

-- | Returns the current user state.
getState :: (Monad m) => ParsecT s u m u

-- | An alias for putState for backwards compatibility.
setState :: (Monad m) => u -> ParsecT s u m ()

-- | An alias for modifyState for backwards compatibility.
updateState :: (Monad m) => (u -> u) -> ParsecT s u m ()

-- | Returns the current source position. See also <a>SourcePos</a>.
getPosition :: (Monad m) => ParsecT s u m SourcePos

-- | <tt>setPosition pos</tt> sets the current source position to
°5u<tt>pos</tt>.
setPosition :: (Monad m) => SourcePos -> ParsecT s u m ()

-- | Returns the current input
getInput :: (Monad m) => ParsecT s u m s

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
°5u<a>getInput</a> and <tt>setInput</tt> functions can for example be
°5uused to deal with #include files.
setInput :: (Monad m) => s -> ParsecT s u m ()
data State s u
State :: s -> !SourcePos -> !u -> State s u
[stateInput] :: State s u -> s
[statePos] :: State s u -> !SourcePos
[stateUser] :: State s u -> !u

-- | Returns the full parser state as a <a>State</a> record.
getParserState :: (Monad m) => ParsecT s u m (State s u)

-- | <tt>setParserState st</tt> set the full parser state to <tt>st</tt>.
setParserState :: (Monad m) => State s u -> ParsecT s u m (State s u)


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec

-- | The abstract data type <tt>ParseError</tt> represents parse errors. It
°5uprovides the source position (<a>SourcePos</a>) of the error and a
°5ulist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
°5ureturned by the function <a>parse</a>. <tt>ParseError</tt> is an
°5uinstance of the <a>Show</a> and <a>Eq</a> classes.
data ParseError

-- | Extracts the source position from the parse error
errorPos :: ParseError -> SourcePos

-- | The abstract data type <tt>SourcePos</tt> represents source positions.
°5uIt contains the name of the source (i.e. file name), a line number and
°5ua column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
°5u<a>Eq</a> and <a>Ord</a> class.
data SourcePos
type SourceName = String
type Line = Int
type Column = Int

-- | Extracts the name of the source from a source position.
sourceName :: SourcePos -> SourceName

-- | Extracts the line number from a source position.
sourceLine :: SourcePos -> Line

-- | Extracts the column number from a source position.
sourceColumn :: SourcePos -> Column

-- | Increments the line number of a source position.
incSourceLine :: SourcePos -> Line -> SourcePos

-- | Increments the column number of a source position.
incSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the line number of a source position.
setSourceLine :: SourcePos -> Line -> SourcePos

-- | Set the column number of a source position.
setSourceColumn :: SourcePos -> Column -> SourcePos

-- | Set the name of the source.
setSourceName :: SourcePos -> SourceName -> SourcePos


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Expr

-- | This data type specifies the associativity of operators: left, right
°5uor none.
data Assoc
AssocNone :: Assoc
AssocLeft :: Assoc
AssocRight :: Assoc
data Operator tok st a
Infix :: (GenParser tok st (a -> a -> a)) -> Assoc -> Operator tok st a
Prefix :: (GenParser tok st (a -> a)) -> Operator tok st a
Postfix :: (GenParser tok st (a -> a)) -> Operator tok st a
type OperatorTable tok st a = [[Operator tok st a]]
buildExpressionParser :: OperatorTable tok st a -> GenParser tok st a -> GenParser tok st a


-- | Parsec compatibility module
module Text.ParserCombinators.Parsec.Token
type LanguageDef st = GenLanguageDef String st Identity

-- | The <tt>GenLanguageDef</tt> type is a record that contains all
°5uparameterizable features of the <a>Text.Parsec.Token</a> module. The
°5umodule <a>Text.Parsec.Language</a> contains some default definitions.
data GenLanguageDef s u m
LanguageDef :: String -> String -> String -> Bool -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> [String] -> [String] -> Bool -> GenLanguageDef s u m

-- | Describes the start of a block comment. Use the empty string if the
°5ulanguage doesn't support block comments. For example "/*".
[commentStart] :: GenLanguageDef s u m -> String

-- | Describes the end of a block comment. Use the empty string if the
°5ulanguage doesn't support block comments. For example "*/".
[commentEnd] :: GenLanguageDef s u m -> String

-- | Describes the start of a line comment. Use the empty string if the
°5ulanguage doesn't support line comments. For example "//".
[commentLine] :: GenLanguageDef s u m -> String

-- | Set to <a>True</a> if the language supports nested block comments.
[nestedComments] :: GenLanguageDef s u m -> Bool

-- | This parser should accept any start characters of identifiers. For
°5uexample <tt>letter &lt;|&gt; char '_'</tt>.
[identStart] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any legal tail characters of identifiers.
°5uFor example <tt>alphaNum &lt;|&gt; char '_'</tt>.
[identLetter] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any start characters of operators. For
°5uexample <tt>oneOf ":!#$%&amp;*+./&lt;=&gt;?@\\^|-~"</tt>
[opStart] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | This parser should accept any legal tail characters of operators. Note
°5uthat this parser should even be defined if the language doesn't
°5usupport user-defined operators, or otherwise the <a>reservedOp</a>
°5uparser won't work correctly.
[opLetter] :: GenLanguageDef s u m -> ParsecT s u m Char

-- | The list of reserved identifiers.
[reservedNames] :: GenLanguageDef s u m -> [String]

-- | The list of reserved operators.
[reservedOpNames] :: GenLanguageDef s u m -> [String]

-- | Set to <a>True</a> if the language is case sensitive.
[caseSensitive] :: GenLanguageDef s u m -> Bool
type TokenParser st = GenTokenParser String st Identity

-- | The type of the record that holds lexical parsers that work on
°5u<tt>s</tt> streams with state <tt>u</tt> over a monad <tt>m</tt>.
data GenTokenParser s u m
TokenParser :: ParsecT s u m String -> String -> ParsecT s u m () -> ParsecT s u m String -> String -> ParsecT s u m () -> ParsecT s u m Char -> ParsecT s u m String -> ParsecT s u m Integer -> ParsecT s u m Integer -> ParsecT s u m Double -> ParsecT s u m (Either Integer Double) -> ParsecT s u m Integer -> ParsecT s u m Integer -> ParsecT s u m Integer -> String -> ParsecT s u m String -> forall a. ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m () -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m String -> ParsecT s u m String -> ParsecT s u m String -> ParsecT s u m String -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> GenTokenParser s u m

-- | This lexeme parser parses a legal identifier. Returns the identifier
°5ustring. This parser will fail on identifiers that are reserved words.
°5uLegal identifier (start) characters and reserved words are defined in
°5uthe <a>LanguageDef</a> that is passed to <a>makeTokenParser</a>. An
°5u<tt>identifier</tt> is treated as a single token using <a>try</a>.
[identifier] :: GenTokenParser s u m -> ParsecT s u m String

-- | The lexeme parser <tt>reserved name</tt> parses <tt>symbol name</tt>,
°5ubut it also checks that the <tt>name</tt> is not a prefix of a valid
°5uidentifier. A <tt>reserved</tt> word is treated as a single token
°5uusing <a>try</a>.
[reserved] :: GenTokenParser s u m -> String -> ParsecT s u m ()

-- | This lexeme parser parses a legal operator. Returns the name of the
°5uoperator. This parser will fail on any operators that are reserved
°5uoperators. Legal operator (start) characters and reserved operators
°5uare defined in the <a>LanguageDef</a> that is passed to
°5u<a>makeTokenParser</a>. An <tt>operator</tt> is treated as a single
°5utoken using <a>try</a>.
[operator] :: GenTokenParser s u m -> ParsecT s u m String

-- | The lexeme parser <tt>reservedOp name</tt> parses <tt>symbol
°5uname</tt>, but it also checks that the <tt>name</tt> is not a prefix
°5uof a valid operator. A <tt>reservedOp</tt> is treated as a single
°5utoken using <a>try</a>.
[reservedOp] :: GenTokenParser s u m -> String -> ParsecT s u m ()

-- | This lexeme parser parses a single literal character. Returns the
°5uliteral character value. This parsers deals correctly with escape
°5usequences. The literal character is parsed according to the grammar
°5urules defined in the Haskell report (which matches most programming
°5ulanguages quite closely).
[charLiteral] :: GenTokenParser s u m -> ParsecT s u m Char

-- | This lexeme parser parses a literal string. Returns the literal string
°5uvalue. This parsers deals correctly with escape sequences and gaps.
°5uThe literal string is parsed according to the grammar rules defined in
°5uthe Haskell report (which matches most programming languages quite
°5uclosely).
[stringLiteral] :: GenTokenParser s u m -> ParsecT s u m String

-- | This lexeme parser parses a natural number (a positive whole number).
°5uReturns the value of the number. The number can be specified in
°5u<a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
°5uparsed according to the grammar rules in the Haskell report.
[natural] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | This lexeme parser parses an integer (a whole number). This parser is
°5ulike <a>natural</a> except that it can be prefixed with sign (i.e. '-'
°5uor '+'). Returns the value of the number. The number can be specified
°5uin <a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
°5uparsed according to the grammar rules in the Haskell report.
[integer] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | This lexeme parser parses a floating point value. Returns the value of
°5uthe number. The number is parsed according to the grammar rules
°5udefined in the Haskell report.
[float] :: GenTokenParser s u m -> ParsecT s u m Double

-- | This lexeme parser parses either <a>natural</a> or a <a>float</a>.
°5uReturns the value of the number. This parsers deals with any overlap
°5uin the grammar rules for naturals and floats. The number is parsed
°5uaccording to the grammar rules defined in the Haskell report.
[naturalOrFloat] :: GenTokenParser s u m -> ParsecT s u m (Either Integer Double)

-- | Parses a positive whole number in the decimal system. Returns the
°5uvalue of the number.
[decimal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Parses a positive whole number in the hexadecimal system. The number
°5ushould be prefixed with "0x" or "0X". Returns the value of the number.
[hexadecimal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Parses a positive whole number in the octal system. The number should
°5ube prefixed with "0o" or "0O". Returns the value of the number.
[octal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Lexeme parser <tt>symbol s</tt> parses <a>string</a> <tt>s</tt> and
°5uskips trailing white space.
[symbol] :: GenTokenParser s u m -> String -> ParsecT s u m String

-- | <tt>lexeme p</tt> first applies parser <tt>p</tt> and then the
°5u<a>whiteSpace</a> parser, returning the value of <tt>p</tt>. Every
°5ulexical token (lexeme) is defined using <tt>lexeme</tt>, this way
°5uevery parse starts at a point without white space. Parsers that use
°5u<tt>lexeme</tt> are called <i>lexeme</i> parsers in this document.
°5u
°5uThe only point where the <a>whiteSpace</a> parser should be called
°5uexplicitly is the start of the main parser in order to skip any
°5uleading white space.
°5u
°5u<pre>
°5umainParser  = do{ whiteSpace
°5u                 ; ds &lt;- many (lexeme digit)
°5u                 ; eof
°5u                 ; return (sum ds)
°5u                 }
°5u</pre>
[lexeme] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Parses any white space. White space consists of <i>zero</i> or more
°5uoccurrences of a <a>space</a>, a line comment or a block (multi line)
°5ucomment. Block comments may be nested. How comments are started and
°5uended is defined in the <a>LanguageDef</a> that is passed to
°5u<a>makeTokenParser</a>.
[whiteSpace] :: GenTokenParser s u m -> ParsecT s u m ()

-- | Lexeme parser <tt>parens p</tt> parses <tt>p</tt> enclosed in
°5uparenthesis, returning the value of <tt>p</tt>.
[parens] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser <tt>braces p</tt> parses <tt>p</tt> enclosed in braces
°5u('{' and '}'), returning the value of <tt>p</tt>.
[braces] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser <tt>angles p</tt> parses <tt>p</tt> enclosed in angle
°5ubrackets ('&lt;' and '&gt;'), returning the value of <tt>p</tt>.
[angles] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser <tt>brackets p</tt> parses <tt>p</tt> enclosed in
°5ubrackets ('[' and ']'), returning the value of <tt>p</tt>.
[brackets] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | DEPRECATED: Use <a>brackets</a>.
[squares] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a

-- | Lexeme parser |semi| parses the character ';' and skips any trailing
°5uwhite space. Returns the string ";".
[semi] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>comma</tt> parses the character ',' and skips any
°5utrailing white space. Returns the string ",".
[comma] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>colon</tt> parses the character ':' and skips any
°5utrailing white space. Returns the string ":".
[colon] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>dot</tt> parses the character '.' and skips any
°5utrailing white space. Returns the string ".".
[dot] :: GenTokenParser s u m -> ParsecT s u m String

-- | Lexeme parser <tt>semiSep p</tt> parses <i>zero</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[semiSep] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | Lexeme parser <tt>semiSep1 p</tt> parses <i>one</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[semiSep1] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | Lexeme parser <tt>commaSep p</tt> parses <i>zero</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[commaSep] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | Lexeme parser <tt>commaSep1 p</tt> parses <i>one</i> or more
°5uoccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
°5uvalues returned by <tt>p</tt>.
[commaSep1] :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]

-- | The expression <tt>makeTokenParser language</tt> creates a
°5u<a>GenTokenParser</a> record that contains lexical parsers that are
°5udefined using the definitions in the <tt>language</tt> record.
°5u
°5uThe use of this function is quite stylized - one imports the
°5uappropiate language definition and selects the lexical parsers that
°5uare needed from the resulting <a>GenTokenParser</a>.
°5u
°5u<pre>
°5umodule Main where
°5u
°5uimport Text.Parsec
°5uimport qualified Text.Parsec.Token as P
°5uimport Text.Parsec.Language (haskellDef)
°5u
°5u-- The parser
°5u...
°5u
°5uexpr  =   parens expr
°5u      &lt;|&gt; identifier
°5u      &lt;|&gt; ...
°5u
°5u
°5u-- The lexer
°5ulexer       = P.makeTokenParser haskellDef
°5u
°5uparens      = P.parens lexer
°5ubraces      = P.braces lexer
°5uidentifier  = P.identifier lexer
°5ureserved    = P.reserved lexer
°5u...
°5u</pre>
makeTokenParser :: (Stream s m Char) => GenLanguageDef s u m -> GenTokenParser s u m
