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


-- | Monadic parser combinators
--   
--   This is industrial-strength monadic parser combinator library.
--   Megaparsec is a fork of Parsec library originally written by Daan
--   Leijen.
@package megaparsec
@version 5.3.1


-- | Textual source position. The position includes name of file, line
--   number, and column number. List of such positions can be used to model
--   a stack of include files.
module Text.Megaparsec.Pos

-- | Positive integer that is used to represent line number, column number,
--   and similar things like indentation level. <a>Semigroup</a> instance
--   can be used to safely and purely add <a>Pos</a>es together.
data Pos

-- | Construction of <a>Pos</a> from an instance of <a>Integral</a>. The
--   function throws <a>InvalidPosException</a> when given non-positive
--   argument. Note that the function is polymorphic with respect to
--   <a>MonadThrow</a> <tt>m</tt>, so you can get result inside of
--   <a>Maybe</a>, for example.
mkPos :: (Integral a, MonadThrow m) => a -> m Pos

-- | Extract <a>Word</a> from <a>Pos</a>.
unPos :: Pos -> Word

-- | Dangerous construction of <a>Pos</a>. Use when you know for sure that
--   argument is positive.
unsafePos :: Word -> Pos

-- | The exception is thrown by <a>mkPos</a> when its argument is not a
--   positive number.
data InvalidPosException
InvalidPosException :: InvalidPosException

-- | The data type <tt>SourcePos</tt> represents source positions. It
--   contains the name of the source file, a line number, and a column
--   number. Source line and column positions change intensively during
--   parsing, so we need to make them strict to avoid memory leaks.
data SourcePos
SourcePos :: FilePath -> !Pos -> !Pos -> SourcePos

-- | Name of source file
[sourceName] :: SourcePos -> FilePath

-- | Line number
[sourceLine] :: SourcePos -> !Pos

-- | Column number
[sourceColumn] :: SourcePos -> !Pos

-- | Construct initial position (line 1, column 1) given name of source
--   file.
initialPos :: String -> SourcePos

-- | Pretty-print a <a>SourcePos</a>.
sourcePosPretty :: SourcePos -> String

-- | Update a source position given a character. The first argument
--   specifies the tab width. If the character is a newline ('\n') the line
--   number is incremented by 1. If the character is a tab ('\t') the
--   column number is incremented to the nearest tab position. In all other
--   cases, the column is incremented by 1.
defaultUpdatePos :: Pos -> SourcePos -> Char -> (SourcePos, SourcePos)

-- | Value of tab width used by default. Always prefer this constant when
--   you want to refer to the default tab width because actual value
--   <i>may</i> change in future.
defaultTabWidth :: Pos
instance GHC.Generics.Generic Text.Megaparsec.Pos.SourcePos
instance Data.Data.Data Text.Megaparsec.Pos.SourcePos
instance GHC.Classes.Ord Text.Megaparsec.Pos.SourcePos
instance GHC.Classes.Eq Text.Megaparsec.Pos.SourcePos
instance GHC.Read.Read Text.Megaparsec.Pos.SourcePos
instance GHC.Show.Show Text.Megaparsec.Pos.SourcePos
instance GHC.Generics.Generic Text.Megaparsec.Pos.InvalidPosException
instance Data.Data.Data Text.Megaparsec.Pos.InvalidPosException
instance GHC.Show.Show Text.Megaparsec.Pos.InvalidPosException
instance GHC.Classes.Eq Text.Megaparsec.Pos.InvalidPosException
instance Control.DeepSeq.NFData Text.Megaparsec.Pos.Pos
instance Data.Data.Data Text.Megaparsec.Pos.Pos
instance GHC.Classes.Ord Text.Megaparsec.Pos.Pos
instance GHC.Classes.Eq Text.Megaparsec.Pos.Pos
instance GHC.Show.Show Text.Megaparsec.Pos.Pos
instance Test.QuickCheck.Arbitrary.Arbitrary Text.Megaparsec.Pos.Pos
instance Data.Semigroup.Semigroup Text.Megaparsec.Pos.Pos
instance GHC.Read.Read Text.Megaparsec.Pos.Pos
instance Test.QuickCheck.Arbitrary.Arbitrary Text.Megaparsec.Pos.SourcePos
instance GHC.Exception.Exception Text.Megaparsec.Pos.InvalidPosException
instance Control.DeepSeq.NFData Text.Megaparsec.Pos.InvalidPosException
instance Control.DeepSeq.NFData Text.Megaparsec.Pos.SourcePos


-- | Parse errors. Current version of Megaparsec supports well-typed errors
--   instead of <a>String</a>-based ones. This gives a lot of flexibility
--   in describing what exactly went wrong as well as a way to return
--   arbitrary data in case of failure.
module Text.Megaparsec.Error

-- | Data type that is used to represent “unexpected/expected” items in
--   <a>ParseError</a>. The data type is parametrized over the token type
--   <tt>t</tt>.
data ErrorItem t

-- | Non-empty stream of tokens
Tokens :: (NonEmpty t) -> ErrorItem t

-- | Label (cannot be empty)
Label :: (NonEmpty Char) -> ErrorItem t

-- | End of input
EndOfInput :: ErrorItem t

-- | The type class defines how to represent information about various
--   exceptional situations. Data types that are used as custom data
--   component in <a>ParseError</a> must be instances of this type class.
class Ord e => ErrorComponent e

-- | Represent the message passed to <a>fail</a> in parser monad.
representFail :: ErrorComponent e => String -> e

-- | Represent information about incorrect indentation.
representIndentation :: ErrorComponent e => Ordering -> Pos -> Pos -> e

-- | “Default error component”. This is our instance of
--   <a>ErrorComponent</a> provided out-of-box.
data Dec

-- | <a>fail</a> has been used in parser monad
DecFail :: String -> Dec

-- | Incorrect indentation error: desired ordering between reference level
--   and actual level, reference indentation level, actual indentation
--   level
DecIndentation :: Ordering -> Pos -> Pos -> Dec

-- | <a>ParseError</a> represents… parse errors. It provides the stack of
--   source positions, a set of expected and unexpected tokens as well as a
--   set of custom associated data. The data type is parametrized over the
--   token type <tt>t</tt> and the custom data <tt>e</tt>.
--   
--   Note that the stack of source positions contains current position as
--   its head, and the rest of positions allows to track full sequence of
--   include files with topmost source file at the end of the list.
--   
--   <a>Semigroup</a> (and <a>Monoid</a>) instance of the data type allows
--   to merge parse errors from different branches of parsing. When merging
--   two <a>ParseError</a>s, the longest match is preferred; if positions
--   are the same, custom data sets and collections of message items are
--   combined.
data ParseError t e
ParseError :: NonEmpty SourcePos -> Set (ErrorItem t) -> Set (ErrorItem t) -> Set e -> ParseError t e

-- | Stack of source positions
[errorPos] :: ParseError t e -> NonEmpty SourcePos

-- | Unexpected items
[errorUnexpected] :: ParseError t e -> Set (ErrorItem t)

-- | Expected items
[errorExpected] :: ParseError t e -> Set (ErrorItem t)

-- | Associated data, if any
[errorCustom] :: ParseError t e -> Set e

-- | Type class <a>ShowToken</a> includes methods that allow to
--   pretty-print single token as well as stream of tokens. This is used
--   for rendering of error messages.
class ShowToken a

-- | Pretty-print non-empty stream of tokens. This function is also used to
--   print single tokens (represented as singleton lists).
showTokens :: ShowToken a => NonEmpty a -> String

-- | The type class defines how to print custom data component of
--   <a>ParseError</a>.
class Ord a => ShowErrorComponent a

-- | Pretty-print custom data component of <a>ParseError</a>.
showErrorComponent :: ShowErrorComponent a => a -> String

-- | Pretty-print a <a>ParseError</a>. The rendered <a>String</a> always
--   ends with a newline.
--   
--   The function is defined as:
--   
--   <pre>
--   parseErrorPretty e =
--     sourcePosStackPretty (errorPos e) ++ ":\n" ++ parseErrorTextPretty e
--   </pre>
parseErrorPretty :: (Ord t, ShowToken t, ShowErrorComponent e) => ParseError t e -> String

-- | Pretty-print a stack of source positions.
sourcePosStackPretty :: NonEmpty SourcePos -> String

-- | Pretty-print a textual part of a <a>ParseError</a>, that is,
--   everything except stack of source positions. The rendered staring
--   always ends with a new line.
parseErrorTextPretty :: (Ord t, ShowToken t, ShowErrorComponent e) => ParseError t e -> String
instance GHC.Generics.Generic (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Classes.Ord e, GHC.Classes.Ord t, Data.Data.Data e, Data.Data.Data t) => Data.Data.Data (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Classes.Eq e, GHC.Classes.Eq t) => GHC.Classes.Eq (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Classes.Ord e, GHC.Classes.Ord t, GHC.Read.Read e, GHC.Read.Read t) => GHC.Read.Read (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Show.Show e, GHC.Show.Show t) => GHC.Show.Show (Text.Megaparsec.Error.ParseError t e)
instance Data.Data.Data Text.Megaparsec.Error.Dec
instance GHC.Classes.Ord Text.Megaparsec.Error.Dec
instance GHC.Classes.Eq Text.Megaparsec.Error.Dec
instance GHC.Read.Read Text.Megaparsec.Error.Dec
instance GHC.Show.Show Text.Megaparsec.Error.Dec
instance GHC.Generics.Generic (Text.Megaparsec.Error.ErrorItem t)
instance Data.Data.Data t => Data.Data.Data (Text.Megaparsec.Error.ErrorItem t)
instance GHC.Classes.Ord t => GHC.Classes.Ord (Text.Megaparsec.Error.ErrorItem t)
instance GHC.Classes.Eq t => GHC.Classes.Eq (Text.Megaparsec.Error.ErrorItem t)
instance GHC.Read.Read t => GHC.Read.Read (Text.Megaparsec.Error.ErrorItem t)
instance GHC.Show.Show t => GHC.Show.Show (Text.Megaparsec.Error.ErrorItem t)
instance Control.DeepSeq.NFData t => Control.DeepSeq.NFData (Text.Megaparsec.Error.ErrorItem t)
instance Test.QuickCheck.Arbitrary.Arbitrary t => Test.QuickCheck.Arbitrary.Arbitrary (Text.Megaparsec.Error.ErrorItem t)
instance Text.Megaparsec.Error.ErrorComponent ()
instance Control.DeepSeq.NFData Text.Megaparsec.Error.Dec
instance Test.QuickCheck.Arbitrary.Arbitrary Text.Megaparsec.Error.Dec
instance Text.Megaparsec.Error.ErrorComponent Text.Megaparsec.Error.Dec
instance (Control.DeepSeq.NFData t, Control.DeepSeq.NFData e) => Control.DeepSeq.NFData (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Classes.Ord t, GHC.Classes.Ord e) => Data.Semigroup.Semigroup (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Classes.Ord t, GHC.Classes.Ord e) => GHC.Base.Monoid (Text.Megaparsec.Error.ParseError t e)
instance (GHC.Show.Show t, Data.Typeable.Internal.Typeable t, GHC.Classes.Ord t, Text.Megaparsec.Error.ShowToken t, GHC.Show.Show e, Data.Typeable.Internal.Typeable e, Text.Megaparsec.Error.ShowErrorComponent e) => GHC.Exception.Exception (Text.Megaparsec.Error.ParseError t e)
instance (Test.QuickCheck.Arbitrary.Arbitrary t, GHC.Classes.Ord t, Test.QuickCheck.Arbitrary.Arbitrary e, GHC.Classes.Ord e) => Test.QuickCheck.Arbitrary.Arbitrary (Text.Megaparsec.Error.ParseError t e)
instance Text.Megaparsec.Error.ShowToken GHC.Types.Char
instance (GHC.Classes.Ord t, Text.Megaparsec.Error.ShowToken t) => Text.Megaparsec.Error.ShowErrorComponent (Text.Megaparsec.Error.ErrorItem t)
instance Text.Megaparsec.Error.ShowErrorComponent Text.Megaparsec.Error.Dec


-- | The primitive parser combinators.
module Text.Megaparsec.Prim

-- | This is the Megaparsec's state, it's parametrized over stream type
--   <tt>s</tt>.
data State s
State :: s -> NonEmpty SourcePos -> {-# UNPACK #-} !Word -> Pos -> State s

-- | Current input (already processed input is removed from the stream)
[stateInput] :: State s -> s

-- | Current position (column + line number) with support for include files
[statePos] :: State s -> NonEmpty SourcePos

-- | Number of processed tokens so far
[stateTokensProcessed] :: State s -> {-# UNPACK #-} !Word

-- | Tab width to use
[stateTabWidth] :: State s -> Pos

-- | An instance of <tt>Stream s</tt> has stream type <tt>s</tt>. Token
--   type is determined by the stream and can be found via <a>Token</a>
--   type function.
class Ord (Token s) => Stream s where type Token s :: * where {
    type family Token s :: *;
}

-- | Get next token from the stream. If the stream is empty, return
--   <a>Nothing</a>.
uncons :: Stream s => s -> Maybe (Token s, s)

-- | Update position in stream given tab width, current position, and
--   current token. The result is a tuple where the first element will be
--   used to report parse errors for current token, while the second
--   element is the incremented position that will be stored in the
--   parser's state. The stored (incremented) position is used whenever
--   position can't be/shouldn't be updated by consuming a token. For
--   example, when using <a>failure</a>, we don't grab a new token (we need
--   to fail right were we are now), so error position will be taken from
--   parser's state.
--   
--   When you work with streams where elements do not contain information
--   about their position in input, the result is usually consists of the
--   third argument unchanged and incremented position calculated with
--   respect to current token. This is how default instances of
--   <a>Stream</a> work (they use <a>defaultUpdatePos</a>, which may be a
--   good starting point for your own position-advancing function).
--   
--   When you wish to deal with a stream of tokens where every token
--   “knows” its start and end position in input (for example, you have
--   produced the stream with Happy/Alex), then the best strategy is to use
--   the start position as the actual element position and provide the end
--   position of the token as the incremented one.
updatePos :: Stream s => Proxy s -> Pos -> SourcePos -> Token s -> (SourcePos, SourcePos)

-- | <tt>Parsec</tt> is a non-transformer variant of the more general
--   <a>ParsecT</a> monad transformer.
type Parsec e s = ParsecT e s Identity

-- | <tt>ParsecT e s m a</tt> is a parser with custom data component of
--   error <tt>e</tt>, stream type <tt>s</tt>, underlying monad <tt>m</tt>
--   and return type <tt>a</tt>.
data ParsecT e s m a

-- | Type class describing parsers independent of input type.
class (ErrorComponent e, Stream s, Alternative m, MonadPlus m) => MonadParsec e s m | m -> e s where hidden = label ""

-- | The most general way to stop parsing and report a <a>ParseError</a>.
--   
--   <a>unexpected</a> is defined in terms of this function:
--   
--   <pre>
--   unexpected item = failure (Set.singleton item) Set.empty Set.empty
--   </pre>
failure :: MonadParsec e s m => Set (ErrorItem (Token s)) -> Set (ErrorItem (Token s)) -> Set e -> m a

-- | The parser <tt>label name p</tt> behaves as parser <tt>p</tt>, but
--   whenever the parser <tt>p</tt> fails <i>without consuming any
--   input</i>, it replaces names of “expected” tokens with the name
--   <tt>name</tt>.
label :: MonadParsec e s m => String -> m a -> m a

-- | <tt>hidden p</tt> behaves just like parser <tt>p</tt>, but it doesn't
--   show any “expected” tokens in error message when <tt>p</tt> fails.
hidden :: MonadParsec e s m => m a -> m a

-- | The parser <tt>try p</tt> behaves like parser <tt>p</tt>, except that
--   it backtracks the parser state when <tt>p</tt> fails (either consuming
--   input or not).
--   
--   This combinator is used whenever arbitrary look ahead is needed. Since
--   it pretends that it hasn't consumed any input when <tt>p</tt> fails,
--   the (<a>&lt;|&gt;</a>) combinator will try its second alternative even
--   when the first parser failed while consuming input.
--   
--   For example, here is a parser that is supposed to parse the word “let”
--   or the word “lexical”:
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (string "let" &lt;|&gt; string "lexical") "lexical"
--   1:1:
--   unexpected "lex"
--   expecting "let"
--   </pre>
--   
--   What happens here? The first parser consumes “le” and fails (because
--   it doesn't see a “t”). The second parser, however, isn't tried, since
--   the first parser has already consumed some input! <a>try</a> fixes
--   this behavior and allows backtracking to work:
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (try (string "let") &lt;|&gt; string "lexical") "lexical"
--   "lexical"
--   </pre>
--   
--   <tt>try</tt> also improves error messages in case of overlapping
--   alternatives, because Megaparsec's hint system can be used:
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (try (string "let") &lt;|&gt; string "lexical") "le"
--   1:1:
--   unexpected "le"
--   expecting "let" or "lexical"
--   </pre>
--   
--   <b>Please note</b> that as of Megaparsec 4.4.0, <tt>string</tt>
--   backtracks automatically (see <a>tokens</a>), so it does not need
--   <a>try</a>. However, the examples above demonstrate the idea behind
--   <a>try</a> so well that it was decided to keep them. You still need to
--   use <a>try</a> when your alternatives are complex, composite parsers.
try :: MonadParsec e s m => m a -> m a

-- | If <tt>p</tt> in <tt>lookAhead p</tt> succeeds (either consuming input
--   or not) the whole parser behaves like <tt>p</tt> succeeded without
--   consuming anything (parser state is not updated as well). If
--   <tt>p</tt> fails, <tt>lookAhead</tt> has no effect, i.e. it will fail
--   consuming input if <tt>p</tt> fails consuming input. Combine with
--   <a>try</a> if this is undesirable.
lookAhead :: MonadParsec e s m => m a -> m a

-- | <tt>notFollowedBy p</tt> only succeeds when the parser <tt>p</tt>
--   fails. This parser <i>never consumes</i> any input and <i>never
--   modifies</i> parser state. It can be used to implement the “longest
--   match” rule.
notFollowedBy :: MonadParsec e s m => m a -> m ()

-- | <tt>withRecovery r p</tt> allows continue parsing even if parser
--   <tt>p</tt> fails. In this case <tt>r</tt> is called with the actual
--   <a>ParseError</a> as its argument. Typical usage is to return a value
--   signifying failure to parse this particular object and to consume some
--   part of the input up to the point where the next object starts.
--   
--   Note that if <tt>r</tt> fails, original error message is reported as
--   if without <a>withRecovery</a>. In no way recovering parser <tt>r</tt>
--   can influence error messages.
withRecovery :: MonadParsec e s m => (ParseError (Token s) e -> m a) -> m a -> m a

-- | <tt>observing p</tt> allows to “observe” failure of the <tt>p</tt>
--   parser, should it happen, without actually ending parsing, but instead
--   getting the <a>ParseError</a> in <a>Left</a>. On success parsed value
--   is returned in <a>Right</a> as usual. Note that this primitive just
--   allows you to observe parse errors as they happen, it does not
--   backtrack or change how the <tt>p</tt> parser works in any way.
observing :: MonadParsec e s m => m a -> m (Either (ParseError (Token s) e) a)

-- | This parser only succeeds at the end of the input.
eof :: MonadParsec e s m => m ()

-- | The parser <tt>token test mrep</tt> accepts a token <tt>t</tt> with
--   result <tt>x</tt> when the function <tt>test t</tt> returns
--   <tt><a>Right</a> x</tt>. <tt>mrep</tt> may provide representation of
--   the token to report in error messages when input stream in empty.
--   
--   This is the most primitive combinator for accepting tokens. For
--   example, the <a>satisfy</a> parser is implemented as:
--   
--   <pre>
--   satisfy f = token testChar Nothing
--     where
--       testChar x =
--         if f x
--           then Right x
--           else Left (Set.singleton (Tokens (x:|[])), Set.empty, Set.empty)
--   </pre>
token :: MonadParsec e s m => (Token s -> Either (Set (ErrorItem (Token s)), Set (ErrorItem (Token s)), Set e) a) -> Maybe (Token s) -> m a

-- | The parser <tt>tokens test</tt> parses a list of tokens and returns
--   it. Supplied predicate <tt>test</tt> is used to check equality of
--   given and parsed tokens.
--   
--   This can be used for example to write <a>string</a>:
--   
--   <pre>
--   string = tokens (==)
--   </pre>
--   
--   Note that beginning from Megaparsec 4.4.0, this is an
--   auto-backtracking primitive, which means that if it fails, it never
--   consumes any input. This is done to make its consumption model match
--   how error messages for this primitive are reported (which becomes an
--   important thing as user gets more control with primitives like
--   <a>withRecovery</a>):
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (string "abc") "abd"
--   1:1:
--   unexpected "abd"
--   expecting "abc"
--   </pre>
--   
--   This means, in particular, that it's no longer necessary to use
--   <a>try</a> with <a>tokens</a>-based parsers, such as <a>string</a> and
--   <a>string'</a>. This feature <i>does not</i> affect performance in any
--   way.
tokens :: MonadParsec e s m => (Token s -> Token s -> Bool) -> [Token s] -> m [Token s]

-- | Return the full parser state as a <a>State</a> record.
getParserState :: MonadParsec e s m => m (State s)

-- | <tt>updateParserState f</tt> applies the function <tt>f</tt> to the
--   parser state.
updateParserState :: MonadParsec e s m => (State s -> State s) -> m ()

-- | A synonym for <a>label</a> in the form of an operator.
(<?>) :: MonadParsec e s m => m a -> String -> m a
infix 0 <?>

-- | The parser <tt>unexpected item</tt> fails with an error message
--   telling about unexpected item <tt>item</tt> without consuming any
--   input.
unexpected :: MonadParsec e s m => ErrorItem (Token s) -> m a

-- | Return both the result of a parse and the list of tokens that were
--   consumed during parsing. This relies on the change of the
--   <a>stateTokensProcessed</a> value to evaluate how many tokens were
--   consumed.
match :: MonadParsec e s m => m a -> m ([Token s], a)

-- | Specify how to process <a>ParseError</a>s that happen inside of this
--   wrapper. As a side effect of the current implementation changing
--   <a>errorPos</a> with this combinator will also change the final
--   <a>statePos</a> in the parser state.
region :: MonadParsec e s m => (ParseError (Token s) e -> ParseError (Token s) e) -> m a -> m a

-- | Return the current input.
getInput :: MonadParsec e s m => m s

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
--   <a>getInput</a> and <a>setInput</a> functions can for example be used
--   to deal with include files.
setInput :: MonadParsec e s m => s -> m ()

-- | Return the current source position.
--   
--   See also: <a>setPosition</a>, <a>pushPosition</a>, <a>popPosition</a>,
--   and <a>SourcePos</a>.
getPosition :: MonadParsec e s m => m SourcePos

-- | Get the position where the next token in the stream begins. If the
--   stream is empty, return <a>Nothing</a>.
getNextTokenPosition :: forall e s m. MonadParsec e s m => m (Maybe SourcePos)

-- | <tt>setPosition pos</tt> sets the current source position to
--   <tt>pos</tt>.
--   
--   See also: <a>getPosition</a>, <a>pushPosition</a>, <a>popPosition</a>,
--   and <a>SourcePos</a>.
setPosition :: MonadParsec e s m => SourcePos -> m ()

-- | Push a position into stack of positions and continue parsing working
--   with this position. Useful for working with include files and the
--   like.
--   
--   See also: <a>getPosition</a>, <a>setPosition</a>, <a>popPosition</a>,
--   and <a>SourcePos</a>.
pushPosition :: MonadParsec e s m => SourcePos -> m ()

-- | Pop a position from the stack of positions unless it only contains one
--   element (in that case the stack of positions remains the same). This
--   is how to return to previous source file after <a>pushPosition</a>.
--   
--   See also: <a>getPosition</a>, <a>setPosition</a>, <a>pushPosition</a>,
--   and <a>SourcePos</a>.
popPosition :: MonadParsec e s m => m ()

-- | Get the number of tokens processed so far.
getTokensProcessed :: MonadParsec e s m => m Word

-- | Set the number of tokens processed so far.
setTokensProcessed :: MonadParsec e s m => Word -> m ()

-- | Return the tab width. The default tab width is equal to
--   <a>defaultTabWidth</a>. You can set a different tab width with the
--   help of <a>setTabWidth</a>.
getTabWidth :: MonadParsec e s m => m Pos

-- | Set tab width. If the argument of the function is not a positive
--   number, <a>defaultTabWidth</a> will be used.
setTabWidth :: MonadParsec e s m => Pos -> m ()

-- | <tt>setParserState st</tt> sets the parser state to <tt>st</tt>.
setParserState :: MonadParsec e s m => State s -> m ()

-- | <tt>parse p file input</tt> runs parser <tt>p</tt> over
--   <a>Identity</a> (see <a>runParserT</a> if you're using the
--   <a>ParsecT</a> monad transformer; <a>parse</a> itself is just a
--   synonym for <a>runParser</a>). It returns either a <a>ParseError</a>
--   (<a>Left</a>) or a value of type <tt>a</tt> (<a>Right</a>).
--   <a>parseErrorPretty</a> can be used to turn <a>ParseError</a> into the
--   string representation of the error message. See
--   <a>Text.Megaparsec.Error</a> if you need to do more advanced error
--   analysis.
--   
--   <pre>
--   main = case (parse numbers "" "11,2,43") of
--            Left err -&gt; putStr (parseErrorPretty err)
--            Right xs -&gt; print (sum xs)
--   
--   numbers = integer `sepBy` char ','
--   </pre>
parse :: Parsec e s a -> String -> s -> Either (ParseError (Token s) e) a

-- | <tt>parseMaybe p input</tt> runs the parser <tt>p</tt> on
--   <tt>input</tt> and returns the result inside <a>Just</a> on success
--   and <a>Nothing</a> on failure. This function also parses <a>eof</a>,
--   so if the parser doesn't consume all of its input, it will fail.
--   
--   The function is supposed to be useful for lightweight parsing, where
--   error messages (and thus file name) are not important and entire input
--   should be parsed. For example it can be used when parsing of a single
--   number according to specification of its format is desired.
parseMaybe :: (ErrorComponent e, Stream s) => Parsec e s a -> s -> Maybe a

-- | The expression <tt>parseTest p input</tt> applies the parser
--   <tt>p</tt> against input <tt>input</tt> and prints the result to
--   stdout. Useful for testing.
parseTest :: (ShowErrorComponent e, Ord (Token s), ShowToken (Token s), Show a) => Parsec e s a -> s -> IO ()

-- | <tt>runParser p file input</tt> runs parser <tt>p</tt> on the input
--   stream of tokens <tt>input</tt>, obtained from source <tt>file</tt>.
--   The <tt>file</tt> is only used in error messages and may be the empty
--   string. Returns either a <a>ParseError</a> (<a>Left</a>) or a value of
--   type <tt>a</tt> (<a>Right</a>).
--   
--   <pre>
--   parseFromFile p file = runParser p file &lt;$&gt; readFile file
--   </pre>
runParser :: Parsec e s a -> String -> s -> Either (ParseError (Token s) e) a

-- | The function is similar to <a>runParser</a> with the difference that
--   it accepts and returns parser state. This allows to specify arbitrary
--   textual position at the beginning of parsing, for example. This is the
--   most general way to run a parser over the <a>Identity</a> monad.
runParser' :: Parsec e s a -> State s -> (State s, Either (ParseError (Token s) e) a)

-- | <tt>runParserT p file input</tt> runs parser <tt>p</tt> on the input
--   list of tokens <tt>input</tt>, obtained from source <tt>file</tt>. The
--   <tt>file</tt> is only used in error messages and may be the empty
--   string. Returns a computation in the underlying monad <tt>m</tt> that
--   returns either a <a>ParseError</a> (<a>Left</a>) or a value of type
--   <tt>a</tt> (<a>Right</a>).
runParserT :: Monad m => ParsecT e s m a -> String -> s -> m (Either (ParseError (Token s) e) a)

-- | This function is similar to <a>runParserT</a>, but like
--   <a>runParser'</a> it accepts and returns parser state. This is thus
--   the most general way to run a parser.
runParserT' :: Monad m => ParsecT e s m a -> State s -> m (State s, Either (ParseError (Token s) e) a)

-- | <tt>dbg label p</tt> parser works exactly like <tt>p</tt>, but when
--   it's evaluated it also prints information useful for debugging. The
--   <tt>label</tt> is only used to refer to this parser in the debugging
--   output. This combinator uses the <a>trace</a> function from
--   <a>Debug.Trace</a> under the hood.
--   
--   Typical usage is to wrap every sub-parser in misbehaving parser with
--   <a>dbg</a> assigning meaningful labels. Then give it a shot and go
--   through the print-out. As of current version, this combinator prints
--   all available information except for <i>hints</i>, which are probably
--   only interesting to the maintainer of Megaparsec itself and may be
--   quite verbose to output in general. Let me know if you would like to
--   be able to see hints in the debugging output.
--   
--   The output itself is pretty self-explanatory, although the following
--   abbreviations should be clarified (they are derived from the low-level
--   source code):
--   
--   <ul>
--   <li><tt>COK</tt>—“consumed OK”. The parser consumed input and
--   succeeded.</li>
--   <li><tt>CERR</tt>—“consumed error”. The parser consumed input and
--   failed.</li>
--   <li><tt>EOK</tt>—“empty OK”. The parser succeeded without consuming
--   input.</li>
--   <li><tt>EERR</tt>—“empty error”. The parser failed without consuming
--   input.</li>
--   </ul>
--   
--   Finally, it's not possible to lift this function into some monad
--   transformers without introducing surprising behavior (e.g. unexpected
--   state backtracking) or adding otherwise redundant constraints (e.g.
--   <a>Show</a> instance for state), so this helper is only available for
--   <a>ParsecT</a> monad, not <a>MonadParsec</a> in general.
dbg :: forall e s m a. (Stream s, ShowToken (Token s), ShowErrorComponent e, Show a) => String -> ParsecT e s m a -> ParsecT e s m a
instance GHC.Base.Monoid (Text.Megaparsec.Prim.Hints t)
instance Data.Semigroup.Semigroup (Text.Megaparsec.Prim.Hints t)
instance GHC.Generics.Generic (Text.Megaparsec.Prim.State s)
instance Data.Data.Data s => Data.Data.Data (Text.Megaparsec.Prim.State s)
instance GHC.Classes.Eq s => GHC.Classes.Eq (Text.Megaparsec.Prim.State s)
instance GHC.Show.Show s => GHC.Show.Show (Text.Megaparsec.Prim.State s)
instance Control.DeepSeq.NFData s => Control.DeepSeq.NFData (Text.Megaparsec.Prim.State s)
instance Test.QuickCheck.Arbitrary.Arbitrary a => Test.QuickCheck.Arbitrary.Arbitrary (Text.Megaparsec.Prim.State a)
instance Text.Megaparsec.Prim.Stream GHC.Base.String
instance Text.Megaparsec.Prim.Stream Data.ByteString.Internal.ByteString
instance Text.Megaparsec.Prim.Stream Data.ByteString.Lazy.Internal.ByteString
instance Text.Megaparsec.Prim.Stream Data.Text.Internal.Text
instance Text.Megaparsec.Prim.Stream Data.Text.Internal.Lazy.Text
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, Data.Semigroup.Semigroup a) => Data.Semigroup.Semigroup (Text.Megaparsec.Prim.ParsecT e s m a)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, GHC.Base.Monoid a) => GHC.Base.Monoid (Text.Megaparsec.Prim.ParsecT e s m a)
instance GHC.Base.Functor (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s) => GHC.Base.Applicative (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s) => GHC.Base.Alternative (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s) => GHC.Base.Monad (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s) => Control.Monad.Fail.MonadFail (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, Control.Monad.IO.Class.MonadIO m) => Control.Monad.IO.Class.MonadIO (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, Control.Monad.Reader.Class.MonadReader r m) => Control.Monad.Reader.Class.MonadReader r (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, Control.Monad.State.Class.MonadState st m) => Control.Monad.State.Class.MonadState st (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, Control.Monad.Cont.Class.MonadCont m) => Control.Monad.Cont.Class.MonadCont (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s, Control.Monad.Error.Class.MonadError e' m) => Control.Monad.Error.Class.MonadError e' (Text.Megaparsec.Prim.ParsecT e s m)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s) => GHC.Base.MonadPlus (Text.Megaparsec.Prim.ParsecT e s m)
instance Control.Monad.Trans.Class.MonadTrans (Text.Megaparsec.Prim.ParsecT e s)
instance (Text.Megaparsec.Error.ErrorComponent e, Text.Megaparsec.Prim.Stream s) => Text.Megaparsec.Prim.MonadParsec e s (Text.Megaparsec.Prim.ParsecT e s m)
instance Text.Megaparsec.Prim.MonadParsec e s m => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.State.Lazy.StateT st m)
instance Text.Megaparsec.Prim.MonadParsec e s m => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.State.Strict.StateT st m)
instance Text.Megaparsec.Prim.MonadParsec e s m => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.Reader.ReaderT r m)
instance (GHC.Base.Monoid w, Text.Megaparsec.Prim.MonadParsec e s m) => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, Text.Megaparsec.Prim.MonadParsec e s m) => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance (GHC.Base.Monoid w, Text.Megaparsec.Prim.MonadParsec e s m) => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.RWS.Lazy.RWST r w st m)
instance (GHC.Base.Monoid w, Text.Megaparsec.Prim.MonadParsec e s m) => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.RWS.Strict.RWST r w st m)
instance Text.Megaparsec.Prim.MonadParsec e s m => Text.Megaparsec.Prim.MonadParsec e s (Control.Monad.Trans.Identity.IdentityT m)


-- | Convenience definitions for working with <a>String</a> as input
--   stream.
module Text.Megaparsec.String

-- | Modules corresponding to various types of streams define <a>Parser</a>
--   accordingly, so the user can use it to easily change type of input
--   stream by importing different “type modules”. This one is for
--   <a>String</a>s.
type Parser = Parsec Dec String


-- | Convenience definitions for working with strict <a>Text</a>.
module Text.Megaparsec.Text

-- | Modules corresponding to various types of streams define <a>Parser</a>
--   accordingly, so the user can use it to easily change type of input
--   stream by importing different “type modules”. This one is for strict
--   <a>Text</a>.
type Parser = Parsec Dec Text


-- | Convenience definitions for working with lazy <a>Text</a>.
module Text.Megaparsec.Text.Lazy

-- | Modules corresponding to various types of streams define <a>Parser</a>
--   accordingly, so the user can use it to easily change type of the input
--   stream by importing different “type modules”. This one is for lazy
--   <a>Text</a>.
type Parser = Parsec Dec Text


-- | Commonly used generic combinators. Note that all the combinators work
--   with <a>Applicative</a> and <a>Alternative</a> instances.
module Text.Megaparsec.Combinator

-- | <tt>between open close p</tt> parses <tt>open</tt>, followed by
--   <tt>p</tt> and <tt>close</tt>. Returns the value returned by
--   <tt>p</tt>.
--   
--   <pre>
--   braces = between (symbol "{") (symbol "}")
--   </pre>
between :: Applicative m => m open -> m close -> m a -> m a

-- | <tt>choice ps</tt> tries to apply the parsers in the list <tt>ps</tt>
--   in order, until one of them succeeds. Returns the value of the
--   succeeding parser.
choice :: (Foldable f, Alternative m) => f (m a) -> m a

-- | <tt>count n p</tt> parses <tt>n</tt> occurrences of <tt>p</tt>. If
--   <tt>n</tt> is smaller or equal to zero, the parser equals to
--   <tt>return []</tt>. Returns a list of <tt>n</tt> values.
count :: Applicative m => Int -> m a -> m [a]

-- | <tt>count' m n p</tt> parses from <tt>m</tt> to <tt>n</tt> occurrences
--   of <tt>p</tt>. If <tt>n</tt> is not positive or <tt>m &gt; n</tt>, the
--   parser equals to <tt>return []</tt>. Returns a list of parsed values.
--   
--   Please note that <tt>m</tt> <i>may</i> be negative, in this case
--   effect is the same as if it were equal to zero.
count' :: Alternative m => Int -> Int -> m a -> m [a]

-- | Combine two alternatives.
eitherP :: Alternative m => m a -> m b -> m (Either a b)

-- | <tt>endBy p sep</tt> parses <i>zero</i> or more occurrences of
--   <tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
--   values returned by <tt>p</tt>.
--   
--   <pre>
--   cStatements = cStatement `endBy` semicolon
--   </pre>
endBy :: Alternative m => m a -> m sep -> m [a]

-- | <tt>endBy1 p sep</tt> parses <i>one</i> or more occurrences of
--   <tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
--   values returned by <tt>p</tt>.
endBy1 :: Alternative m => m a -> m sep -> m [a]

-- | <tt>manyTill p end</tt> applies parser <tt>p</tt> <i>zero</i> or more
--   times until parser <tt>end</tt> succeeds. Returns the list of values
--   returned by <tt>p</tt>. This parser can be used to scan comments:
--   
--   <pre>
--   simpleComment = string "&lt;!--" &gt;&gt; manyTill anyChar (string "--&gt;")
--   </pre>
manyTill :: Alternative m => m a -> m end -> m [a]

-- | <tt>someTill p end</tt> works similarly to <tt>manyTill p end</tt>,
--   but <tt>p</tt> should succeed at least once.
someTill :: Alternative m => m a -> m end -> m [a]

-- | <tt>option x p</tt> tries to apply the parser <tt>p</tt>. If
--   <tt>p</tt> fails without consuming input, it returns the value
--   <tt>x</tt>, otherwise the value returned by <tt>p</tt>.
--   
--   <pre>
--   priority = option 0 (digitToInt &lt;$&gt; digitChar)
--   </pre>
option :: Alternative m => a -> m a -> m a

-- | <tt>sepBy p sep</tt> parses <i>zero</i> or more occurrences of
--   <tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
--   returned by <tt>p</tt>.
--   
--   <pre>
--   commaSep p = p `sepBy` comma
--   </pre>
sepBy :: Alternative m => m a -> m sep -> m [a]

-- | <tt>sepBy1 p sep</tt> parses <i>one</i> or more occurrences of
--   <tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
--   returned by <tt>p</tt>.
sepBy1 :: Alternative m => m a -> m sep -> m [a]

-- | <tt>sepEndBy p sep</tt> parses <i>zero</i> or more occurrences of
--   <tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
--   list of values returned by <tt>p</tt>.
sepEndBy :: Alternative m => m a -> m sep -> m [a]

-- | <tt>sepEndBy1 p sep</tt> parses <i>one</i> or more occurrences of
--   <tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
--   list of values returned by <tt>p</tt>.
sepEndBy1 :: Alternative m => m a -> m sep -> m [a]

-- | <tt>skipMany p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
--   times, skipping its result.
--   
--   <pre>
--   space = skipMany spaceChar
--   </pre>
skipMany :: Alternative m => m a -> m ()

-- | <tt>skipSome p</tt> applies the parser <tt>p</tt> <i>one</i> or more
--   times, skipping its result.
skipSome :: Alternative m => m a -> m ()


-- | A helper module to parse expressions. It can build a parser given a
--   table of operators.
module Text.Megaparsec.Expr

-- | This data type specifies operators that work on values of type
--   <tt>a</tt>. An operator is either binary infix or unary prefix or
--   postfix. A binary operator has also an associated associativity.
data Operator m a

-- | Non-associative infix
InfixN :: (m (a -> a -> a)) -> Operator m a

-- | Left-associative infix
InfixL :: (m (a -> a -> a)) -> Operator m a

-- | Right-associative infix
InfixR :: (m (a -> a -> a)) -> Operator m a

-- | Prefix
Prefix :: (m (a -> a)) -> Operator m a

-- | Postfix
Postfix :: (m (a -> a)) -> Operator m a

-- | <tt>makeExprParser term table</tt> builds an expression parser for
--   terms <tt>term</tt> with operators from <tt>table</tt>, taking the
--   associativity and precedence specified in the <tt>table</tt> into
--   account.
--   
--   <tt>table</tt> is a list of <tt>[Operator m a]</tt> lists. The list is
--   ordered in descending precedence. All operators in one list have the
--   same precedence (but may have different associativity).
--   
--   Prefix and postfix operators of the same precedence associate to the
--   left (i.e. if <tt>++</tt> is postfix increment, than <tt>-2++</tt>
--   equals <tt>-1</tt>, not <tt>-3</tt>).
--   
--   Unary operators of the same precedence can only occur once (i.e.
--   <tt>--2</tt> is not allowed if <tt>-</tt> is prefix negate). If you
--   need to parse several prefix or postfix operators in a row, (like C
--   pointers—<tt>**i</tt>) you can use this approach:
--   
--   <pre>
--   manyUnaryOp = foldr1 (.) &lt;$&gt; some singleUnaryOp
--   </pre>
--   
--   This is not done by default because in some cases allowing repeating
--   prefix or postfix operators is not desirable.
--   
--   If you want to have an operator that is a prefix of another operator
--   in the table, use the following (or similar) wrapper instead of plain
--   <tt>symbol</tt>:
--   
--   <pre>
--   op n = (lexeme . try) (string n &lt;* notFollowedBy punctuationChar)
--   </pre>
--   
--   <tt>makeExprParser</tt> takes care of all the complexity involved in
--   building an expression parser. Here is an example of an expression
--   parser that handles prefix signs, postfix increment and basic
--   arithmetic:
--   
--   <pre>
--   expr = makeExprParser term table &lt;?&gt; "expression"
--   
--   term = parens expr &lt;|&gt; integer &lt;?&gt; "term"
--   
--   table = [ [ prefix  "-"  negate
--             , prefix  "+"  id ]
--           , [ postfix "++" (+1) ]
--           , [ binary  "*"  (*)
--             , binary  "/"  div  ]
--           , [ binary  "+"  (+)
--             , binary  "-"  (-)  ] ]
--   
--   binary  name f = InfixL  (f &lt;$ symbol name)
--   prefix  name f = Prefix  (f &lt;$ symbol name)
--   postfix name f = Postfix (f &lt;$ symbol name)
--   </pre>
makeExprParser :: MonadParsec e s m => m a -> [[Operator m a]] -> m a


-- | This module implements permutation parsers. The algorithm is described
--   in: <i>Parsing Permutation Phrases</i>, by Arthur Baars, Andres Loh
--   and Doaitse Swierstra. Published as a functional pearl at the Haskell
--   Workshop 2001.
module Text.Megaparsec.Perm

-- | The type <tt>PermParser s m a</tt> denotes a permutation parser that,
--   when converted by the <a>makePermParser</a> function, produces
--   instance of <a>MonadParsec</a> <tt>m</tt> that parses <tt>s</tt>
--   stream and returns a value of type <tt>a</tt> on success.
--   
--   Normally, a permutation parser is first build with special operators
--   like (<a>&lt;||&gt;</a>) and than transformed into a normal parser
--   using <a>makePermParser</a>.
data PermParser s m a

-- | The parser <tt>makePermParser perm</tt> parses a permutation of parser
--   described by <tt>perm</tt>. For example, suppose we want to parse a
--   permutation of: an optional string of <tt>a</tt>'s, the character
--   <tt>b</tt> and an optional <tt>c</tt>. This can be described by:
--   
--   <pre>
--   test = makePermParser $
--            (,,) &lt;$?&gt; ("", some (char 'a'))
--                 &lt;||&gt; char 'b'
--                 &lt;|?&gt; ('_', char 'c')
--   </pre>
makePermParser :: MonadParsec e s m => PermParser s m a -> m a

-- | The expression <tt>f &lt;$$&gt; p</tt> creates a fresh permutation
--   parser consisting of parser <tt>p</tt>. The the final result of the
--   permutation parser is the function <tt>f</tt> applied to the return
--   value of <tt>p</tt>. The parser <tt>p</tt> is not allowed to accept
--   empty input—use the optional combinator (<a>&lt;$?&gt;</a>) instead.
--   
--   If the function <tt>f</tt> takes more than one parameter, the type
--   variable <tt>b</tt> is instantiated to a functional type which
--   combines nicely with the adds parser <tt>p</tt> to the
--   (<a>&lt;||&gt;</a>) combinator. This results in stylized code where a
--   permutation parser starts with a combining function <tt>f</tt>
--   followed by the parsers. The function <tt>f</tt> gets its parameters
--   in the order in which the parsers are specified, but actual input can
--   be in any order.
(<$$>) :: MonadParsec e s m => (a -> b) -> m a -> PermParser s m b
infixl 2 <$$>

-- | The expression <tt>f &lt;$?&gt; (x, p)</tt> creates a fresh
--   permutation parser consisting of parser <tt>p</tt>. The final result
--   of the permutation parser is the function <tt>f</tt> applied to the
--   return value of <tt>p</tt>. The parser <tt>p</tt> is optional—if it
--   cannot be applied, the default value <tt>x</tt> will be used instead.
(<$?>) :: MonadParsec e s m => (a -> b) -> (a, m a) -> PermParser s m b
infixl 2 <$?>

-- | The expression <tt>perm &lt;||&gt; p</tt> adds parser <tt>p</tt> to
--   the permutation parser <tt>perm</tt>. The parser <tt>p</tt> is not
--   allowed to accept empty input—use the optional combinator
--   (<a>&lt;|?&gt;</a>) instead. Returns a new permutation parser that
--   includes <tt>p</tt>.
(<||>) :: MonadParsec e s m => PermParser s m (a -> b) -> m a -> PermParser s m b
infixl 1 <||>

-- | The expression <tt>perm &lt;||&gt; (x, p)</tt> adds parser <tt>p</tt>
--   to the permutation parser <tt>perm</tt>. The parser <tt>p</tt> is
--   optional—if it cannot be applied, the default value <tt>x</tt> will be
--   used instead. Returns a new permutation parser that includes the
--   optional parser <tt>p</tt>.
(<|?>) :: MonadParsec e s m => PermParser s m (a -> b) -> (a, m a) -> PermParser s m b
infixl 1 <|?>


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

-- | Parse a newline character.
newline :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a carriage return character followed by a newline character.
--   Return the sequence of characters parsed.
crlf :: (MonadParsec e s m, Token s ~ Char) => m String

-- | Parse a CRLF (see <a>crlf</a>) or LF (see <a>newline</a>) end of line.
--   Return the sequence of characters parsed.
--   
--   <pre>
--   eol = (pure &lt;$&gt; newline) &lt;|&gt; crlf &lt;?&gt; "end of line"
--   </pre>
eol :: (MonadParsec e s m, Token s ~ Char) => m String

-- | Parse a tab character.
tab :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Skip <i>zero</i> or more white space characters.
--   
--   See also: <a>skipMany</a> and <a>spaceChar</a>.
space :: (MonadParsec e s m, Token s ~ Char) => m ()

-- | Parse a control character (a non-printing character of the Latin-1
--   subset of Unicode).
controlChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode space character, and the control characters: tab,
--   newline, carriage return, form feed, and vertical tab.
spaceChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an upper-case or title-case alphabetic Unicode character. Title
--   case is used by a small number of letter ligatures like the
--   single-character form of Lj.
upperChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a lower-case alphabetic Unicode character.
lowerChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an alphabetic Unicode character: lower-case, upper-case, or
--   title-case letter, or a letter of case-less scripts/modifier letter.
letterChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an alphabetic or numeric digit Unicode characters.
--   
--   Note that the numeric digits outside the ASCII range are parsed by
--   this parser but not by <a>digitChar</a>. Such digits may be part of
--   identifiers but are not used by the printer and reader to represent
--   numbers.
alphaNumChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a printable Unicode character: letter, number, mark,
--   punctuation, symbol or space.
printChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an ASCII digit, i.e between “0” and “9”.
digitChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an octal digit, i.e. between “0” and “7”.
octDigitChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a hexadecimal digit, i.e. between “0” and “9”, or “a” and “f”,
--   or “A” and “F”.
hexDigitChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode mark character (accents and the like), which combines
--   with preceding characters.
markChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode numeric character, including digits from various
--   scripts, Roman numerals, etc.
numberChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode punctuation character, including various kinds of
--   connectors, brackets and quotes.
punctuationChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode symbol characters, including mathematical and currency
--   symbols.
symbolChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode space and separator characters.
separatorChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a character from the first 128 characters of the Unicode
--   character set, corresponding to the ASCII character set.
asciiChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a character from the first 256 characters of the Unicode
--   character set, corresponding to the ISO 8859-1 (Latin-1) character
--   set.
latin1Char :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | <tt>charCategory cat</tt> parses character in Unicode General Category
--   <tt>cat</tt>, see <a>GeneralCategory</a>.
charCategory :: (MonadParsec e s m, Token s ~ Char) => GeneralCategory -> m Char

-- | Return the human-readable name of Unicode General Category.
categoryName :: GeneralCategory -> String

-- | <tt>char c</tt> parses a single character <tt>c</tt>.
--   
--   <pre>
--   semicolon = char ';'
--   </pre>
char :: (MonadParsec e s m, Token s ~ Char) => Char -> m Char

-- | The same as <a>char</a> but case-insensitive. This parser returns the
--   actually parsed character preserving its case.
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (char' 'e') "E"
--   'E'
--   
--   &gt;&gt;&gt; parseTest (char' 'e') "G"
--   1:1:
--   unexpected 'G'
--   expecting 'E' or 'e'
--   </pre>
char' :: (MonadParsec e s m, Token s ~ Char) => Char -> m Char

-- | This parser succeeds for any character. Returns the parsed character.
anyChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | <tt>oneOf cs</tt> succeeds if the current character is in the supplied
--   collection of characters <tt>cs</tt>. Returns the parsed character.
--   Note that this parser cannot automatically generate the “expected”
--   component of error message, so usually you should label it manually
--   with <a>label</a> or (<a>&lt;?&gt;</a>).
--   
--   See also: <a>satisfy</a>.
--   
--   <pre>
--   digit = oneOf ['0'..'9'] &lt;?&gt; "digit"
--   </pre>
oneOf :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | The same as <a>oneOf</a>, but case-insensitive. Returns the parsed
--   character preserving its case.
--   
--   <pre>
--   vowel = oneOf' "aeiou" &lt;?&gt; "vowel"
--   </pre>
oneOf' :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | As the dual of <a>oneOf</a>, <tt>noneOf cs</tt> succeeds if the
--   current character <i>not</i> in the supplied list of characters
--   <tt>cs</tt>. Returns the parsed character.
noneOf :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | The same as <a>noneOf</a>, but case-insensitive.
--   
--   <pre>
--   consonant = noneOf' "aeiou" &lt;?&gt; "consonant"
--   </pre>
noneOf' :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | The parser <tt>satisfy f</tt> succeeds for any character for which the
--   supplied function <tt>f</tt> returns <a>True</a>. Returns the
--   character that is actually parsed.
--   
--   <pre>
--   digitChar = satisfy isDigit &lt;?&gt; "digit"
--   oneOf cs  = satisfy (`elem` cs)
--   </pre>
satisfy :: (MonadParsec e s m, Token s ~ Char) => (Char -> Bool) -> m Char

-- | <tt>string s</tt> parses a sequence of characters given by <tt>s</tt>.
--   Returns the parsed string (i.e. <tt>s</tt>).
--   
--   <pre>
--   divOrMod = string "div" &lt;|&gt; string "mod"
--   </pre>
string :: (MonadParsec e s m, Token s ~ Char) => String -> m String

-- | The same as <a>string</a>, but case-insensitive. On success returns
--   string cased as actually parsed input.
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (string' "foobar") "foObAr"
--   "foObAr"
--   </pre>
string' :: (MonadParsec e s m, Token s ~ Char) => String -> m String


-- | High-level parsers to help you write your lexer. The module doesn't
--   impose how you should write your parser, but certain approaches may be
--   more elegant than others. Especially important theme is parsing of
--   white space, comments, and indentation.
--   
--   This module is intended to be imported qualified:
--   
--   <pre>
--   import qualified Text.Megaparsec.Lexer as L
--   </pre>
module Text.Megaparsec.Lexer

-- | <tt>space spaceChar lineComment blockComment</tt> produces parser that
--   can parse white space in general. It's expected that you create such a
--   parser once and pass it to other functions in this module as needed
--   (when you see <tt>spaceConsumer</tt> in documentation, usually it
--   means that something like <a>space</a> is expected there).
--   
--   <tt>spaceChar</tt> is used to parse trivial space characters. You can
--   use <a>spaceChar</a> from <a>Text.Megaparsec.Char</a> for this purpose
--   as well as your own parser (if you don't want to automatically consume
--   newlines, for example).
--   
--   <tt>lineComment</tt> is used to parse line comments. You can use
--   <a>skipLineComment</a> if you don't need anything special.
--   
--   <tt>blockComment</tt> is used to parse block (multi-line) comments.
--   You can use <a>skipBlockComment</a> if you don't need anything
--   special.
--   
--   Parsing of white space is an important part of any parser. We propose
--   a convention where every lexeme parser assumes no spaces before the
--   lexeme and consumes all spaces after the lexeme; this is what the
--   <a>lexeme</a> combinator does, and so it's enough to wrap every lexeme
--   parser with <a>lexeme</a> to achieve this. Note that you'll need to
--   call <a>space</a> manually to consume any white space before the first
--   lexeme (i.e. at the beginning of the file).
space :: MonadParsec e s m => m () -> m () -> m () -> m ()

-- | This is a wrapper for lexemes. Typical usage is to supply the first
--   argument (parser that consumes white space, probably defined via
--   <a>space</a>) and use the resulting function to wrap parsers for every
--   lexeme.
--   
--   <pre>
--   lexeme  = L.lexeme spaceConsumer
--   integer = lexeme L.integer
--   </pre>
lexeme :: MonadParsec e s m => m () -> m a -> m a

-- | This is a helper to parse symbols, i.e. verbatim strings. You pass the
--   first argument (parser that consumes white space, probably defined via
--   <a>space</a>) and then you can use the resulting function to parse
--   strings:
--   
--   <pre>
--   symbol    = L.symbol spaceConsumer
--   
--   parens    = between (symbol "(") (symbol ")")
--   braces    = between (symbol "{") (symbol "}")
--   angles    = between (symbol "&lt;") (symbol "&gt;")
--   brackets  = between (symbol "[") (symbol "]")
--   semicolon = symbol ";"
--   comma     = symbol ","
--   colon     = symbol ":"
--   dot       = symbol "."
--   </pre>
symbol :: (MonadParsec e s m, Token s ~ Char) => m () -> String -> m String

-- | Case-insensitive version of <a>symbol</a>. This may be helpful if
--   you're working with case-insensitive languages.
symbol' :: (MonadParsec e s m, Token s ~ Char) => m () -> String -> m String

-- | Given comment prefix this function returns a parser that skips line
--   comments. Note that it stops just before the newline character but
--   doesn't consume the newline. Newline is either supposed to be consumed
--   by <a>space</a> parser or picked up manually.
skipLineComment :: (MonadParsec e s m, Token s ~ Char) => String -> m ()

-- | <tt>skipBlockComment start end</tt> skips non-nested block comment
--   starting with <tt>start</tt> and ending with <tt>end</tt>.
skipBlockComment :: (MonadParsec e s m, Token s ~ Char) => String -> String -> m ()

-- | <tt>skipBlockCommentNested start end</tt> skips possibly nested block
--   comment starting with <tt>start</tt> and ending with <tt>end</tt>.
skipBlockCommentNested :: (MonadParsec e s m, Token s ~ Char) => String -> String -> m ()

-- | Return the current indentation level.
--   
--   The function is a simple shortcut defined as:
--   
--   <pre>
--   indentLevel = sourceColumn &lt;$&gt; getPosition
--   </pre>
indentLevel :: MonadParsec e s m => m Pos

-- | Fail reporting incorrect indentation error. The error has attached
--   information:
--   
--   <ul>
--   <li>Desired ordering between reference level and actual level</li>
--   <li>Reference indentation level</li>
--   <li>Actual indentation level</li>
--   </ul>
incorrectIndent :: MonadParsec e s m => Ordering -> Pos -> Pos -> m a

-- | <tt>indentGuard spaceConsumer ord ref</tt> first consumes all white
--   space (indentation) with <tt>spaceConsumer</tt> parser, then it checks
--   the column position. Ordering between current indentation level and
--   the reference indentation level <tt>ref</tt> should be <tt>ord</tt>,
--   otherwise the parser fails. On success the current column position is
--   returned.
--   
--   When you want to parse a block of indentation, first run this parser
--   with arguments like <tt>indentGuard spaceConsumer GT (unsafePos
--   1)</tt>—this will make sure you have some indentation. Use returned
--   value to check indentation on every subsequent line according to
--   syntax of your language.
indentGuard :: MonadParsec e s m => m () -> Ordering -> Pos -> m Pos

-- | Parse a non-indented construction. This ensures that there is no
--   indentation before actual data. Useful, for example, as a wrapper for
--   top-level function definitions.
nonIndented :: MonadParsec e s m => m () -> m a -> m a

-- | The data type represents available behaviors for parsing of indented
--   tokens. This is used in <a>indentBlock</a>, which see.
data IndentOpt m a b

-- | Parse no indented tokens, just return the value
IndentNone :: a -> IndentOpt m a b

-- | Parse many indented tokens (possibly zero), use given indentation
--   level (if <a>Nothing</a>, use level of the first indented token); the
--   second argument tells how to get final result, and third argument
--   describes how to parse an indented token
IndentMany :: (Maybe Pos) -> ([b] -> m a) -> (m b) -> IndentOpt m a b

-- | Just like <a>IndentMany</a>, but requires at least one indented token
--   to be present
IndentSome :: (Maybe Pos) -> ([b] -> m a) -> (m b) -> IndentOpt m a b

-- | Parse a “reference” token and a number of other tokens that have
--   greater (but the same) level of indentation than that of “reference”
--   token. Reference token can influence parsing, see <a>IndentOpt</a> for
--   more information.
--   
--   Tokens <i>must not</i> consume newlines after them. On the other hand,
--   the first argument of this function <i>must</i> consume newlines among
--   other white space characters.
indentBlock :: (MonadParsec e s m, Token s ~ Char) => m () -> m (IndentOpt m a b) -> m a

-- | Create a parser that supports line-folding. The first argument is used
--   to consume white space between components of line fold, thus it
--   <i>must</i> consume newlines in order to work properly. The second
--   argument is a callback that receives a custom space-consuming parser
--   as argument. This parser should be used after separate components of
--   line fold that can be put on different lines.
--   
--   An example should clarify the usage pattern:
--   
--   <pre>
--   sc = L.space (void spaceChar) empty empty
--   
--   myFold = L.lineFold sc $ \sc' -&gt; do
--     L.symbol sc' "foo"
--     L.symbol sc' "bar"
--     L.symbol sc  "baz" -- for the last symbol we use normal space consumer
--   </pre>
lineFold :: MonadParsec e s m => m () -> (m () -> m a) -> m a

-- | The lexeme parser parses a single literal character without quotes.
--   The purpose of this parser is to help with parsing of conventional
--   escape sequences. It's your responsibility to take care of character
--   literal syntax in your language (by surrounding it with single quotes
--   or similar).
--   
--   The literal character is parsed according to the grammar rules defined
--   in the Haskell report.
--   
--   Note that you can use this parser as a building block to parse various
--   string literals:
--   
--   <pre>
--   stringLiteral = char '"' &gt;&gt; manyTill L.charLiteral (char '"')
--   </pre>
--   
--   If you want to write <tt>stringLiteral</tt> that adheres to the
--   Haskell report though, you'll need to take care of the <tt>\&amp;</tt>
--   combination which is not a character, but can be used to separate
--   characters (as in <tt>"\291\&amp;4"</tt> which is two characters
--   long):
--   
--   <pre>
--   stringLiteral = catMaybes &lt;$&gt; (char '"' &gt;&gt; manyTill ch (char '"'))
--     where ch = (Just &lt;$&gt; L.charLiteral) &lt;|&gt; (Nothing &lt;$ string "\\&amp;")
--   </pre>
charLiteral :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an integer without sign in decimal representation (according to
--   the format of integer literals described in the Haskell report).
--   
--   If you need to parse signed integers, see <a>signed</a> combinator.
integer :: (MonadParsec e s m, Token s ~ Char) => m Integer

-- | The same as <a>integer</a>, but <a>integer</a> is <a>label</a>ed with
--   “integer” label, while this parser is labeled with “decimal integer”.
decimal :: (MonadParsec e s m, Token s ~ Char) => m Integer

-- | Parse an integer in hexadecimal representation. Representation of
--   hexadecimal number is expected to be according to the Haskell report
--   except for the fact that this parser doesn't parse “0x” or “0X”
--   prefix. It is a responsibility of the programmer to parse correct
--   prefix before parsing the number itself.
--   
--   For example you can make it conform to Haskell report like this:
--   
--   <pre>
--   hexadecimal = char '0' &gt;&gt; char' 'x' &gt;&gt; L.hexadecimal
--   </pre>
hexadecimal :: (MonadParsec e s m, Token s ~ Char) => m Integer

-- | Parse an integer in octal representation. Representation of octal
--   number is expected to be according to the Haskell report except for
--   the fact that this parser doesn't parse “0o” or “0O” prefix. It is a
--   responsibility of the programmer to parse correct prefix before
--   parsing the number itself.
octal :: (MonadParsec e s m, Token s ~ Char) => m Integer

-- | Parse a floating point value as a <a>Scientific</a> number.
--   <a>Scientific</a> is great for parsing of arbitrary precision numbers
--   coming from an untrusted source. See documentation in
--   <a>Data.Scientific</a> for more information. Representation of the
--   floating point value is expected to be according to the Haskell
--   report.
--   
--   This function does not parse sign, if you need to parse signed
--   numbers, see <a>signed</a>.
scientific :: (MonadParsec e s m, Token s ~ Char) => m Scientific

-- | Parse a floating point number without sign. This is a simple shortcut
--   defined as:
--   
--   <pre>
--   float = toRealFloat &lt;$&gt; scientific
--   </pre>
float :: (MonadParsec e s m, Token s ~ Char) => m Double

-- | Parse a number: either integer or floating point. The parser can
--   handle overlapping grammars graciously. Use functions like
--   <a>floatingOrInteger</a> from <a>Data.Scientific</a> to test and
--   extract integer or real values.
number :: (MonadParsec e s m, Token s ~ Char) => m Scientific

-- | <tt>signed space p</tt> parser parses an optional sign, then if there
--   is a sign it will consume optional white space (using <tt>space</tt>
--   parser), then it runs parser <tt>p</tt> which should return a number.
--   Sign of the number is changed according to previously parsed sign.
--   
--   For example, to parse signed integer you can write:
--   
--   <pre>
--   lexeme        = L.lexeme spaceConsumer
--   integer       = lexeme L.integer
--   signedInteger = L.signed spaceConsumer integer
--   </pre>
signed :: (MonadParsec e s m, Token s ~ Char, Num a) => m () -> m a -> m a


-- | Convenience definitions for working with lazy <a>ByteString</a>.
module Text.Megaparsec.ByteString.Lazy

-- | Modules corresponding to various types of streams define <a>Parser</a>
--   accordingly, so the user can use it to easily change the type of input
--   stream by importing different “type modules”. This one is for lazy
--   <a>ByteString</a>s.
type Parser = Parsec Dec ByteString


-- | Convenience definitions for working with strict <a>ByteString</a>.
module Text.Megaparsec.ByteString

-- | Modules corresponding to various types of streams define <a>Parser</a>
--   accordingly, so the user can use it to easily change type of input
--   stream by importing different “type modules”. This one is for strict
--   <a>ByteString</a>s.
type Parser = Parsec Dec ByteString


-- | This module includes everything you need to get started writing a
--   parser. If you are new to Megaparsec and don't know where to begin,
--   take a look at the tutorials
--   <a>https://markkarpov.com/learn-haskell.html#megaparsec-tutorials</a>.
--   
--   By default this module is set up to parse character data. If you'd
--   like to parse the result of your own tokenizer you should start with
--   the following imports:
--   
--   <pre>
--   import Text.Megaparsec.Prim
--   import Text.Megaparsec.Combinator
--   </pre>
--   
--   Then you can implement your own version of <a>satisfy</a> on top of
--   the <a>token</a> primitive, etc.
--   
--   The typical import section looks like this:
--   
--   <pre>
--   import Text.Megaparsec
--   import Text.Megaparsec.String
--   -- import Text.Megaparsec.ByteString
--   -- import Text.Megaparsec.ByteString.Lazy
--   -- import Text.Megaparsec.Text
--   -- import Text.Megaparsec.Text.Lazy
--   </pre>
--   
--   As you can see the second import depends on the data type you want to
--   use as input stream. It just defines the useful type-synonym
--   <tt>Parser</tt>.
--   
--   Megaparsec 5 uses some type-level machinery to provide flexibility
--   without compromising on type safety. Thus type signatures are
--   sometimes necessary to avoid ambiguous types. If you're seeing a error
--   message that reads like “Ambiguous type variable <tt>e0</tt> arising
--   from … prevents the constraint <tt>(ErrorComponent e0)</tt> from being
--   resolved”, you need to give an explicit signature to your parser to
--   resolve the ambiguity. It's a good idea to provide type signatures for
--   all top-level definitions.
--   
--   Megaparsec is capable of a lot. Apart from this standard functionality
--   you can parse permutation phrases with <a>Text.Megaparsec.Perm</a>,
--   expressions with <a>Text.Megaparsec.Expr</a>, and even entire
--   languages with <a>Text.Megaparsec.Lexer</a>. These modules should be
--   imported explicitly along with the two modules mentioned above.
module Text.Megaparsec

-- | <tt>Parsec</tt> is a non-transformer variant of the more general
--   <a>ParsecT</a> monad transformer.
type Parsec e s = ParsecT e s Identity

-- | <tt>ParsecT e s m a</tt> is a parser with custom data component of
--   error <tt>e</tt>, stream type <tt>s</tt>, underlying monad <tt>m</tt>
--   and return type <tt>a</tt>.
data ParsecT e s m a

-- | <tt>parse p file input</tt> runs parser <tt>p</tt> over
--   <a>Identity</a> (see <a>runParserT</a> if you're using the
--   <a>ParsecT</a> monad transformer; <a>parse</a> itself is just a
--   synonym for <a>runParser</a>). It returns either a <a>ParseError</a>
--   (<a>Left</a>) or a value of type <tt>a</tt> (<a>Right</a>).
--   <a>parseErrorPretty</a> can be used to turn <a>ParseError</a> into the
--   string representation of the error message. See
--   <a>Text.Megaparsec.Error</a> if you need to do more advanced error
--   analysis.
--   
--   <pre>
--   main = case (parse numbers "" "11,2,43") of
--            Left err -&gt; putStr (parseErrorPretty err)
--            Right xs -&gt; print (sum xs)
--   
--   numbers = integer `sepBy` char ','
--   </pre>
parse :: Parsec e s a -> String -> s -> Either (ParseError (Token s) e) a

-- | <tt>parseMaybe p input</tt> runs the parser <tt>p</tt> on
--   <tt>input</tt> and returns the result inside <a>Just</a> on success
--   and <a>Nothing</a> on failure. This function also parses <a>eof</a>,
--   so if the parser doesn't consume all of its input, it will fail.
--   
--   The function is supposed to be useful for lightweight parsing, where
--   error messages (and thus file name) are not important and entire input
--   should be parsed. For example it can be used when parsing of a single
--   number according to specification of its format is desired.
parseMaybe :: (ErrorComponent e, Stream s) => Parsec e s a -> s -> Maybe a

-- | The expression <tt>parseTest p input</tt> applies the parser
--   <tt>p</tt> against input <tt>input</tt> and prints the result to
--   stdout. Useful for testing.
parseTest :: (ShowErrorComponent e, Ord (Token s), ShowToken (Token s), Show a) => Parsec e s a -> s -> IO ()

-- | <tt>runParser p file input</tt> runs parser <tt>p</tt> on the input
--   stream of tokens <tt>input</tt>, obtained from source <tt>file</tt>.
--   The <tt>file</tt> is only used in error messages and may be the empty
--   string. Returns either a <a>ParseError</a> (<a>Left</a>) or a value of
--   type <tt>a</tt> (<a>Right</a>).
--   
--   <pre>
--   parseFromFile p file = runParser p file &lt;$&gt; readFile file
--   </pre>
runParser :: Parsec e s a -> String -> s -> Either (ParseError (Token s) e) a

-- | The function is similar to <a>runParser</a> with the difference that
--   it accepts and returns parser state. This allows to specify arbitrary
--   textual position at the beginning of parsing, for example. This is the
--   most general way to run a parser over the <a>Identity</a> monad.
runParser' :: Parsec e s a -> State s -> (State s, Either (ParseError (Token s) e) a)

-- | <tt>runParserT p file input</tt> runs parser <tt>p</tt> on the input
--   list of tokens <tt>input</tt>, obtained from source <tt>file</tt>. The
--   <tt>file</tt> is only used in error messages and may be the empty
--   string. Returns a computation in the underlying monad <tt>m</tt> that
--   returns either a <a>ParseError</a> (<a>Left</a>) or a value of type
--   <tt>a</tt> (<a>Right</a>).
runParserT :: Monad m => ParsecT e s m a -> String -> s -> m (Either (ParseError (Token s) e) a)

-- | This function is similar to <a>runParserT</a>, but like
--   <a>runParser'</a> it accepts and returns parser state. This is thus
--   the most general way to run a parser.
runParserT' :: Monad m => ParsecT e s m a -> State s -> m (State s, Either (ParseError (Token s) e) a)

-- | An associative binary operation
(<|>) :: Alternative f => forall a. f a -> f a -> f a

-- | Zero or more.
many :: Alternative f => forall a. f a -> f [a]

-- | One or more.
some :: Alternative f => forall a. f a -> f [a]

-- | One or none.
optional :: Alternative f => f a -> f (Maybe a)

-- | The parser <tt>unexpected item</tt> fails with an error message
--   telling about unexpected item <tt>item</tt> without consuming any
--   input.
unexpected :: MonadParsec e s m => ErrorItem (Token s) -> m a

-- | Return both the result of a parse and the list of tokens that were
--   consumed during parsing. This relies on the change of the
--   <a>stateTokensProcessed</a> value to evaluate how many tokens were
--   consumed.
match :: MonadParsec e s m => m a -> m ([Token s], a)

-- | Specify how to process <a>ParseError</a>s that happen inside of this
--   wrapper. As a side effect of the current implementation changing
--   <a>errorPos</a> with this combinator will also change the final
--   <a>statePos</a> in the parser state.
region :: MonadParsec e s m => (ParseError (Token s) e -> ParseError (Token s) e) -> m a -> m a

-- | The most general way to stop parsing and report a <a>ParseError</a>.
--   
--   <a>unexpected</a> is defined in terms of this function:
--   
--   <pre>
--   unexpected item = failure (Set.singleton item) Set.empty Set.empty
--   </pre>
failure :: MonadParsec e s m => Set (ErrorItem (Token s)) -> Set (ErrorItem (Token s)) -> Set e -> m a

-- | A synonym for <a>label</a> in the form of an operator.
(<?>) :: MonadParsec e s m => m a -> String -> m a
infix 0 <?>

-- | The parser <tt>label name p</tt> behaves as parser <tt>p</tt>, but
--   whenever the parser <tt>p</tt> fails <i>without consuming any
--   input</i>, it replaces names of “expected” tokens with the name
--   <tt>name</tt>.
label :: MonadParsec e s m => String -> m a -> m a

-- | <tt>hidden p</tt> behaves just like parser <tt>p</tt>, but it doesn't
--   show any “expected” tokens in error message when <tt>p</tt> fails.
hidden :: MonadParsec e s m => m a -> m a

-- | The parser <tt>try p</tt> behaves like parser <tt>p</tt>, except that
--   it backtracks the parser state when <tt>p</tt> fails (either consuming
--   input or not).
--   
--   This combinator is used whenever arbitrary look ahead is needed. Since
--   it pretends that it hasn't consumed any input when <tt>p</tt> fails,
--   the (<a>&lt;|&gt;</a>) combinator will try its second alternative even
--   when the first parser failed while consuming input.
--   
--   For example, here is a parser that is supposed to parse the word “let”
--   or the word “lexical”:
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (string "let" &lt;|&gt; string "lexical") "lexical"
--   1:1:
--   unexpected "lex"
--   expecting "let"
--   </pre>
--   
--   What happens here? The first parser consumes “le” and fails (because
--   it doesn't see a “t”). The second parser, however, isn't tried, since
--   the first parser has already consumed some input! <a>try</a> fixes
--   this behavior and allows backtracking to work:
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (try (string "let") &lt;|&gt; string "lexical") "lexical"
--   "lexical"
--   </pre>
--   
--   <tt>try</tt> also improves error messages in case of overlapping
--   alternatives, because Megaparsec's hint system can be used:
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (try (string "let") &lt;|&gt; string "lexical") "le"
--   1:1:
--   unexpected "le"
--   expecting "let" or "lexical"
--   </pre>
--   
--   <b>Please note</b> that as of Megaparsec 4.4.0, <tt>string</tt>
--   backtracks automatically (see <a>tokens</a>), so it does not need
--   <a>try</a>. However, the examples above demonstrate the idea behind
--   <a>try</a> so well that it was decided to keep them. You still need to
--   use <a>try</a> when your alternatives are complex, composite parsers.
try :: MonadParsec e s m => m a -> m a

-- | If <tt>p</tt> in <tt>lookAhead p</tt> succeeds (either consuming input
--   or not) the whole parser behaves like <tt>p</tt> succeeded without
--   consuming anything (parser state is not updated as well). If
--   <tt>p</tt> fails, <tt>lookAhead</tt> has no effect, i.e. it will fail
--   consuming input if <tt>p</tt> fails consuming input. Combine with
--   <a>try</a> if this is undesirable.
lookAhead :: MonadParsec e s m => m a -> m a

-- | <tt>notFollowedBy p</tt> only succeeds when the parser <tt>p</tt>
--   fails. This parser <i>never consumes</i> any input and <i>never
--   modifies</i> parser state. It can be used to implement the “longest
--   match” rule.
notFollowedBy :: MonadParsec e s m => m a -> m ()

-- | <tt>withRecovery r p</tt> allows continue parsing even if parser
--   <tt>p</tt> fails. In this case <tt>r</tt> is called with the actual
--   <a>ParseError</a> as its argument. Typical usage is to return a value
--   signifying failure to parse this particular object and to consume some
--   part of the input up to the point where the next object starts.
--   
--   Note that if <tt>r</tt> fails, original error message is reported as
--   if without <a>withRecovery</a>. In no way recovering parser <tt>r</tt>
--   can influence error messages.
withRecovery :: MonadParsec e s m => (ParseError (Token s) e -> m a) -> m a -> m a

-- | <tt>observing p</tt> allows to “observe” failure of the <tt>p</tt>
--   parser, should it happen, without actually ending parsing, but instead
--   getting the <a>ParseError</a> in <a>Left</a>. On success parsed value
--   is returned in <a>Right</a> as usual. Note that this primitive just
--   allows you to observe parse errors as they happen, it does not
--   backtrack or change how the <tt>p</tt> parser works in any way.
observing :: MonadParsec e s m => m a -> m (Either (ParseError (Token s) e) a)

-- | This parser only succeeds at the end of the input.
eof :: MonadParsec e s m => m ()

-- | The parser <tt>token test mrep</tt> accepts a token <tt>t</tt> with
--   result <tt>x</tt> when the function <tt>test t</tt> returns
--   <tt><a>Right</a> x</tt>. <tt>mrep</tt> may provide representation of
--   the token to report in error messages when input stream in empty.
--   
--   This is the most primitive combinator for accepting tokens. For
--   example, the <a>satisfy</a> parser is implemented as:
--   
--   <pre>
--   satisfy f = token testChar Nothing
--     where
--       testChar x =
--         if f x
--           then Right x
--           else Left (Set.singleton (Tokens (x:|[])), Set.empty, Set.empty)
--   </pre>
token :: MonadParsec e s m => (Token s -> Either (Set (ErrorItem (Token s)), Set (ErrorItem (Token s)), Set e) a) -> Maybe (Token s) -> m a

-- | The parser <tt>tokens test</tt> parses a list of tokens and returns
--   it. Supplied predicate <tt>test</tt> is used to check equality of
--   given and parsed tokens.
--   
--   This can be used for example to write <a>string</a>:
--   
--   <pre>
--   string = tokens (==)
--   </pre>
--   
--   Note that beginning from Megaparsec 4.4.0, this is an
--   auto-backtracking primitive, which means that if it fails, it never
--   consumes any input. This is done to make its consumption model match
--   how error messages for this primitive are reported (which becomes an
--   important thing as user gets more control with primitives like
--   <a>withRecovery</a>):
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (string "abc") "abd"
--   1:1:
--   unexpected "abd"
--   expecting "abc"
--   </pre>
--   
--   This means, in particular, that it's no longer necessary to use
--   <a>try</a> with <a>tokens</a>-based parsers, such as <a>string</a> and
--   <a>string'</a>. This feature <i>does not</i> affect performance in any
--   way.
tokens :: MonadParsec e s m => (Token s -> Token s -> Bool) -> [Token s] -> m [Token s]

-- | <tt>between open close p</tt> parses <tt>open</tt>, followed by
--   <tt>p</tt> and <tt>close</tt>. Returns the value returned by
--   <tt>p</tt>.
--   
--   <pre>
--   braces = between (symbol "{") (symbol "}")
--   </pre>
between :: Applicative m => m open -> m close -> m a -> m a

-- | <tt>choice ps</tt> tries to apply the parsers in the list <tt>ps</tt>
--   in order, until one of them succeeds. Returns the value of the
--   succeeding parser.
choice :: (Foldable f, Alternative m) => f (m a) -> m a

-- | <tt>count n p</tt> parses <tt>n</tt> occurrences of <tt>p</tt>. If
--   <tt>n</tt> is smaller or equal to zero, the parser equals to
--   <tt>return []</tt>. Returns a list of <tt>n</tt> values.
count :: Applicative m => Int -> m a -> m [a]

-- | <tt>count' m n p</tt> parses from <tt>m</tt> to <tt>n</tt> occurrences
--   of <tt>p</tt>. If <tt>n</tt> is not positive or <tt>m &gt; n</tt>, the
--   parser equals to <tt>return []</tt>. Returns a list of parsed values.
--   
--   Please note that <tt>m</tt> <i>may</i> be negative, in this case
--   effect is the same as if it were equal to zero.
count' :: Alternative m => Int -> Int -> m a -> m [a]

-- | Combine two alternatives.
eitherP :: Alternative m => m a -> m b -> m (Either a b)

-- | <tt>endBy p sep</tt> parses <i>zero</i> or more occurrences of
--   <tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
--   values returned by <tt>p</tt>.
--   
--   <pre>
--   cStatements = cStatement `endBy` semicolon
--   </pre>
endBy :: Alternative m => m a -> m sep -> m [a]

-- | <tt>endBy1 p sep</tt> parses <i>one</i> or more occurrences of
--   <tt>p</tt>, separated and ended by <tt>sep</tt>. Returns a list of
--   values returned by <tt>p</tt>.
endBy1 :: Alternative m => m a -> m sep -> m [a]

-- | <tt>manyTill p end</tt> applies parser <tt>p</tt> <i>zero</i> or more
--   times until parser <tt>end</tt> succeeds. Returns the list of values
--   returned by <tt>p</tt>. This parser can be used to scan comments:
--   
--   <pre>
--   simpleComment = string "&lt;!--" &gt;&gt; manyTill anyChar (string "--&gt;")
--   </pre>
manyTill :: Alternative m => m a -> m end -> m [a]

-- | <tt>someTill p end</tt> works similarly to <tt>manyTill p end</tt>,
--   but <tt>p</tt> should succeed at least once.
someTill :: Alternative m => m a -> m end -> m [a]

-- | <tt>option x p</tt> tries to apply the parser <tt>p</tt>. If
--   <tt>p</tt> fails without consuming input, it returns the value
--   <tt>x</tt>, otherwise the value returned by <tt>p</tt>.
--   
--   <pre>
--   priority = option 0 (digitToInt &lt;$&gt; digitChar)
--   </pre>
option :: Alternative m => a -> m a -> m a

-- | <tt>sepBy p sep</tt> parses <i>zero</i> or more occurrences of
--   <tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
--   returned by <tt>p</tt>.
--   
--   <pre>
--   commaSep p = p `sepBy` comma
--   </pre>
sepBy :: Alternative m => m a -> m sep -> m [a]

-- | <tt>sepBy1 p sep</tt> parses <i>one</i> or more occurrences of
--   <tt>p</tt>, separated by <tt>sep</tt>. Returns a list of values
--   returned by <tt>p</tt>.
sepBy1 :: Alternative m => m a -> m sep -> m [a]

-- | <tt>sepEndBy p sep</tt> parses <i>zero</i> or more occurrences of
--   <tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
--   list of values returned by <tt>p</tt>.
sepEndBy :: Alternative m => m a -> m sep -> m [a]

-- | <tt>sepEndBy1 p sep</tt> parses <i>one</i> or more occurrences of
--   <tt>p</tt>, separated and optionally ended by <tt>sep</tt>. Returns a
--   list of values returned by <tt>p</tt>.
sepEndBy1 :: Alternative m => m a -> m sep -> m [a]

-- | <tt>skipMany p</tt> applies the parser <tt>p</tt> <i>zero</i> or more
--   times, skipping its result.
--   
--   <pre>
--   space = skipMany spaceChar
--   </pre>
skipMany :: Alternative m => m a -> m ()

-- | <tt>skipSome p</tt> applies the parser <tt>p</tt> <i>one</i> or more
--   times, skipping its result.
skipSome :: Alternative m => m a -> m ()

-- | Parse a newline character.
newline :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a carriage return character followed by a newline character.
--   Return the sequence of characters parsed.
crlf :: (MonadParsec e s m, Token s ~ Char) => m String

-- | Parse a CRLF (see <a>crlf</a>) or LF (see <a>newline</a>) end of line.
--   Return the sequence of characters parsed.
--   
--   <pre>
--   eol = (pure &lt;$&gt; newline) &lt;|&gt; crlf &lt;?&gt; "end of line"
--   </pre>
eol :: (MonadParsec e s m, Token s ~ Char) => m String

-- | Parse a tab character.
tab :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Skip <i>zero</i> or more white space characters.
--   
--   See also: <a>skipMany</a> and <a>spaceChar</a>.
space :: (MonadParsec e s m, Token s ~ Char) => m ()

-- | Parse a control character (a non-printing character of the Latin-1
--   subset of Unicode).
controlChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode space character, and the control characters: tab,
--   newline, carriage return, form feed, and vertical tab.
spaceChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an upper-case or title-case alphabetic Unicode character. Title
--   case is used by a small number of letter ligatures like the
--   single-character form of Lj.
upperChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a lower-case alphabetic Unicode character.
lowerChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an alphabetic Unicode character: lower-case, upper-case, or
--   title-case letter, or a letter of case-less scripts/modifier letter.
letterChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an alphabetic or numeric digit Unicode characters.
--   
--   Note that the numeric digits outside the ASCII range are parsed by
--   this parser but not by <a>digitChar</a>. Such digits may be part of
--   identifiers but are not used by the printer and reader to represent
--   numbers.
alphaNumChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a printable Unicode character: letter, number, mark,
--   punctuation, symbol or space.
printChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an ASCII digit, i.e between “0” and “9”.
digitChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse an octal digit, i.e. between “0” and “7”.
octDigitChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a hexadecimal digit, i.e. between “0” and “9”, or “a” and “f”,
--   or “A” and “F”.
hexDigitChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode mark character (accents and the like), which combines
--   with preceding characters.
markChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode numeric character, including digits from various
--   scripts, Roman numerals, etc.
numberChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode punctuation character, including various kinds of
--   connectors, brackets and quotes.
punctuationChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode symbol characters, including mathematical and currency
--   symbols.
symbolChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a Unicode space and separator characters.
separatorChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a character from the first 128 characters of the Unicode
--   character set, corresponding to the ASCII character set.
asciiChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | Parse a character from the first 256 characters of the Unicode
--   character set, corresponding to the ISO 8859-1 (Latin-1) character
--   set.
latin1Char :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | <tt>charCategory cat</tt> parses character in Unicode General Category
--   <tt>cat</tt>, see <a>GeneralCategory</a>.
charCategory :: (MonadParsec e s m, Token s ~ Char) => GeneralCategory -> m Char

-- | <tt>char c</tt> parses a single character <tt>c</tt>.
--   
--   <pre>
--   semicolon = char ';'
--   </pre>
char :: (MonadParsec e s m, Token s ~ Char) => Char -> m Char

-- | The same as <a>char</a> but case-insensitive. This parser returns the
--   actually parsed character preserving its case.
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (char' 'e') "E"
--   'E'
--   
--   &gt;&gt;&gt; parseTest (char' 'e') "G"
--   1:1:
--   unexpected 'G'
--   expecting 'E' or 'e'
--   </pre>
char' :: (MonadParsec e s m, Token s ~ Char) => Char -> m Char

-- | This parser succeeds for any character. Returns the parsed character.
anyChar :: (MonadParsec e s m, Token s ~ Char) => m Char

-- | <tt>oneOf cs</tt> succeeds if the current character is in the supplied
--   collection of characters <tt>cs</tt>. Returns the parsed character.
--   Note that this parser cannot automatically generate the “expected”
--   component of error message, so usually you should label it manually
--   with <a>label</a> or (<a>&lt;?&gt;</a>).
--   
--   See also: <a>satisfy</a>.
--   
--   <pre>
--   digit = oneOf ['0'..'9'] &lt;?&gt; "digit"
--   </pre>
oneOf :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | The same as <a>oneOf</a>, but case-insensitive. Returns the parsed
--   character preserving its case.
--   
--   <pre>
--   vowel = oneOf' "aeiou" &lt;?&gt; "vowel"
--   </pre>
oneOf' :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | As the dual of <a>oneOf</a>, <tt>noneOf cs</tt> succeeds if the
--   current character <i>not</i> in the supplied list of characters
--   <tt>cs</tt>. Returns the parsed character.
noneOf :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | The same as <a>noneOf</a>, but case-insensitive.
--   
--   <pre>
--   consonant = noneOf' "aeiou" &lt;?&gt; "consonant"
--   </pre>
noneOf' :: (Foldable f, MonadParsec e s m, Token s ~ Char) => f Char -> m Char

-- | The parser <tt>satisfy f</tt> succeeds for any character for which the
--   supplied function <tt>f</tt> returns <a>True</a>. Returns the
--   character that is actually parsed.
--   
--   <pre>
--   digitChar = satisfy isDigit &lt;?&gt; "digit"
--   oneOf cs  = satisfy (`elem` cs)
--   </pre>
satisfy :: (MonadParsec e s m, Token s ~ Char) => (Char -> Bool) -> m Char

-- | <tt>string s</tt> parses a sequence of characters given by <tt>s</tt>.
--   Returns the parsed string (i.e. <tt>s</tt>).
--   
--   <pre>
--   divOrMod = string "div" &lt;|&gt; string "mod"
--   </pre>
string :: (MonadParsec e s m, Token s ~ Char) => String -> m String

-- | The same as <a>string</a>, but case-insensitive. On success returns
--   string cased as actually parsed input.
--   
--   <pre>
--   &gt;&gt;&gt; parseTest (string' "foobar") "foObAr"
--   "foObAr"
--   </pre>
string' :: (MonadParsec e s m, Token s ~ Char) => String -> m String

-- | Positive integer that is used to represent line number, column number,
--   and similar things like indentation level. <a>Semigroup</a> instance
--   can be used to safely and purely add <a>Pos</a>es together.
data Pos

-- | Construction of <a>Pos</a> from an instance of <a>Integral</a>. The
--   function throws <a>InvalidPosException</a> when given non-positive
--   argument. Note that the function is polymorphic with respect to
--   <a>MonadThrow</a> <tt>m</tt>, so you can get result inside of
--   <a>Maybe</a>, for example.
mkPos :: (Integral a, MonadThrow m) => a -> m Pos

-- | Extract <a>Word</a> from <a>Pos</a>.
unPos :: Pos -> Word

-- | Dangerous construction of <a>Pos</a>. Use when you know for sure that
--   argument is positive.
unsafePos :: Word -> Pos

-- | The exception is thrown by <a>mkPos</a> when its argument is not a
--   positive number.
data InvalidPosException
InvalidPosException :: InvalidPosException

-- | The data type <tt>SourcePos</tt> represents source positions. It
--   contains the name of the source file, a line number, and a column
--   number. Source line and column positions change intensively during
--   parsing, so we need to make them strict to avoid memory leaks.
data SourcePos
SourcePos :: FilePath -> !Pos -> !Pos -> SourcePos

-- | Name of source file
[sourceName] :: SourcePos -> FilePath

-- | Line number
[sourceLine] :: SourcePos -> !Pos

-- | Column number
[sourceColumn] :: SourcePos -> !Pos

-- | Construct initial position (line 1, column 1) given name of source
--   file.
initialPos :: String -> SourcePos

-- | Pretty-print a <a>SourcePos</a>.
sourcePosPretty :: SourcePos -> String

-- | Data type that is used to represent “unexpected/expected” items in
--   <a>ParseError</a>. The data type is parametrized over the token type
--   <tt>t</tt>.
data ErrorItem t

-- | Non-empty stream of tokens
Tokens :: (NonEmpty t) -> ErrorItem t

-- | Label (cannot be empty)
Label :: (NonEmpty Char) -> ErrorItem t

-- | End of input
EndOfInput :: ErrorItem t

-- | The type class defines how to represent information about various
--   exceptional situations. Data types that are used as custom data
--   component in <a>ParseError</a> must be instances of this type class.
class Ord e => ErrorComponent e

-- | Represent the message passed to <a>fail</a> in parser monad.
representFail :: ErrorComponent e => String -> e

-- | Represent information about incorrect indentation.
representIndentation :: ErrorComponent e => Ordering -> Pos -> Pos -> e

-- | “Default error component”. This is our instance of
--   <a>ErrorComponent</a> provided out-of-box.
data Dec

-- | <a>fail</a> has been used in parser monad
DecFail :: String -> Dec

-- | Incorrect indentation error: desired ordering between reference level
--   and actual level, reference indentation level, actual indentation
--   level
DecIndentation :: Ordering -> Pos -> Pos -> Dec

-- | <a>ParseError</a> represents… parse errors. It provides the stack of
--   source positions, a set of expected and unexpected tokens as well as a
--   set of custom associated data. The data type is parametrized over the
--   token type <tt>t</tt> and the custom data <tt>e</tt>.
--   
--   Note that the stack of source positions contains current position as
--   its head, and the rest of positions allows to track full sequence of
--   include files with topmost source file at the end of the list.
--   
--   <a>Semigroup</a> (and <a>Monoid</a>) instance of the data type allows
--   to merge parse errors from different branches of parsing. When merging
--   two <a>ParseError</a>s, the longest match is preferred; if positions
--   are the same, custom data sets and collections of message items are
--   combined.
data ParseError t e
ParseError :: NonEmpty SourcePos -> Set (ErrorItem t) -> Set (ErrorItem t) -> Set e -> ParseError t e

-- | Stack of source positions
[errorPos] :: ParseError t e -> NonEmpty SourcePos

-- | Unexpected items
[errorUnexpected] :: ParseError t e -> Set (ErrorItem t)

-- | Expected items
[errorExpected] :: ParseError t e -> Set (ErrorItem t)

-- | Associated data, if any
[errorCustom] :: ParseError t e -> Set e

-- | Type class <a>ShowToken</a> includes methods that allow to
--   pretty-print single token as well as stream of tokens. This is used
--   for rendering of error messages.
class ShowToken a

-- | Pretty-print non-empty stream of tokens. This function is also used to
--   print single tokens (represented as singleton lists).
showTokens :: ShowToken a => NonEmpty a -> String

-- | The type class defines how to print custom data component of
--   <a>ParseError</a>.
class Ord a => ShowErrorComponent a

-- | Pretty-print custom data component of <a>ParseError</a>.
showErrorComponent :: ShowErrorComponent a => a -> String

-- | Pretty-print a <a>ParseError</a>. The rendered <a>String</a> always
--   ends with a newline.
--   
--   The function is defined as:
--   
--   <pre>
--   parseErrorPretty e =
--     sourcePosStackPretty (errorPos e) ++ ":\n" ++ parseErrorTextPretty e
--   </pre>
parseErrorPretty :: (Ord t, ShowToken t, ShowErrorComponent e) => ParseError t e -> String

-- | <tt>dbg label p</tt> parser works exactly like <tt>p</tt>, but when
--   it's evaluated it also prints information useful for debugging. The
--   <tt>label</tt> is only used to refer to this parser in the debugging
--   output. This combinator uses the <a>trace</a> function from
--   <a>Debug.Trace</a> under the hood.
--   
--   Typical usage is to wrap every sub-parser in misbehaving parser with
--   <a>dbg</a> assigning meaningful labels. Then give it a shot and go
--   through the print-out. As of current version, this combinator prints
--   all available information except for <i>hints</i>, which are probably
--   only interesting to the maintainer of Megaparsec itself and may be
--   quite verbose to output in general. Let me know if you would like to
--   be able to see hints in the debugging output.
--   
--   The output itself is pretty self-explanatory, although the following
--   abbreviations should be clarified (they are derived from the low-level
--   source code):
--   
--   <ul>
--   <li><tt>COK</tt>—“consumed OK”. The parser consumed input and
--   succeeded.</li>
--   <li><tt>CERR</tt>—“consumed error”. The parser consumed input and
--   failed.</li>
--   <li><tt>EOK</tt>—“empty OK”. The parser succeeded without consuming
--   input.</li>
--   <li><tt>EERR</tt>—“empty error”. The parser failed without consuming
--   input.</li>
--   </ul>
--   
--   Finally, it's not possible to lift this function into some monad
--   transformers without introducing surprising behavior (e.g. unexpected
--   state backtracking) or adding otherwise redundant constraints (e.g.
--   <a>Show</a> instance for state), so this helper is only available for
--   <a>ParsecT</a> monad, not <a>MonadParsec</a> in general.
dbg :: forall e s m a. (Stream s, ShowToken (Token s), ShowErrorComponent e, Show a) => String -> ParsecT e s m a -> ParsecT e s m a

-- | An instance of <tt>Stream s</tt> has stream type <tt>s</tt>. Token
--   type is determined by the stream and can be found via <a>Token</a>
--   type function.
class Ord (Token s) => Stream s where type Token s :: * where {
    type family Token s :: *;
}

-- | Get next token from the stream. If the stream is empty, return
--   <a>Nothing</a>.
uncons :: Stream s => s -> Maybe (Token s, s)

-- | Update position in stream given tab width, current position, and
--   current token. The result is a tuple where the first element will be
--   used to report parse errors for current token, while the second
--   element is the incremented position that will be stored in the
--   parser's state. The stored (incremented) position is used whenever
--   position can't be/shouldn't be updated by consuming a token. For
--   example, when using <a>failure</a>, we don't grab a new token (we need
--   to fail right were we are now), so error position will be taken from
--   parser's state.
--   
--   When you work with streams where elements do not contain information
--   about their position in input, the result is usually consists of the
--   third argument unchanged and incremented position calculated with
--   respect to current token. This is how default instances of
--   <a>Stream</a> work (they use <a>defaultUpdatePos</a>, which may be a
--   good starting point for your own position-advancing function).
--   
--   When you wish to deal with a stream of tokens where every token
--   “knows” its start and end position in input (for example, you have
--   produced the stream with Happy/Alex), then the best strategy is to use
--   the start position as the actual element position and provide the end
--   position of the token as the incremented one.
updatePos :: Stream s => Proxy s -> Pos -> SourcePos -> Token s -> (SourcePos, SourcePos)

-- | This is the Megaparsec's state, it's parametrized over stream type
--   <tt>s</tt>.
data State s
State :: s -> NonEmpty SourcePos -> {-# UNPACK #-} !Word -> Pos -> State s

-- | Current input (already processed input is removed from the stream)
[stateInput] :: State s -> s

-- | Current position (column + line number) with support for include files
[statePos] :: State s -> NonEmpty SourcePos

-- | Number of processed tokens so far
[stateTokensProcessed] :: State s -> {-# UNPACK #-} !Word

-- | Tab width to use
[stateTabWidth] :: State s -> Pos

-- | Return the current input.
getInput :: MonadParsec e s m => m s

-- | <tt>setInput input</tt> continues parsing with <tt>input</tt>. The
--   <a>getInput</a> and <a>setInput</a> functions can for example be used
--   to deal with include files.
setInput :: MonadParsec e s m => s -> m ()

-- | Return the current source position.
--   
--   See also: <a>setPosition</a>, <a>pushPosition</a>, <a>popPosition</a>,
--   and <a>SourcePos</a>.
getPosition :: MonadParsec e s m => m SourcePos

-- | Get the position where the next token in the stream begins. If the
--   stream is empty, return <a>Nothing</a>.
getNextTokenPosition :: forall e s m. MonadParsec e s m => m (Maybe SourcePos)

-- | <tt>setPosition pos</tt> sets the current source position to
--   <tt>pos</tt>.
--   
--   See also: <a>getPosition</a>, <a>pushPosition</a>, <a>popPosition</a>,
--   and <a>SourcePos</a>.
setPosition :: MonadParsec e s m => SourcePos -> m ()

-- | Push a position into stack of positions and continue parsing working
--   with this position. Useful for working with include files and the
--   like.
--   
--   See also: <a>getPosition</a>, <a>setPosition</a>, <a>popPosition</a>,
--   and <a>SourcePos</a>.
pushPosition :: MonadParsec e s m => SourcePos -> m ()

-- | Pop a position from the stack of positions unless it only contains one
--   element (in that case the stack of positions remains the same). This
--   is how to return to previous source file after <a>pushPosition</a>.
--   
--   See also: <a>getPosition</a>, <a>setPosition</a>, <a>pushPosition</a>,
--   and <a>SourcePos</a>.
popPosition :: MonadParsec e s m => m ()

-- | Get the number of tokens processed so far.
getTokensProcessed :: MonadParsec e s m => m Word

-- | Set the number of tokens processed so far.
setTokensProcessed :: MonadParsec e s m => Word -> m ()

-- | Return the tab width. The default tab width is equal to
--   <a>defaultTabWidth</a>. You can set a different tab width with the
--   help of <a>setTabWidth</a>.
getTabWidth :: MonadParsec e s m => m Pos

-- | Set tab width. If the argument of the function is not a positive
--   number, <a>defaultTabWidth</a> will be used.
setTabWidth :: MonadParsec e s m => Pos -> m ()

-- | Return the full parser state as a <a>State</a> record.
getParserState :: MonadParsec e s m => m (State s)

-- | <tt>setParserState st</tt> sets the parser state to <tt>st</tt>.
setParserState :: MonadParsec e s m => State s -> m ()

-- | <tt>updateParserState f</tt> applies the function <tt>f</tt> to the
--   parser state.
updateParserState :: MonadParsec e s m => (State s -> State s) -> m ()
