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


-- | Monadic parser combinators
gr
grParsec is designed from scratch as an industrial-strength parser
grlibrary. It is simple, safe, well documented (on the package
grhomepage), has extensive libraries, good error messages, and is fast.
grIt is defined as a monad transformer that can be stacked on arbitrary
grmonads, and it is also parametric in the input stream type.
gr
grThe main entry point is the <a>Text.Parsec</a> module which provides
grdefaults for parsing <a>Char</a>acter data.
gr
grThe <a>Text.ParserCombinators.Parsec</a> module hierarchy contains the
grlegacy <tt>parsec-2</tt> API and may be removed at some point in the
grfuture.
@package parsec
@version 3.1.13.0


-- | 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.
grIt contains the name of the source (i.e. file name), a line number and
gra column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
gr<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
grand column number.
newPos :: SourceName -> Line -> Column -> SourcePos

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

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

-- | The expression <tt>updatePosString pos s</tt> updates the source
grposition <tt>pos</tt> by calling <a>updatePosChar</a> on every
grcharacter 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
grfour kinds of messages:
gr
gr<pre>
grdata Message = SysUnExpect String
gr             | UnExpect String
gr             | Expect String
gr             | Message String
gr</pre>
gr
grThe fine distinction between different kinds of parse errors allows
grthe system to generate quite good error messages for the user. It also
grallows error messages that are formatted in different languages. Each
grkind of message is generated by different combinators:
gr
gr<ul>
gr<li>A <a>SysUnExpect</a> message is automatically generated by the
gr<a>satisfy</a> combinator. The argument is the unexpected input.</li>
gr<li>A <a>UnExpect</a> message is generated by the <a>unexpected</a>
grcombinator. The argument describes the unexpected item.</li>
gr<li>A <a>Expect</a> message is generated by the <a>&lt;?&gt;</a>
grcombinator. The argument describes the expected item.</li>
gr<li>A <a>Message</a> message is generated by the <a>fail</a>
grcombinator. The argument is some general parser message.</li>
gr</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
grprovides the source position (<a>SourcePos</a>) of the error and a
grlist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
grreturned by the function <a>parse</a>. <tt>ParseError</tt> is an
grinstance 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
grerror message <tt>msg</tt> without consuming any input.
gr
grThe parsers <a>fail</a>, (<a>&lt;?&gt;</a>) and <tt>unexpected</tt>
grare the three parsers used to generate error messages. Of these, only
gr(<a>&lt;?&gt;</a>) is commonly used. For an example of the use of
gr<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
gr
gr<tt>ParsecT s u m a</tt> is a parser with stream type <tt>s</tt>, user
grstate type <tt>u</tt>, underlying monad <tt>m</tt> and return type
gr<tt>a</tt>. Parsec is strict in the user state. If this is
grundesirable, simply use a data type like <tt>data Box a = Box a</tt>
grand the state type <tt>Box YourStateType</tt> to add a level of
grindirection.
data ParsecT s u m a

-- | Low-level unpacking of the ParsecT type. To run your parser, please
grlook 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
grdo 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.
gr<tt>parserZero</tt> is defined equal to the <a>mzero</a> member of the
gr<a>MonadPlus</a> class and to the <a>empty</a> member of the
gr<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
grwhenever the parser <tt>p</tt> fails <i>without consuming any
grinput</i>, it replaces expect error messages with the expect error
grmessage <tt>msg</tt>.
gr
grThis is normally used at the end of a set alternatives where we want
grto return an error message in terms of a higher level construct rather
grthan returning all possible characters. For example, if the
gr<tt>expr</tt> parser from the <a>try</a> example would fail, the error
grmessage is: '...: expecting expression'. Without the
gr<tt>(&lt;?&gt;)</tt> combinator, the message would be like '...:
grexpecting "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>
grfirst applies <tt>p</tt>. If it succeeds, the value of <tt>p</tt> is
grreturned. If <tt>p</tt> fails <i>without consuming any input</i>,
grparser <tt>q</tt> is tried. This combinator is defined equal to the
gr<a>mplus</a> member of the <a>MonadPlus</a> class and the
gr(<a>&lt;|&gt;</a>) member of <a>Alternative</a>.
gr
grThe parser is called <i>predictive</i> since <tt>q</tt> is only tried
grwhen parser <tt>p</tt> didn't consume any input (i.e.. the look ahead
gris 1). This non-backtracking behaviour allows for both an efficient
grimplementation of the parser combinators and the generation of good
grerror 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
groperator.
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.
gr
grIf <tt>p</tt> fails and consumes some input, so does
gr<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
grmonad <tt>m</tt> and token type <tt>t</tt> determined by the stream
gr
grSome rough guidelines for a "correct" instance of Stream:
gr
gr<ul>
gr<li>unfoldM uncons gives the [t] corresponding to the stream</li>
gr<li>A <tt>Stream</tt> instance is responsible for maintaining the
gr"position within the stream" in the stream state <tt>s</tt>. This is
grtrivial unless you are using the monad in a non-trivial way.</li>
gr</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
grit pretends that it hasn't consumed any input when an error occurs.
gr
grThis combinator is used whenever arbitrary look ahead is needed. Since
grit pretends that it hasn't consumed any input when <tt>p</tt> fails,
grthe (<a>&lt;|&gt;</a>) combinator will try its second alternative even
grwhen the first parser failed while consuming input.
gr
grThe <tt>try</tt> combinator can for example be used to distinguish
gridentifiers and reserved words. Both reserved words and identifiers
grare a sequence of letters. Whenever we expect a certain reserved word
grwhere we can also expect an identifier we have to use the <tt>try</tt>
grcombinator. Suppose we write:
gr
gr<pre>
grexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
gr
grletExpr     = do{ string "let"; ... }
gridentifier  = many1 letter
gr</pre>
gr
grIf the user writes "lexical", the parser fails with: <tt>unexpected
gr'x', expecting 't' in "let"</tt>. Indeed, since the (<a>&lt;|&gt;</a>)
grcombinator only tries alternatives when the first alternative hasn't
grconsumed input, the <tt>identifier</tt> parser is never tried (because
grthe prefix "le" of the <tt>string "let"</tt> parser is already
grconsumed). The right behaviour can be obtained by adding the
gr<tt>try</tt> combinator:
gr
gr<pre>
grexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
gr
grletExpr     = do{ try (string "let"); ... }
gridentifier  = many1 letter
gr</pre>
try :: ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>token showTok posFromTok testTok</tt> accepts a token
gr<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
grreturns <tt><a>Just</a> x</tt>. The source position of the <tt>t</tt>
grshould be returned by <tt>posFromTok t</tt> and the token can be shown
grusing <tt>showTok t</tt>.
gr
grThis combinator is expressed in terms of <a>tokenPrim</a>. It is used
grto accept user defined token streams. For example, suppose that we
grhave a stream of basic tokens tupled with source positions. We can
grthen define a parser that accepts single tokens as:
gr
gr<pre>
grmytoken x
gr  = token showTok posFromTok testTok
gr  where
gr    showTok (pos,t)     = show t
gr    posFromTok (pos,t)  = pos
gr    testTok (pos,t)     = if x == t then Just t else Nothing
gr</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
gr<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
grreturns <tt><a>Just</a> x</tt>. The token can be shown using
gr<tt>showTok t</tt>. The position of the <i>next</i> token should be
grreturned when <tt>nextPos</tt> is called with the current source
grposition <tt>pos</tt>, the current token <tt>t</tt> and the rest of
grthe tokens <tt>toks</tt>, <tt>nextPos pos t toks</tt>.
gr
grThis is the most primitive combinator for accepting tokens. For
grexample, the <a>char</a> parser could be implemented as:
gr
gr<pre>
grchar c
gr  = tokenPrim showChar nextPos testChar
gr  where
gr    showChar x        = "'" ++ x ++ "'"
gr    testChar x        = if x == c then Just x else Nothing
gr    nextPos pos x xs  = updatePosChar pos x
gr</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
grtimes. Returns a list of the returned values of <tt>p</tt>.
gr
gr<pre>
gridentifier  = do{ c  &lt;- letter
gr                ; cs &lt;- many (alphaNum &lt;|&gt; char '_')
gr                ; return (c:cs)
gr                }
gr</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
grtimes, skipping its result.
gr
gr<pre>
grspaces  = skipMany space
gr</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
grinput</tt> runs parser <tt>p</tt> on the input list of tokens
gr<tt>input</tt>, obtained from source <tt>filePath</tt> with the
grinitial user state <tt>st</tt>. The <tt>filePath</tt> is only used in
grerror messages and may be the empty string. Returns a computation in
grthe underlying monad <tt>m</tt> that return either a <a>ParseError</a>
gr(<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.
gr<tt>runParser p state filePath input</tt> runs parser <tt>p</tt> on
grthe input list of tokens <tt>input</tt>, obtained from source
gr<tt>filePath</tt> with the initial user state <tt>st</tt>. The
gr<tt>filePath</tt> is only used in error messages and may be the empty
grstring. Returns either a <a>ParseError</a> (<a>Left</a>) or a value of
grtype <tt>a</tt> (<a>Right</a>).
gr
gr<pre>
grparseFromFile p fname
gr  = do{ input &lt;- readFile fname
gr      ; return (runParser p () fname input)
gr      }
gr</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
grwithout user state. The <tt>filePath</tt> is only used in error
grmessages and may be the empty string. Returns either a
gr<a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
gr(<a>Right</a>).
gr
gr<pre>
grmain    = case (parse numbers "" "11, 2, 43") of
gr           Left err  -&gt; print err
gr           Right xs  -&gt; print (sum xs)
gr
grnumbers = commaSep integer
gr</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>
gragainst input <tt>input</tt> and prints the result to stdout. Used for
grtesting 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
gr<tt>pos</tt>.
setPosition :: (Monad m) => SourcePos -> ParsecT s u m ()

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
gr<a>getInput</a> and <tt>setInput</tt> functions can for example be
grused 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
grstate.
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.
grSuppose that we want to count identifiers in a source, we could use
grthe user state as:
gr
gr<pre>
grexpr  = do{ x &lt;- identifier
gr          ; modifyState (+1)
gr          ; return (Id x)
gr          }
gr</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.Semigroup a => GHC.Base.Semigroup (Text.Parsec.Prim.ParsecT s u m a)
instance (GHC.Base.Monoid a, GHC.Base.Semigroup (Text.Parsec.Prim.ParsecT s u m a)) => GHC.Base.Monoid (Text.Parsec.Prim.ParsecT s u m a)
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.
gr
grSee also the <a>parser-combinators</a> package for additional (and
grgeneralised) combinators.
module Text.Parsec.Combinator

-- | <tt>choice ps</tt> tries to apply the parsers in the list <tt>ps</tt>
grin order, until one of them succeeds. Returns the value of the
grsucceeding 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
gr<tt>n</tt> is smaller or equal to zero, the parser equals to
gr<tt>return []</tt>. Returns a list of <tt>n</tt> values returned by
gr<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
gr<tt>p</tt> and <tt>close</tt>. Returns the value returned by
gr<tt>p</tt>.
gr
gr<pre>
grbraces  = between (symbol "{") (symbol "}")
gr</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>
grfails without consuming input, it returns the value <tt>x</tt>,
grotherwise the value returned by <tt>p</tt>.
gr
gr<pre>
grpriority  = option 0 (do{ d &lt;- digit
gr                        ; return (digitToInt d)
gr                        })
gr</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>
grfails without consuming input, it return <a>Nothing</a>, otherwise it
grreturns <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
gr<tt>p</tt> or nothing. It only fails if <tt>p</tt> fails after
grconsuming 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
grtimes, 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
grtimes. Returns a list of the returned values of <tt>p</tt>.
gr
gr<pre>
grword  = many1 letter
gr</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
gr<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
grreturned by <tt>p</tt>.
gr
gr<pre>
grcommaSep p  = p `sepBy` (symbol ",")
gr</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
gr<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
grreturned 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
gr<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
grvalues returned by <tt>p</tt>.
gr
gr<pre>
grcStatements  = cStatement `endBy` semi
gr</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
gr<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
grvalues 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
gr<tt>p</tt>, separated and optionally ended by <tt>sep</tt>, ie.
grhaskell style statements. Returns a list of values returned by
gr<tt>p</tt>.
gr
gr<pre>
grhaskellStatements  = haskellStatement `sepEndBy` semi
gr</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
gr<tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
grlist 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
gr<tt>p</tt>, separated by <tt>op</tt>. Returns a value obtained by a
gr<i>left</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. If there are zero
groccurrences 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
gr<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
gr<i>left</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. This parser can for
grexample be used to eliminate left recursion which typically occurs in
grexpression grammars.
gr
gr<pre>
grexpr    = term   `chainl1` addop
grterm    = factor `chainl1` mulop
grfactor  = parens expr &lt;|&gt; integer
gr
grmulop   =   do{ symbol "*"; return (*)   }
gr        &lt;|&gt; do{ symbol "/"; return (div) }
gr
graddop   =   do{ symbol "+"; return (+) }
gr        &lt;|&gt; do{ symbol "-"; return (-) }
gr</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
gr<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
gr<i>right</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. If there are no
groccurrences 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|,
grseparated by <tt>op</tt> Returns a value obtained by a <i>right</i>
grassociative application of all functions returned by <tt>op</tt> to
grthe 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
grprimitive parser but it is defined using <a>notFollowedBy</a>.
gr
gr<pre>
greof  = notFollowedBy anyToken &lt;?&gt; "end of input"
gr</pre>
eof :: (Stream s m t, Show t) => ParsecT s u m ()

-- | <tt>notFollowedBy p</tt> only succeeds when parser <tt>p</tt> fails.
grThis parser does not consume any input. This parser can be used to
grimplement the 'longest match' rule. For example, when recognizing
grkeywords (for example <tt>let</tt>), we want to make sure that a
grkeyword is not followed by a legal identifier character, in which case
grthe keyword is actually an identifier (for example <tt>lets</tt>). We
grcan program this behaviour as follows:
gr
gr<pre>
grkeywordLet  = try (do{ string "let"
gr                     ; notFollowedBy alphaNum
gr                     })
gr</pre>
gr
gr<b>NOTE</b>: Currently, <a>notFollowedBy</a> exhibits surprising
grbehaviour when applied to a parser <tt>p</tt> that doesn't consume any
grinput; specifically
gr
gr<ul>
gr<li><tt><a>notFollowedBy</a> . <a>notFollowedBy</a></tt> is <i>not</i>
grequivalent to <a>lookAhead</a>, and</li>
gr<li><tt><a>notFollowedBy</a> <a>eof</a></tt> <i>never</i> fails.</li>
gr</ul>
gr
grSee <a>haskell/parsec#8</a> for more details.
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
grtimes until parser <tt>end</tt> succeeds. Returns the list of values
grreturned by <tt>p</tt>. This parser can be used to scan comments:
gr
gr<pre>
grsimpleComment   = do{ string "&lt;!--"
gr                    ; manyTill anyChar (try (string "--&gt;"))
gr                    }
gr</pre>
gr
grNote the overlapping parsers <tt>anyChar</tt> and <tt>string
gr"--&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.
gr
grIf <tt>p</tt> fails and consumes some input, so does
gr<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
grexample used to implement <a>eof</a>. Returns the accepted token.
anyToken :: (Stream s m t, Show t) => ParsecT s u m t

-- | <tt>parserTrace label</tt> is an impure function, implemented with
gr<a>Debug.Trace</a> that prints to the console the remaining parser
grstate at the time it is invoked. It is intended to be used for
grdebugging parsers by inspecting their intermediate states.
gr
gr<pre>
gr*&gt; parseTest (oneOf "aeiou"  &gt;&gt; parserTrace "label") "atest"
grlabel: "test"
gr...
gr</pre>
parserTrace :: (Show t, Stream s m t) => String -> ParsecT s u m ()

-- | <tt>parserTraced label p</tt> is an impure function, implemented with
gr<a>Debug.Trace</a> that prints to the console the remaining parser
grstate at the time it is invoked. It then continues to apply parser
gr<tt>p</tt>, and if <tt>p</tt> fails will indicate that the label has
grbeen backtracked. It is intended to be used for debugging parsers by
grinspecting their intermediate states.
gr
gr<pre>
gr*&gt;  parseTest (oneOf "aeiou"  &gt;&gt; parserTraced "label" (oneOf "nope")) "atest"
grlabel: "test"
grlabel backtracked
grparse error at (line 1, column 2):
gr...
gr</pre>
parserTraced :: (Stream s m t, Show t) => String -> ParsecT s u m b -> ParsecT s u m b


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

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

-- | This data type specifies operators that work on values of type
gr<tt>a</tt>. An operator is either binary infix or unary prefix or
grpostfix. 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
gra</tt> lists. The list is ordered in descending precedence. All
groperators in one list have the same precedence (but may have a
grdifferent associativity).
type OperatorTable s u m a = [[Operator s u m a]]

-- | <tt>buildExpressionParser table term</tt> builds an expression parser
grfor terms <tt>term</tt> with operators from <tt>table</tt>, taking the
grassociativity and precedence specified in <tt>table</tt> into account.
grPrefix and postfix operators of the same precedence can only occur
gronce (i.e. <tt>--2</tt> is not allowed if <tt>-</tt> is prefix
grnegate). Prefix and postfix operators of the same precedence associate
grto the left (i.e. if <tt>++</tt> is postfix increment, than
gr<tt>-2++</tt> equals <tt>-1</tt>, not <tt>-3</tt>).
gr
grThe <tt>buildExpressionParser</tt> takes care of all the complexity
grinvolved in building expression parser. Here is an example of an
grexpression parser that handles prefix signs, postfix increment and
grbasic arithmetic.
gr
gr<pre>
grexpr    = buildExpressionParser table term
gr        &lt;?&gt; "expression"
gr
grterm    =  parens expr
gr        &lt;|&gt; natural
gr        &lt;?&gt; "simple expression"
gr
grtable   = [ [prefix "-" negate, prefix "+" id ]
gr          , [postfix "++" (+1)]
gr          , [binary "*" (*) AssocLeft, binary "/" (div) AssocLeft ]
gr          , [binary "+" (+) AssocLeft, binary "-" (-)   AssocLeft ]
gr          ]
gr
grbinary  name fun assoc = Infix (do{ reservedOp name; return fun }) assoc
grprefix  name fun       = Prefix (do{ reservedOp name; return fun })
grpostfix name fun       = Postfix (do{ reservedOp name; return fun })
gr</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
grlist of characters <tt>cs</tt>. Returns the parsed character. See also
gr<a>satisfy</a>.
gr
gr<pre>
grvowel  = oneOf "aeiou"
gr</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
grcurrent character <i>not</i> in the supplied list of characters
gr<tt>cs</tt>. Returns the parsed character.
gr
gr<pre>
grconsonant = noneOf "aeiou"
gr</pre>
noneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char

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

-- | Parses a white space character (any character which satisfies
gr<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
grcharacter ('\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>)
grend-of-line. Returns a newline character ('\n').
gr
gr<pre>
grendOfLine = newline &lt;|&gt; crlf
gr</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 (according to <a>isUpper</a>). Returns the
grparsed character.
upper :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a lower case character (according to <a>isLower</a>). Returns
grthe parsed character.
lower :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a letter or digit (a character between '0' and '9') according
grto <a>isAlphaNum</a>. Returns the parsed character.
alphaNum :: (Stream s m Char => ParsecT s u m Char)

-- | Parses a letter (an upper case or lower case character according to
gr<a>isAlpha</a>). Returns the parsed 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
gr'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
grparsed character.
octDigit :: (Stream s m Char) => ParsecT s u m Char

-- | <tt>char c</tt> parses a single character <tt>c</tt>. Returns the
grparsed character (i.e. <tt>c</tt>).
gr
gr<pre>
grsemiColon  = char ';'
gr</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
grsupplied function <tt>f</tt> returns <a>True</a>. Returns the
grcharacter 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>.
grReturns the parsed string (i.e. <tt>s</tt>).
gr
gr<pre>
grdivOrMod    =   string "div"
gr            &lt;|&gt; string "mod"
gr</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
gr<tt>p</tt> on the input read from <tt>filePath</tt> using
gr<a>readFile</a>. Returns either a <a>ParseError</a> (<a>Left</a>) or a
grvalue of type <tt>a</tt> (<a>Right</a>).
gr
gr<pre>
grmain    = do{ result &lt;- parseFromFile numbers "digits.txt"
gr            ; case result of
gr                Left err  -&gt; print err
gr                Right xs  -&gt; print (sum xs)
gr            }
gr</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
gr<tt>p</tt> on the input read from <tt>filePath</tt> using
gr<a>readFile</a>. Returns either a <a>ParseError</a> (<a>Left</a>) or a
grvalue of type <tt>a</tt> (<a>Right</a>).
gr
gr<pre>
grmain    = do{ result &lt;- parseFromFile numbers "digits.txt"
gr            ; case result of
gr                Left err  -&gt; print err
gr                Right xs  -&gt; print (sum xs)
gr            }
gr</pre>
parseFromFile :: Parser a -> String -> IO (Either ParseError a)


-- | This module includes everything you need to get started writing a
grparser.
gr
grBy default this module is set up to parse character data. If you'd
grlike to parse the result of your own tokenizer you should start with
grthe following imports:
gr
gr<pre>
grimport Text.Parsec.Prim
grimport Text.Parsec.Combinator
gr</pre>
gr
grThen you can implement your own version of <a>satisfy</a> on top of
grthe <a>tokenPrim</a> primitive.
module Text.Parsec

-- | ParserT monad transformer and Parser type
gr
gr<tt>ParsecT s u m a</tt> is a parser with stream type <tt>s</tt>, user
grstate type <tt>u</tt>, underlying monad <tt>m</tt> and return type
gr<tt>a</tt>. Parsec is strict in the user state. If this is
grundesirable, simply use a data type like <tt>data Box a = Box a</tt>
grand the state type <tt>Box YourStateType</tt> to add a level of
grindirection.
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
gr<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
grreturns <tt><a>Just</a> x</tt>. The source position of the <tt>t</tt>
grshould be returned by <tt>posFromTok t</tt> and the token can be shown
grusing <tt>showTok t</tt>.
gr
grThis combinator is expressed in terms of <a>tokenPrim</a>. It is used
grto accept user defined token streams. For example, suppose that we
grhave a stream of basic tokens tupled with source positions. We can
grthen define a parser that accepts single tokens as:
gr
gr<pre>
grmytoken x
gr  = token showTok posFromTok testTok
gr  where
gr    showTok (pos,t)     = show t
gr    posFromTok (pos,t)  = pos
gr    testTok (pos,t)     = if x == t then Just t else Nothing
gr</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
grinput</tt> runs parser <tt>p</tt> on the input list of tokens
gr<tt>input</tt>, obtained from source <tt>filePath</tt> with the
grinitial user state <tt>st</tt>. The <tt>filePath</tt> is only used in
grerror messages and may be the empty string. Returns a computation in
grthe underlying monad <tt>m</tt> that return either a <a>ParseError</a>
gr(<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.
gr<tt>runParser p state filePath input</tt> runs parser <tt>p</tt> on
grthe input list of tokens <tt>input</tt>, obtained from source
gr<tt>filePath</tt> with the initial user state <tt>st</tt>. The
gr<tt>filePath</tt> is only used in error messages and may be the empty
grstring. Returns either a <a>ParseError</a> (<a>Left</a>) or a value of
grtype <tt>a</tt> (<a>Right</a>).
gr
gr<pre>
grparseFromFile p fname
gr  = do{ input &lt;- readFile fname
gr      ; return (runParser p () fname input)
gr      }
gr</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
grwithout user state. The <tt>filePath</tt> is only used in error
grmessages and may be the empty string. Returns either a
gr<a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
gr(<a>Right</a>).
gr
gr<pre>
grmain    = case (parse numbers "" "11, 2, 43") of
gr           Left err  -&gt; print err
gr           Right xs  -&gt; print (sum xs)
gr
grnumbers = commaSep integer
gr</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>
gragainst input <tt>input</tt> and prints the result to stdout. Used for
grtesting 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.
grSuppose that we want to count identifiers in a source, we could use
grthe user state as:
gr
gr<pre>
grexpr  = do{ x &lt;- identifier
gr          ; modifyState (+1)
gr          ; return (Id x)
gr          }
gr</pre>
modifyState :: (Monad m) => (u -> u) -> ParsecT s u m ()

-- | This combinator implements choice. The parser <tt>p &lt;|&gt; q</tt>
grfirst applies <tt>p</tt>. If it succeeds, the value of <tt>p</tt> is
grreturned. If <tt>p</tt> fails <i>without consuming any input</i>,
grparser <tt>q</tt> is tried. This combinator is defined equal to the
gr<a>mplus</a> member of the <a>MonadPlus</a> class and the
gr(<a>&lt;|&gt;</a>) member of <a>Alternative</a>.
gr
grThe parser is called <i>predictive</i> since <tt>q</tt> is only tried
grwhen parser <tt>p</tt> didn't consume any input (i.e.. the look ahead
gris 1). This non-backtracking behaviour allows for both an efficient
grimplementation of the parser combinators and the generation of good
grerror 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
grwhenever the parser <tt>p</tt> fails <i>without consuming any
grinput</i>, it replaces expect error messages with the expect error
grmessage <tt>msg</tt>.
gr
grThis is normally used at the end of a set alternatives where we want
grto return an error message in terms of a higher level construct rather
grthan returning all possible characters. For example, if the
gr<tt>expr</tt> parser from the <a>try</a> example would fail, the error
grmessage is: '...: expecting expression'. Without the
gr<tt>(&lt;?&gt;)</tt> combinator, the message would be like '...:
grexpecting "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
groperator.
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
grit pretends that it hasn't consumed any input when an error occurs.
gr
grThis combinator is used whenever arbitrary look ahead is needed. Since
grit pretends that it hasn't consumed any input when <tt>p</tt> fails,
grthe (<a>&lt;|&gt;</a>) combinator will try its second alternative even
grwhen the first parser failed while consuming input.
gr
grThe <tt>try</tt> combinator can for example be used to distinguish
gridentifiers and reserved words. Both reserved words and identifiers
grare a sequence of letters. Whenever we expect a certain reserved word
grwhere we can also expect an identifier we have to use the <tt>try</tt>
grcombinator. Suppose we write:
gr
gr<pre>
grexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
gr
grletExpr     = do{ string "let"; ... }
gridentifier  = many1 letter
gr</pre>
gr
grIf the user writes "lexical", the parser fails with: <tt>unexpected
gr'x', expecting 't' in "let"</tt>. Indeed, since the (<a>&lt;|&gt;</a>)
grcombinator only tries alternatives when the first alternative hasn't
grconsumed input, the <tt>identifier</tt> parser is never tried (because
grthe prefix "le" of the <tt>string "let"</tt> parser is already
grconsumed). The right behaviour can be obtained by adding the
gr<tt>try</tt> combinator:
gr
gr<pre>
grexpr        = letExpr &lt;|&gt; identifier &lt;?&gt; "expression"
gr
grletExpr     = do{ try (string "let"); ... }
gridentifier  = many1 letter
gr</pre>
try :: ParsecT s u m a -> ParsecT s u m a

-- | The parser <tt>unexpected msg</tt> always fails with an unexpected
grerror message <tt>msg</tt> without consuming any input.
gr
grThe parsers <a>fail</a>, (<a>&lt;?&gt;</a>) and <tt>unexpected</tt>
grare the three parsers used to generate error messages. Of these, only
gr(<a>&lt;?&gt;</a>) is commonly used. For an example of the use of
gr<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>
grin order, until one of them succeeds. Returns the value of the
grsucceeding 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
grtimes. Returns a list of the returned values of <tt>p</tt>.
gr
gr<pre>
gridentifier  = do{ c  &lt;- letter
gr                ; cs &lt;- many (alphaNum &lt;|&gt; char '_')
gr                ; return (c:cs)
gr                }
gr</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
grtimes. Returns a list of the returned values of <tt>p</tt>.
gr
gr<pre>
grword  = many1 letter
gr</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
grtimes, skipping its result.
gr
gr<pre>
grspaces  = skipMany space
gr</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
grtimes, 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
gr<tt>n</tt> is smaller or equal to zero, the parser equals to
gr<tt>return []</tt>. Returns a list of <tt>n</tt> values returned by
gr<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
gr<tt>p</tt> and <tt>close</tt>. Returns the value returned by
gr<tt>p</tt>.
gr
gr<pre>
grbraces  = between (symbol "{") (symbol "}")
gr</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>
grfails without consuming input, it returns the value <tt>x</tt>,
grotherwise the value returned by <tt>p</tt>.
gr
gr<pre>
grpriority  = option 0 (do{ d &lt;- digit
gr                        ; return (digitToInt d)
gr                        })
gr</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>
grfails without consuming input, it return <a>Nothing</a>, otherwise it
grreturns <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
gr<tt>p</tt> or nothing. It only fails if <tt>p</tt> fails after
grconsuming 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
gr<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
grreturned by <tt>p</tt>.
gr
gr<pre>
grcommaSep p  = p `sepBy` (symbol ",")
gr</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
gr<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
grreturned 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
gr<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
grvalues returned by <tt>p</tt>.
gr
gr<pre>
grcStatements  = cStatement `endBy` semi
gr</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
gr<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
grvalues 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
gr<tt>p</tt>, separated and optionally ended by <tt>sep</tt>, ie.
grhaskell style statements. Returns a list of values returned by
gr<tt>p</tt>.
gr
gr<pre>
grhaskellStatements  = haskellStatement `sepEndBy` semi
gr</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
gr<tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
grlist 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
gr<tt>p</tt>, separated by <tt>op</tt>. Returns a value obtained by a
gr<i>left</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. If there are zero
groccurrences 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
gr<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
gr<i>left</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. This parser can for
grexample be used to eliminate left recursion which typically occurs in
grexpression grammars.
gr
gr<pre>
grexpr    = term   `chainl1` addop
grterm    = factor `chainl1` mulop
grfactor  = parens expr &lt;|&gt; integer
gr
grmulop   =   do{ symbol "*"; return (*)   }
gr        &lt;|&gt; do{ symbol "/"; return (div) }
gr
graddop   =   do{ symbol "+"; return (+) }
gr        &lt;|&gt; do{ symbol "-"; return (-) }
gr</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
gr<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
gr<i>right</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. If there are no
groccurrences 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|,
grseparated by <tt>op</tt> Returns a value obtained by a <i>right</i>
grassociative application of all functions returned by <tt>op</tt> to
grthe 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
grprimitive parser but it is defined using <a>notFollowedBy</a>.
gr
gr<pre>
greof  = notFollowedBy anyToken &lt;?&gt; "end of input"
gr</pre>
eof :: (Stream s m t, Show t) => ParsecT s u m ()

-- | <tt>notFollowedBy p</tt> only succeeds when parser <tt>p</tt> fails.
grThis parser does not consume any input. This parser can be used to
grimplement the 'longest match' rule. For example, when recognizing
grkeywords (for example <tt>let</tt>), we want to make sure that a
grkeyword is not followed by a legal identifier character, in which case
grthe keyword is actually an identifier (for example <tt>lets</tt>). We
grcan program this behaviour as follows:
gr
gr<pre>
grkeywordLet  = try (do{ string "let"
gr                     ; notFollowedBy alphaNum
gr                     })
gr</pre>
gr
gr<b>NOTE</b>: Currently, <a>notFollowedBy</a> exhibits surprising
grbehaviour when applied to a parser <tt>p</tt> that doesn't consume any
grinput; specifically
gr
gr<ul>
gr<li><tt><a>notFollowedBy</a> . <a>notFollowedBy</a></tt> is <i>not</i>
grequivalent to <a>lookAhead</a>, and</li>
gr<li><tt><a>notFollowedBy</a> <a>eof</a></tt> <i>never</i> fails.</li>
gr</ul>
gr
grSee <a>haskell/parsec#8</a> for more details.
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
grtimes until parser <tt>end</tt> succeeds. Returns the list of values
grreturned by <tt>p</tt>. This parser can be used to scan comments:
gr
gr<pre>
grsimpleComment   = do{ string "&lt;!--"
gr                    ; manyTill anyChar (try (string "--&gt;"))
gr                    }
gr</pre>
gr
grNote the overlapping parsers <tt>anyChar</tt> and <tt>string
gr"--&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.
gr
grIf <tt>p</tt> fails and consumes some input, so does
gr<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
grexample 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
grprovides the source position (<a>SourcePos</a>) of the error and a
grlist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
grreturned by the function <a>parse</a>. <tt>ParseError</tt> is an
grinstance 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.
grIt contains the name of the source (i.e. file name), a line number and
gra column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
gr<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

-- | <tt>parserTrace label</tt> is an impure function, implemented with
gr<a>Debug.Trace</a> that prints to the console the remaining parser
grstate at the time it is invoked. It is intended to be used for
grdebugging parsers by inspecting their intermediate states.
gr
gr<pre>
gr*&gt; parseTest (oneOf "aeiou"  &gt;&gt; parserTrace "label") "atest"
grlabel: "test"
gr...
gr</pre>
parserTrace :: (Show t, Stream s m t) => String -> ParsecT s u m ()

-- | <tt>parserTraced label p</tt> is an impure function, implemented with
gr<a>Debug.Trace</a> that prints to the console the remaining parser
grstate at the time it is invoked. It then continues to apply parser
gr<tt>p</tt>, and if <tt>p</tt> fails will indicate that the label has
grbeen backtracked. It is intended to be used for debugging parsers by
grinspecting their intermediate states.
gr
gr<pre>
gr*&gt;  parseTest (oneOf "aeiou"  &gt;&gt; parserTraced "label" (oneOf "nope")) "atest"
grlabel: "test"
grlabel backtracked
grparse error at (line 1, column 2):
gr...
gr</pre>
parserTraced :: (Stream s m t, Show t) => String -> ParsecT s u m b -> ParsecT s u m b
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
gr<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
grreturns <tt><a>Just</a> x</tt>. The token can be shown using
gr<tt>showTok t</tt>. The position of the <i>next</i> token should be
grreturned when <tt>nextPos</tt> is called with the current source
grposition <tt>pos</tt>, the current token <tt>t</tt> and the rest of
grthe tokens <tt>toks</tt>, <tt>nextPos pos t toks</tt>.
gr
grThis is the most primitive combinator for accepting tokens. For
grexample, the <a>char</a> parser could be implemented as:
gr
gr<pre>
grchar c
gr  = tokenPrim showChar nextPos testChar
gr  where
gr    showChar x        = "'" ++ x ++ "'"
gr    testChar x        = if x == c then Just x else Nothing
gr    nextPos pos x xs  = updatePosChar pos x
gr</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
grstate.
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
grmonad <tt>m</tt> and token type <tt>t</tt> determined by the stream
gr
grSome rough guidelines for a "correct" instance of Stream:
gr
gr<ul>
gr<li>unfoldM uncons gives the [t] corresponding to the stream</li>
gr<li>A <tt>Stream</tt> instance is responsible for maintaining the
gr"position within the stream" in the stream state <tt>s</tt>. This is
grtrivial unless you are using the monad in a non-trivial way.</li>
gr</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
grlook 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
grdo 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
gr<tt>pos</tt>.
setPosition :: (Monad m) => SourcePos -> ParsecT s u m ()

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
gr<a>getInput</a> and <tt>setInput</tt> functions can for example be
grused 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.
gr<tt>parserZero</tt> is defined equal to the <a>mzero</a> member of the
gr<a>MonadPlus</a> class and to the <a>empty</a> member of the
gr<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
grfairly complex since we push the type system to its limits :-) The
gralgorithm is described in:
gr
gr<i>Parsing Permutation Phrases,</i> by Arthur Baars, Andres Loh and
grDoaitse Swierstra. Published as a functional pearl at the Haskell
grWorkshop 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
grthat, when converted by the <a>permute</a> function, parses <tt>s</tt>
grstreams with user state <tt>st</tt> and returns a value of type
gr<tt>a</tt> on success.
gr
grNormally, a permutation parser is first build with special operators
grlike (<a>&lt;||&gt;</a>) and than transformed into a normal parser
grusing <a>permute</a>.
data StreamPermParser s st a

-- | The parser <tt>permute perm</tt> parses a permutation of parser
grdescribed by <tt>perm</tt>. For example, suppose we want to parse a
grpermutation of: an optional string of <tt>a</tt>'s, the character
gr<tt>b</tt> and an optional <tt>c</tt>. This can be described by:
gr
gr<pre>
grtest  = permute (tuple &lt;$?&gt; ("",many1 (char 'a'))
gr                       &lt;||&gt; char 'b'
gr                       &lt;|?&gt; ('_',char 'c'))
gr      where
gr        tuple a b c  = (a,b,c)
gr</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
grthe permutation parser <tt>perm</tt>. The parser <tt>p</tt> is not
grallowed to accept empty input - use the optional combinator
gr(<a>&lt;|?&gt;</a>) instead. Returns a new permutation parser that
grincludes <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
grparser consisting of parser <tt>p</tt>. The the final result of the
grpermutation parser is the function <tt>f</tt> applied to the return
grvalue of <tt>p</tt>. The parser <tt>p</tt> is not allowed to accept
grempty input - use the optional combinator (<a>&lt;$?&gt;</a>) instead.
gr
grIf the function <tt>f</tt> takes more than one parameter, the type
grvariable <tt>b</tt> is instantiated to a functional type which
grcombines nicely with the adds parser <tt>p</tt> to the
gr(<a>&lt;||&gt;</a>) combinator. This results in stylized code where a
grpermutation parser starts with a combining function <tt>f</tt>
grfollowed by the parsers. The function <tt>f</tt> gets its parameters
grin the order in which the parsers are specified, but actual input can
grbe 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>
grto the permutation parser <tt>perm</tt>. The parser <tt>p</tt> is
groptional - if it can not be applied, the default value <tt>x</tt> will
grbe used instead. Returns a new permutation parser that includes the
groptional 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
grparser consisting of parser <tt>p</tt>. The the final result of the
grpermutation parser is the function <tt>f</tt> applied to the return
grvalue of <tt>p</tt>. The parser <tt>p</tt> is optional - if it can not
grbe 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
grthe input read from <tt>filePath</tt> using <a>readFile</a>. Returns
greither a <a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
gr(<a>Right</a>).
gr
gr<pre>
grmain    = do{ result &lt;- parseFromFile numbers "digits.txt"
gr            ; case result of
gr                Left err  -&gt; print err
gr                Right xs  -&gt; print (sum xs)
gr            }
gr</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
gr<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
grparameterizable features of the <a>Text.Parsec.Token</a> module. The
grmodule <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
grlanguage 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
grlanguage 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
grlanguage 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
grexample <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.
grFor 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
grexample <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
grthat this parser should even be defined if the language doesn't
grsupport user-defined operators, or otherwise the <a>reservedOp</a>
grparser 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
gr<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
grstring. This parser will fail on identifiers that are reserved words.
grLegal identifier (start) characters and reserved words are defined in
grthe <a>LanguageDef</a> that is passed to <a>makeTokenParser</a>. An
gr<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>,
grbut it also checks that the <tt>name</tt> is not a prefix of a valid
gridentifier. A <tt>reserved</tt> word is treated as a single token
grusing <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
groperator. This parser will fail on any operators that are reserved
groperators. Legal operator (start) characters and reserved operators
grare defined in the <a>LanguageDef</a> that is passed to
gr<a>makeTokenParser</a>. An <tt>operator</tt> is treated as a single
grtoken using <a>try</a>.
[operator] :: GenTokenParser s u m -> ParsecT s u m String

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

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

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

-- | This lexeme parser parses a natural number (a positive whole number).
grReturns the value of the number. The number can be specified in
gr<a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
grparsed 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
grlike <a>natural</a> except that it can be prefixed with sign (i.e. '-'
gror '+'). Returns the value of the number. The number can be specified
grin <a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
grparsed 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
grthe number. The number is parsed according to the grammar rules
grdefined 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>.
grReturns the value of the number. This parsers deals with any overlap
grin the grammar rules for naturals and floats. The number is parsed
graccording 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
grvalue of the number.
[decimal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Parses a positive whole number in the hexadecimal system. The number
grshould 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
grbe 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
grskips 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
gr<a>whiteSpace</a> parser, returning the value of <tt>p</tt>. Every
grlexical token (lexeme) is defined using <tt>lexeme</tt>, this way
grevery parse starts at a point without white space. Parsers that use
gr<tt>lexeme</tt> are called <i>lexeme</i> parsers in this document.
gr
grThe only point where the <a>whiteSpace</a> parser should be called
grexplicitly is the start of the main parser in order to skip any
grleading white space.
gr
gr<pre>
grmainParser  = do{ whiteSpace
gr                 ; ds &lt;- many (lexeme digit)
gr                 ; eof
gr                 ; return (sum ds)
gr                 }
gr</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
groccurrences of a <a>space</a>, a line comment or a block (multi line)
grcomment. Block comments may be nested. How comments are started and
grended is defined in the <a>LanguageDef</a> that is passed to
gr<a>makeTokenParser</a>.
[whiteSpace] :: GenTokenParser s u m -> ParsecT s u m ()

-- | Lexeme parser <tt>parens p</tt> parses <tt>p</tt> enclosed in
grparenthesis, 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
gr('{' 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
grbrackets ('&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
grbrackets ('[' 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
grwhite 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
grtrailing 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
grtrailing 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
grtrailing 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
groccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
grvalues 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
groccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
grvalues 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
groccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
grvalues 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
groccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
grvalues 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
gr<a>GenTokenParser</a> record that contains lexical parsers that are
grdefined using the definitions in the <tt>language</tt> record.
gr
grThe use of this function is quite stylized - one imports the
grappropiate language definition and selects the lexical parsers that
grare needed from the resulting <a>GenTokenParser</a>.
gr
gr<pre>
grmodule Main where
gr
grimport Text.Parsec
grimport qualified Text.Parsec.Token as P
grimport Text.Parsec.Language (haskellDef)
gr
gr-- The parser
gr...
gr
grexpr  =   parens expr
gr      &lt;|&gt; identifier
gr      &lt;|&gt; ...
gr
gr
gr-- The lexer
grlexer       = P.makeTokenParser haskellDef
gr
grparens      = P.parens lexer
grbraces      = P.braces lexer
gridentifier  = P.identifier lexer
grreserved    = P.reserved lexer
gr...
gr</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
grused 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
grthis definition as the basis for other definitions. <tt>emptyDef</tt>
grhas no reserved names or operators, is case sensitive and doesn't
graccept comments, identifiers or operators.
emptyDef :: LanguageDef st

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

-- | This is a minimal token definition for Java style languages. It
grdefines the style of comments, valid identifiers and case sensitivity.
grIt 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
grparameterizable features of the <a>Text.Parsec.Token</a> module. The
grmodule <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
gr<a>skipMany</a>.
spaces :: (Stream s m Char) => ParsecT s u m ()

-- | Parses a white space character (any character which satisfies
gr<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 (according to <a>isUpper</a>). Returns the
grparsed character.
upper :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a lower case character (according to <a>isLower</a>). Returns
grthe parsed character.
lower :: (Stream s m Char) => ParsecT s u m Char

-- | Parses a letter or digit (a character between '0' and '9') according
grto <a>isAlphaNum</a>. Returns the parsed character.
alphaNum :: (Stream s m Char => ParsecT s u m Char)

-- | Parses a letter (an upper case or lower case character according to
gr<a>isAlpha</a>). Returns the parsed 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
gr'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
grparsed character.
octDigit :: (Stream s m Char) => ParsecT s u m Char

-- | <tt>char c</tt> parses a single character <tt>c</tt>. Returns the
grparsed character (i.e. <tt>c</tt>).
gr
gr<pre>
grsemiColon  = char ';'
gr</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>.
grReturns the parsed string (i.e. <tt>s</tt>).
gr
gr<pre>
grdivOrMod    =   string "div"
gr            &lt;|&gt; string "mod"
gr</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
grlist of characters <tt>cs</tt>. Returns the parsed character. See also
gr<a>satisfy</a>.
gr
gr<pre>
grvowel  = oneOf "aeiou"
gr</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
grcurrent character <i>not</i> in the supplied list of characters
gr<tt>cs</tt>. Returns the parsed character.
gr
gr<pre>
grconsonant = noneOf "aeiou"
gr</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
grsupplied function <tt>f</tt> returns <a>True</a>. Returns the
grcharacter 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>
grin order, until one of them succeeds. Returns the value of the
grsucceeding 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
gr<tt>n</tt> is smaller or equal to zero, the parser equals to
gr<tt>return []</tt>. Returns a list of <tt>n</tt> values returned by
gr<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
gr<tt>p</tt> and <tt>close</tt>. Returns the value returned by
gr<tt>p</tt>.
gr
gr<pre>
grbraces  = between (symbol "{") (symbol "}")
gr</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>
grfails without consuming input, it returns the value <tt>x</tt>,
grotherwise the value returned by <tt>p</tt>.
gr
gr<pre>
grpriority  = option 0 (do{ d &lt;- digit
gr                        ; return (digitToInt d)
gr                        })
gr</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>
grfails without consuming input, it return <a>Nothing</a>, otherwise it
grreturns <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
gr<tt>p</tt> or nothing. It only fails if <tt>p</tt> fails after
grconsuming 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
grtimes, 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
grtimes. Returns a list of the returned values of <tt>p</tt>.
gr
gr<pre>
grword  = many1 letter
gr</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
gr<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
grreturned by <tt>p</tt>.
gr
gr<pre>
grcommaSep p  = p `sepBy` (symbol ",")
gr</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
gr<tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
grreturned 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
gr<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
grvalues returned by <tt>p</tt>.
gr
gr<pre>
grcStatements  = cStatement `endBy` semi
gr</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
gr<tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
grvalues 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
gr<tt>p</tt>, separated and optionally ended by <tt>sep</tt>, ie.
grhaskell style statements. Returns a list of values returned by
gr<tt>p</tt>.
gr
gr<pre>
grhaskellStatements  = haskellStatement `sepEndBy` semi
gr</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
gr<tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
grlist 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
gr<tt>p</tt>, separated by <tt>op</tt>. Returns a value obtained by a
gr<i>left</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. If there are zero
groccurrences 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
gr<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
gr<i>left</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. This parser can for
grexample be used to eliminate left recursion which typically occurs in
grexpression grammars.
gr
gr<pre>
grexpr    = term   `chainl1` addop
grterm    = factor `chainl1` mulop
grfactor  = parens expr &lt;|&gt; integer
gr
grmulop   =   do{ symbol "*"; return (*)   }
gr        &lt;|&gt; do{ symbol "/"; return (div) }
gr
graddop   =   do{ symbol "+"; return (+) }
gr        &lt;|&gt; do{ symbol "-"; return (-) }
gr</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
gr<tt>p</tt>, separated by <tt>op</tt> Returns a value obtained by a
gr<i>right</i> associative application of all functions returned by
gr<tt>op</tt> to the values returned by <tt>p</tt>. If there are no
groccurrences 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|,
grseparated by <tt>op</tt> Returns a value obtained by a <i>right</i>
grassociative application of all functions returned by <tt>op</tt> to
grthe 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
grprimitive parser but it is defined using <a>notFollowedBy</a>.
gr
gr<pre>
greof  = notFollowedBy anyToken &lt;?&gt; "end of input"
gr</pre>
eof :: (Stream s m t, Show t) => ParsecT s u m ()

-- | <tt>notFollowedBy p</tt> only succeeds when parser <tt>p</tt> fails.
grThis parser does not consume any input. This parser can be used to
grimplement the 'longest match' rule. For example, when recognizing
grkeywords (for example <tt>let</tt>), we want to make sure that a
grkeyword is not followed by a legal identifier character, in which case
grthe keyword is actually an identifier (for example <tt>lets</tt>). We
grcan program this behaviour as follows:
gr
gr<pre>
grkeywordLet  = try (do{ string "let"
gr                     ; notFollowedBy alphaNum
gr                     })
gr</pre>
gr
gr<b>NOTE</b>: Currently, <a>notFollowedBy</a> exhibits surprising
grbehaviour when applied to a parser <tt>p</tt> that doesn't consume any
grinput; specifically
gr
gr<ul>
gr<li><tt><a>notFollowedBy</a> . <a>notFollowedBy</a></tt> is <i>not</i>
grequivalent to <a>lookAhead</a>, and</li>
gr<li><tt><a>notFollowedBy</a> <a>eof</a></tt> <i>never</i> fails.</li>
gr</ul>
gr
grSee <a>haskell/parsec#8</a> for more details.
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
grtimes until parser <tt>end</tt> succeeds. Returns the list of values
grreturned by <tt>p</tt>. This parser can be used to scan comments:
gr
gr<pre>
grsimpleComment   = do{ string "&lt;!--"
gr                    ; manyTill anyChar (try (string "--&gt;"))
gr                    }
gr</pre>
gr
grNote the overlapping parsers <tt>anyChar</tt> and <tt>string
gr"--&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.
gr
grIf <tt>p</tt> fails and consumes some input, so does
gr<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
grexample 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
grfour kinds of messages:
gr
gr<pre>
grdata Message = SysUnExpect String
gr             | UnExpect String
gr             | Expect String
gr             | Message String
gr</pre>
gr
grThe fine distinction between different kinds of parse errors allows
grthe system to generate quite good error messages for the user. It also
grallows error messages that are formatted in different languages. Each
grkind of message is generated by different combinators:
gr
gr<ul>
gr<li>A <a>SysUnExpect</a> message is automatically generated by the
gr<a>satisfy</a> combinator. The argument is the unexpected input.</li>
gr<li>A <a>UnExpect</a> message is generated by the <a>unexpected</a>
grcombinator. The argument describes the unexpected item.</li>
gr<li>A <a>Expect</a> message is generated by the <a>&lt;?&gt;</a>
grcombinator. The argument describes the expected item.</li>
gr<li>A <a>Message</a> message is generated by the <a>fail</a>
grcombinator. The argument is some general parser message.</li>
gr</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
grprovides the source position (<a>SourcePos</a>) of the error and a
grlist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
grreturned by the function <a>parse</a>. <tt>ParseError</tt> is an
grinstance 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
grthis definition as the basis for other definitions. <tt>emptyDef</tt>
grhas no reserved names or operators, is case sensitive and doesn't
graccept comments, identifiers or operators.
emptyDef :: LanguageDef st

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

-- | This is a minimal token definition for Java style languages. It
grdefines the style of comments, valid identifiers and case sensitivity.
grIt 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
grparameterizable features of the <a>Text.Parsec.Token</a> module. The
grmodule <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
grlanguage 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
grlanguage 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
grlanguage 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
grexample <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.
grFor 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
grexample <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
grthat this parser should even be defined if the language doesn't
grsupport user-defined operators, or otherwise the <a>reservedOp</a>
grparser 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
grdescribed by <tt>perm</tt>. For example, suppose we want to parse a
grpermutation of: an optional string of <tt>a</tt>'s, the character
gr<tt>b</tt> and an optional <tt>c</tt>. This can be described by:
gr
gr<pre>
grtest  = permute (tuple &lt;$?&gt; ("",many1 (char 'a'))
gr                       &lt;||&gt; char 'b'
gr                       &lt;|?&gt; ('_',char 'c'))
gr      where
gr        tuple a b c  = (a,b,c)
gr</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
grthe permutation parser <tt>perm</tt>. The parser <tt>p</tt> is not
grallowed to accept empty input - use the optional combinator
gr(<a>&lt;|?&gt;</a>) instead. Returns a new permutation parser that
grincludes <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
grparser consisting of parser <tt>p</tt>. The the final result of the
grpermutation parser is the function <tt>f</tt> applied to the return
grvalue of <tt>p</tt>. The parser <tt>p</tt> is not allowed to accept
grempty input - use the optional combinator (<a>&lt;$?&gt;</a>) instead.
gr
grIf the function <tt>f</tt> takes more than one parameter, the type
grvariable <tt>b</tt> is instantiated to a functional type which
grcombines nicely with the adds parser <tt>p</tt> to the
gr(<a>&lt;||&gt;</a>) combinator. This results in stylized code where a
grpermutation parser starts with a combining function <tt>f</tt>
grfollowed by the parsers. The function <tt>f</tt> gets its parameters
grin the order in which the parsers are specified, but actual input can
grbe 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>
grto the permutation parser <tt>perm</tt>. The parser <tt>p</tt> is
groptional - if it can not be applied, the default value <tt>x</tt> will
grbe used instead. Returns a new permutation parser that includes the
groptional 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
grparser consisting of parser <tt>p</tt>. The the final result of the
grpermutation parser is the function <tt>f</tt> applied to the return
grvalue of <tt>p</tt>. The parser <tt>p</tt> is optional - if it can not
grbe 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.
grIt contains the name of the source (i.e. file name), a line number and
gra column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
gr<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
grand column number.
newPos :: SourceName -> Line -> Column -> SourcePos

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

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

-- | The expression <tt>updatePosString pos s</tt> updates the source
grposition <tt>pos</tt> by calling <a>updatePosChar</a> on every
grcharacter 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
grwhenever the parser <tt>p</tt> fails <i>without consuming any
grinput</i>, it replaces expect error messages with the expect error
grmessage <tt>msg</tt>.
gr
grThis is normally used at the end of a set alternatives where we want
grto return an error message in terms of a higher level construct rather
grthan returning all possible characters. For example, if the
gr<tt>expr</tt> parser from the <a>try</a> example would fail, the error
grmessage is: '...: expecting expression'. Without the
gr<tt>(&lt;?&gt;)</tt> combinator, the message would be like '...:
grexpecting "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>
grfirst applies <tt>p</tt>. If it succeeds, the value of <tt>p</tt> is
grreturned. If <tt>p</tt> fails <i>without consuming any input</i>,
grparser <tt>q</tt> is tried. This combinator is defined equal to the
gr<a>mplus</a> member of the <a>MonadPlus</a> class and the
gr(<a>&lt;|&gt;</a>) member of <a>Alternative</a>.
gr
grThe parser is called <i>predictive</i> since <tt>q</tt> is only tried
grwhen parser <tt>p</tt> didn't consume any input (i.e.. the look ahead
gris 1). This non-backtracking behaviour allows for both an efficient
grimplementation of the parser combinators and the generation of good
grerror 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
grwithout user state. The <tt>filePath</tt> is only used in error
grmessages and may be the empty string. Returns either a
gr<a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
gr(<a>Right</a>).
gr
gr<pre>
grmain    = case (parse numbers "" "11, 2, 43") of
gr           Left err  -&gt; print err
gr           Right xs  -&gt; print (sum xs)
gr
grnumbers = commaSep integer
gr</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
grthe input read from <tt>filePath</tt> using <a>readFile</a>. Returns
greither a <a>ParseError</a> (<a>Left</a>) or a value of type <tt>a</tt>
gr(<a>Right</a>).
gr
gr<pre>
grmain    = do{ result &lt;- parseFromFile numbers "digits.txt"
gr            ; case result of
gr                Left err  -&gt; print err
gr                Right xs  -&gt; print (sum xs)
gr            }
gr</pre>
parseFromFile :: Parser a -> String -> IO (Either ParseError a)

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

-- | The parser <tt>token showTok posFromTok testTok</tt> accepts a token
gr<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
grreturns <tt><a>Just</a> x</tt>. The source position of the <tt>t</tt>
grshould be returned by <tt>posFromTok t</tt> and the token can be shown
grusing <tt>showTok t</tt>.
gr
grThis combinator is expressed in terms of <a>tokenPrim</a>. It is used
grto accept user defined token streams. For example, suppose that we
grhave a stream of basic tokens tupled with source positions. We can
grthen define a parser that accepts single tokens as:
gr
gr<pre>
grmytoken x
gr  = token showTok posFromTok testTok
gr  where
gr    showTok (pos,t)     = show t
gr    posFromTok (pos,t)  = pos
gr    testTok (pos,t)     = if x == t then Just t else Nothing
gr</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
gr<tt>t</tt> with result <tt>x</tt> when the function <tt>testTok t</tt>
grreturns <tt><a>Just</a> x</tt>. The token can be shown using
gr<tt>showTok t</tt>. The position of the <i>next</i> token should be
grreturned when <tt>nextPos</tt> is called with the current source
grposition <tt>pos</tt>, the current token <tt>t</tt> and the rest of
grthe tokens <tt>toks</tt>, <tt>nextPos pos t toks</tt>.
gr
grThis is the most primitive combinator for accepting tokens. For
grexample, the <a>char</a> parser could be implemented as:
gr
gr<pre>
grchar c
gr  = tokenPrim showChar nextPos testChar
gr  where
gr    showChar x        = "'" ++ x ++ "'"
gr    testChar x        = if x == c then Just x else Nothing
gr    nextPos pos x xs  = updatePosChar pos x
gr</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
groperator.
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
grerror message <tt>msg</tt> without consuming any input.
gr
grThe parsers <a>fail</a>, (<a>&lt;?&gt;</a>) and <tt>unexpected</tt>
grare the three parsers used to generate error messages. Of these, only
gr(<a>&lt;?&gt;</a>) is commonly used. For an example of the use of
gr<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
grtimes. Returns a list of the returned values of <tt>p</tt>.
gr
gr<pre>
gridentifier  = do{ c  &lt;- letter
gr                ; cs &lt;- many (alphaNum &lt;|&gt; char '_')
gr                ; return (c:cs)
gr                }
gr</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
grtimes, skipping its result.
gr
gr<pre>
grspaces  = skipMany space
gr</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
gr<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
gr<a>getInput</a> and <tt>setInput</tt> functions can for example be
grused 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
grprovides the source position (<a>SourcePos</a>) of the error and a
grlist of error messages (<a>Message</a>). A <tt>ParseError</tt> can be
grreturned by the function <a>parse</a>. <tt>ParseError</tt> is an
grinstance 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.
grIt contains the name of the source (i.e. file name), a line number and
gra column number. <tt>SourcePos</tt> is an instance of the <a>Show</a>,
gr<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
gror 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
grparameterizable features of the <a>Text.Parsec.Token</a> module. The
grmodule <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
grlanguage 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
grlanguage 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
grlanguage 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
grexample <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.
grFor 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
grexample <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
grthat this parser should even be defined if the language doesn't
grsupport user-defined operators, or otherwise the <a>reservedOp</a>
grparser 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
gr<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
grstring. This parser will fail on identifiers that are reserved words.
grLegal identifier (start) characters and reserved words are defined in
grthe <a>LanguageDef</a> that is passed to <a>makeTokenParser</a>. An
gr<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>,
grbut it also checks that the <tt>name</tt> is not a prefix of a valid
gridentifier. A <tt>reserved</tt> word is treated as a single token
grusing <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
groperator. This parser will fail on any operators that are reserved
groperators. Legal operator (start) characters and reserved operators
grare defined in the <a>LanguageDef</a> that is passed to
gr<a>makeTokenParser</a>. An <tt>operator</tt> is treated as a single
grtoken using <a>try</a>.
[operator] :: GenTokenParser s u m -> ParsecT s u m String

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

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

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

-- | This lexeme parser parses a natural number (a positive whole number).
grReturns the value of the number. The number can be specified in
gr<a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
grparsed 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
grlike <a>natural</a> except that it can be prefixed with sign (i.e. '-'
gror '+'). Returns the value of the number. The number can be specified
grin <a>decimal</a>, <a>hexadecimal</a> or <a>octal</a>. The number is
grparsed 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
grthe number. The number is parsed according to the grammar rules
grdefined 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>.
grReturns the value of the number. This parsers deals with any overlap
grin the grammar rules for naturals and floats. The number is parsed
graccording 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
grvalue of the number.
[decimal] :: GenTokenParser s u m -> ParsecT s u m Integer

-- | Parses a positive whole number in the hexadecimal system. The number
grshould 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
grbe 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
grskips 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
gr<a>whiteSpace</a> parser, returning the value of <tt>p</tt>. Every
grlexical token (lexeme) is defined using <tt>lexeme</tt>, this way
grevery parse starts at a point without white space. Parsers that use
gr<tt>lexeme</tt> are called <i>lexeme</i> parsers in this document.
gr
grThe only point where the <a>whiteSpace</a> parser should be called
grexplicitly is the start of the main parser in order to skip any
grleading white space.
gr
gr<pre>
grmainParser  = do{ whiteSpace
gr                 ; ds &lt;- many (lexeme digit)
gr                 ; eof
gr                 ; return (sum ds)
gr                 }
gr</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
groccurrences of a <a>space</a>, a line comment or a block (multi line)
grcomment. Block comments may be nested. How comments are started and
grended is defined in the <a>LanguageDef</a> that is passed to
gr<a>makeTokenParser</a>.
[whiteSpace] :: GenTokenParser s u m -> ParsecT s u m ()

-- | Lexeme parser <tt>parens p</tt> parses <tt>p</tt> enclosed in
grparenthesis, 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
gr('{' 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
grbrackets ('&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
grbrackets ('[' 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
grwhite 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
grtrailing 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
grtrailing 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
grtrailing 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
groccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
grvalues 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
groccurrences of <tt>p</tt> separated by <a>semi</a>. Returns a list of
grvalues 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
groccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
grvalues 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
groccurrences of <tt>p</tt> separated by <a>comma</a>. Returns a list of
grvalues 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
gr<a>GenTokenParser</a> record that contains lexical parsers that are
grdefined using the definitions in the <tt>language</tt> record.
gr
grThe use of this function is quite stylized - one imports the
grappropiate language definition and selects the lexical parsers that
grare needed from the resulting <a>GenTokenParser</a>.
gr
gr<pre>
grmodule Main where
gr
grimport Text.Parsec
grimport qualified Text.Parsec.Token as P
grimport Text.Parsec.Language (haskellDef)
gr
gr-- The parser
gr...
gr
grexpr  =   parens expr
gr      &lt;|&gt; identifier
gr      &lt;|&gt; ...
gr
gr
gr-- The lexer
grlexer       = P.makeTokenParser haskellDef
gr
grparens      = P.parens lexer
grbraces      = P.braces lexer
gridentifier  = P.identifier lexer
grreserved    = P.reserved lexer
gr...
gr</pre>
makeTokenParser :: (Stream s m Char) => GenLanguageDef s u m -> GenTokenParser s u m
