{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolymorphicComponents #-}
{-# LANGUAGE Safe #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Parsec.Token
-- Copyright   :  (c) Daan Leijen 1999-2001, (c) Paolo Martini 2007
-- License     :  BSD-style (see the LICENSE file)
--
-- Maintainer  :  derek.a.elkins@gmail.com
-- Stability   :  provisional
-- Portability :  non-portable (uses local universal quantification: PolymorphicComponents)
--
-- A helper module to parse lexical elements (tokens). See 'makeTokenParser'
-- for a description of how to use it.
--
-----------------------------------------------------------------------------

{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

module Text.Parsec.Token
    ( LanguageDef
    , GenLanguageDef (..)
    , TokenParser
    , GenTokenParser (..)
    , makeTokenParser
    ) where

import Data.Char ( isAlpha, toLower, toUpper, isSpace, digitToInt )
#if MIN_VERSION_base(4,7,0)
import Data.Typeable ( Typeable )
#endif
import Data.List ( nub, sort )
import Control.Monad.Identity (Identity)

import Text.Parsec.Prim
import Text.Parsec.Char
import Text.Parsec.Combinator

-----------------------------------------------------------
-- Language Definition
-----------------------------------------------------------

type LanguageDef st = GenLanguageDef String st Identity

-- | The @GenLanguageDef@ type is a record that contains all parameterizable
-- features of the "Text.Parsec.Token" module. The module "Text.Parsec.Language"
-- contains some default definitions.

data GenLanguageDef s u m
    = LanguageDef {

    -- | Describes the start of a block comment. Use the empty string if the
    -- language doesn't support block comments. For example \"\/*\".

    forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentStart   :: String,

    -- | Describes the end of a block comment. Use the empty string if the
    -- language doesn't support block comments. For example \"*\/\".

    forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentEnd     :: String,

    -- | Describes the start of a line comment. Use the empty string if the
    -- language doesn't support line comments. For example \"\/\/\".

    forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentLine    :: String,

    -- | Set to 'True' if the language supports nested block comments.

    forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
nestedComments :: Bool,

    -- | This parser should accept any start characters of identifiers. For
    -- example @letter \<|> char \'_\'@.

    forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identStart     :: ParsecT s u m Char,

    -- | This parser should accept any legal tail characters of identifiers.
    -- For example @alphaNum \<|> char \'_\'@.

    forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identLetter    :: ParsecT s u m Char,

    -- | This parser should accept any start characters of operators. For
    -- example @oneOf \":!#$%&*+.\/\<=>?\@\\\\^|-~\"@

    forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opStart        :: ParsecT s u m Char,

    -- | This parser should accept any legal tail characters of operators.
    -- Note that this parser should even be defined if the language doesn't
    -- support user-defined operators, or otherwise the 'reservedOp'
    -- parser won't work correctly.

    forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opLetter       :: ParsecT s u m Char,

    -- | The list of reserved identifiers.

    forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedNames  :: [String],

    -- | The list of reserved operators.

    forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedOpNames:: [String],

    -- | Set to 'True' if the language is case sensitive.

    forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
caseSensitive  :: Bool

    }
#if MIN_VERSION_base(4,7,0)
    deriving ( Typeable )
#endif

-----------------------------------------------------------
-- A first class module: TokenParser
-----------------------------------------------------------

type TokenParser st = GenTokenParser String st Identity

-- | The type of the record that holds lexical parsers that work on
-- @s@ streams with state @u@ over a monad @m@.

data GenTokenParser s u m
    = TokenParser {

        -- | This lexeme parser parses a legal identifier. Returns the identifier
        -- string. This parser will fail on identifiers that are reserved
        -- words. Legal identifier (start) characters and reserved words are
        -- defined in the 'LanguageDef' that is passed to
        -- 'makeTokenParser'. An @identifier@ is treated as
        -- a single token using 'try'.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
identifier       :: ParsecT s u m String,

        -- | The lexeme parser @reserved name@ parses @symbol
        -- name@, but it also checks that the @name@ is not a prefix of a
        -- valid identifier. A @reserved@ word is treated as a single token
        -- using 'try'.

        forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
reserved         :: String -> ParsecT s u m (),

        -- | This lexeme parser parses a legal operator. Returns the name of the
        -- operator. This parser will fail on any operators that are reserved
        -- operators. Legal operator (start) characters and reserved operators
        -- are defined in the 'LanguageDef' that is passed to
        -- 'makeTokenParser'. An @operator@ is treated as a
        -- single token using 'try'.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
operator         :: ParsecT s u m String,

        -- |The lexeme parser @reservedOp name@ parses @symbol
        -- name@, but it also checks that the @name@ is not a prefix of a
        -- valid operator. A @reservedOp@ is treated as a single token using
        -- 'try'.

        forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
reservedOp       :: String -> ParsecT s u m (),


        -- | This lexeme parser parses a single literal character. Returns the
        -- literal character value. This parsers deals correctly with escape
        -- sequences. The literal character is parsed according to the grammar
        -- rules defined in the Haskell report (which matches most programming
        -- languages quite closely).

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Char
charLiteral      :: ParsecT s u m Char,

        -- | This lexeme parser parses a literal string. Returns the literal
        -- string value. This parsers deals correctly with escape sequences and
        -- gaps. The literal string is parsed according to the grammar rules
        -- defined in the Haskell report (which matches most programming
        -- languages quite closely).

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
stringLiteral    :: ParsecT s u m String,

        -- | This lexeme parser parses a natural number (a non-negative whole
        -- number). Returns the value of the number. The number can be
        -- specified in 'decimal', 'hexadecimal' or
        -- 'octal'. The number is parsed according to the grammar
        -- rules in the Haskell report.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
natural          :: ParsecT s u m Integer,

        -- | This lexeme parser parses an integer (a whole number). This parser
        -- is like 'natural' except that it can be prefixed with
        -- sign (i.e. \'-\' or \'+\'). Returns the value of the number. The
        -- number can be specified in 'decimal', 'hexadecimal'
        -- or 'octal'. The number is parsed according
        -- to the grammar rules in the Haskell report.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
integer          :: ParsecT s u m Integer,

        -- | This lexeme parser parses a floating point value. Returns the value
        -- of the number. The number is parsed according to the grammar rules
        -- defined in the Haskell report.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Double
float            :: ParsecT s u m Double,

        -- | This lexeme parser parses either 'natural' or a 'float'.
        -- Returns the value of the number. This parsers deals with
        -- any overlap in the grammar rules for naturals and floats. The number
        -- is parsed according to the grammar rules defined in the Haskell report.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m (Either Integer Double)
naturalOrFloat   :: ParsecT s u m (Either Integer Double),

        -- | Parses a non-negative whole number in the decimal system. Returns the
        -- value of the number.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
decimal          :: ParsecT s u m Integer,

        -- | Parses a non-negative whole number in the hexadecimal system. The
        -- number should be prefixed with \"x\" or \"X\". Returns the value of the
        -- number.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
hexadecimal      :: ParsecT s u m Integer,

        -- | Parses a non-negative whole number in the octal system. The number
        -- should be prefixed with \"o\" or \"O\". Returns the value of the
        -- number.

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
octal            :: ParsecT s u m Integer,

        -- | Lexeme parser @symbol s@ parses 'string' @s@ and skips
        -- trailing white space.

        forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m String
symbol           :: String -> ParsecT s u m String,

        -- | @lexeme p@ first applies parser @p@ and then the 'whiteSpace'
        -- parser, returning the value of @p@. Every lexical
        -- token (lexeme) is defined using @lexeme@, this way every parse
        -- starts at a point without white space. Parsers that use @lexeme@ are
        -- called /lexeme/ parsers in this document.
        --
        -- The only point where the 'whiteSpace' parser should be
        -- called explicitly is the start of the main parser in order to skip
        -- any leading white space.
        --
        -- >    mainParser  = do{ whiteSpace
        -- >                     ; ds <- many (lexeme digit)
        -- >                     ; eof
        -- >                     ; return (sum ds)
        -- >                     }

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
lexeme           :: forall a. ParsecT s u m a -> ParsecT s u m a,

        -- | Parses any white space. White space consists of /zero/ or more
        -- occurrences of a 'space', a line comment or a block (multi
        -- line) comment. Block comments may be nested. How comments are
        -- started and ended is defined in the 'LanguageDef'
        -- that is passed to 'makeTokenParser'.

        forall s u (m :: * -> *). GenTokenParser s u m -> ParsecT s u m ()
whiteSpace       :: ParsecT s u m (),

        -- | Lexeme parser @parens p@ parses @p@ enclosed in parenthesis,
        -- returning the value of @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
parens           :: forall a. ParsecT s u m a -> ParsecT s u m a,

        -- | Lexeme parser @braces p@ parses @p@ enclosed in braces (\'{\' and
        -- \'}\'), returning the value of @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
braces           :: forall a. ParsecT s u m a -> ParsecT s u m a,

        -- | Lexeme parser @angles p@ parses @p@ enclosed in angle brackets (\'\<\'
        -- and \'>\'), returning the value of @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
angles           :: forall a. ParsecT s u m a -> ParsecT s u m a,

        -- | Lexeme parser @brackets p@ parses @p@ enclosed in brackets (\'[\'
        -- and \']\'), returning the value of @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
brackets         :: forall a. ParsecT s u m a -> ParsecT s u m a,

        -- | DEPRECATED: Use 'brackets'.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m a
squares          :: forall a. ParsecT s u m a -> ParsecT s u m a,

        -- | Lexeme parser |semi| parses the character \';\' and skips any
        -- trailing white space. Returns the string \";\".

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
semi             :: ParsecT s u m String,

        -- | Lexeme parser @comma@ parses the character \',\' and skips any
        -- trailing white space. Returns the string \",\".

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
comma            :: ParsecT s u m String,

        -- | Lexeme parser @colon@ parses the character \':\' and skips any
        -- trailing white space. Returns the string \":\".

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
colon            :: ParsecT s u m String,

        -- | Lexeme parser @dot@ parses the character \'.\' and skips any
        -- trailing white space. Returns the string \".\".

        forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
dot              :: ParsecT s u m String,

        -- | Lexeme parser @semiSep p@ parses /zero/ or more occurrences of @p@
        -- separated by 'semi'. Returns a list of values returned by
        -- @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m [a]
semiSep          :: forall a . ParsecT s u m a -> ParsecT s u m [a],

        -- | Lexeme parser @semiSep1 p@ parses /one/ or more occurrences of @p@
        -- separated by 'semi'. Returns a list of values returned by @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m [a]
semiSep1         :: forall a . ParsecT s u m a -> ParsecT s u m [a],

        -- | Lexeme parser @commaSep p@ parses /zero/ or more occurrences of
        -- @p@ separated by 'comma'. Returns a list of values returned
        -- by @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m [a]
commaSep         :: forall a . ParsecT s u m a -> ParsecT s u m [a],

        -- | Lexeme parser @commaSep1 p@ parses /one/ or more occurrences of
        -- @p@ separated by 'comma'. Returns a list of values returned
        -- by @p@.

        forall s u (m :: * -> *).
GenTokenParser s u m
-> forall a. ParsecT s u m a -> ParsecT s u m [a]
commaSep1        :: forall a . ParsecT s u m a -> ParsecT s u m [a]
    }
#if MIN_VERSION_base(4,7,0)
    deriving ( Typeable )
#endif

-----------------------------------------------------------
-- Given a LanguageDef, create a token parser.
-----------------------------------------------------------

-- | The expression @makeTokenParser language@ creates a 'GenTokenParser'
-- record that contains lexical parsers that are
-- defined using the definitions in the @language@ record.
--
-- The use of this function is quite stylized - one imports the
-- appropriate language definition and selects the lexical parsers that
-- are needed from the resulting 'GenTokenParser'.
--
-- >  module Main where
-- >
-- >  import Text.Parsec
-- >  import qualified Text.Parsec.Token as P
-- >  import Text.Parsec.Language (haskellDef)
-- >
-- >  -- The parser
-- >  ...
-- >
-- >  expr  =   parens expr
-- >        <|> identifier
-- >        <|> ...
-- >
-- >
-- >  -- The lexer
-- >  lexer       = P.makeTokenParser haskellDef
-- >
-- >  parens      = P.parens lexer
-- >  braces      = P.braces lexer
-- >  identifier  = P.identifier lexer
-- >  reserved    = P.reserved lexer
-- >  ...

makeTokenParser :: (Stream s m Char)
                => GenLanguageDef s u m -> GenTokenParser s u m
{-# INLINABLE makeTokenParser #-}
makeTokenParser :: forall s (m :: * -> *) u.
Stream s m Char =>
GenLanguageDef s u m -> GenTokenParser s u m
makeTokenParser GenLanguageDef s u m
languageDef
    = TokenParser{ identifier :: ParsecT s u m String
identifier = ParsecT s u m String
identifier
                 , reserved :: String -> ParsecT s u m ()
reserved = String -> ParsecT s u m ()
reserved
                 , operator :: ParsecT s u m String
operator = ParsecT s u m String
operator
                 , reservedOp :: String -> ParsecT s u m ()
reservedOp = String -> ParsecT s u m ()
reservedOp

                 , charLiteral :: ParsecT s u m Char
charLiteral = forall {u}. ParsecT s u m Char
charLiteral
                 , stringLiteral :: ParsecT s u m String
stringLiteral = forall {u}. ParsecT s u m String
stringLiteral
                 , natural :: ParsecT s u m Integer
natural = forall {u}. ParsecT s u m Integer
natural
                 , integer :: ParsecT s u m Integer
integer = forall {u}. ParsecT s u m Integer
integer
                 , float :: ParsecT s u m Double
float = forall {u}. ParsecT s u m Double
float
                 , naturalOrFloat :: ParsecT s u m (Either Integer Double)
naturalOrFloat = forall {u}. ParsecT s u m (Either Integer Double)
naturalOrFloat
                 , decimal :: ParsecT s u m Integer
decimal = forall {u}. ParsecT s u m Integer
decimal
                 , hexadecimal :: ParsecT s u m Integer
hexadecimal = forall {u}. ParsecT s u m Integer
hexadecimal
                 , octal :: ParsecT s u m Integer
octal = forall {u}. ParsecT s u m Integer
octal

                 , symbol :: String -> ParsecT s u m String
symbol = forall {u}. String -> ParsecT s u m String
symbol
                 , lexeme :: forall a. ParsecT s u m a -> ParsecT s u m a
lexeme = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme
                 , whiteSpace :: ParsecT s u m ()
whiteSpace = forall {u}. ParsecT s u m ()
whiteSpace

                 , parens :: forall a. ParsecT s u m a -> ParsecT s u m a
parens = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
parens
                 , braces :: forall a. ParsecT s u m a -> ParsecT s u m a
braces = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
braces
                 , angles :: forall a. ParsecT s u m a -> ParsecT s u m a
angles = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
angles
                 , brackets :: forall a. ParsecT s u m a -> ParsecT s u m a
brackets = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
brackets
                 , squares :: forall a. ParsecT s u m a -> ParsecT s u m a
squares = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
brackets
                 , semi :: ParsecT s u m String
semi = forall {u}. ParsecT s u m String
semi
                 , comma :: ParsecT s u m String
comma = forall {u}. ParsecT s u m String
comma
                 , colon :: ParsecT s u m String
colon = forall {u}. ParsecT s u m String
colon
                 , dot :: ParsecT s u m String
dot = forall {u}. ParsecT s u m String
dot
                 , semiSep :: forall a. ParsecT s u m a -> ParsecT s u m [a]
semiSep = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
semiSep
                 , semiSep1 :: forall a. ParsecT s u m a -> ParsecT s u m [a]
semiSep1 = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
semiSep1
                 , commaSep :: forall a. ParsecT s u m a -> ParsecT s u m [a]
commaSep = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
commaSep
                 , commaSep1 :: forall a. ParsecT s u m a -> ParsecT s u m [a]
commaSep1 = forall {t} {u} {a}.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
commaSep1
                 }
    where

    -----------------------------------------------------------
    -- Bracketing
    -----------------------------------------------------------
    parens :: ParsecT s u m a -> ParsecT s u m a
parens ParsecT s u m a
p        = forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (forall {u}. String -> ParsecT s u m String
symbol String
"(") (forall {u}. String -> ParsecT s u m String
symbol String
")") ParsecT s u m a
p
    braces :: ParsecT s u m a -> ParsecT s u m a
braces ParsecT s u m a
p        = forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (forall {u}. String -> ParsecT s u m String
symbol String
"{") (forall {u}. String -> ParsecT s u m String
symbol String
"}") ParsecT s u m a
p
    angles :: ParsecT s u m a -> ParsecT s u m a
angles ParsecT s u m a
p        = forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (forall {u}. String -> ParsecT s u m String
symbol String
"<") (forall {u}. String -> ParsecT s u m String
symbol String
">") ParsecT s u m a
p
    brackets :: ParsecT s u m a -> ParsecT s u m a
brackets ParsecT s u m a
p      = forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (forall {u}. String -> ParsecT s u m String
symbol String
"[") (forall {u}. String -> ParsecT s u m String
symbol String
"]") ParsecT s u m a
p

    semi :: ParsecT s u m String
semi            = forall {u}. String -> ParsecT s u m String
symbol String
";"
    comma :: ParsecT s u m String
comma           = forall {u}. String -> ParsecT s u m String
symbol String
","
    dot :: ParsecT s u m String
dot             = forall {u}. String -> ParsecT s u m String
symbol String
"."
    colon :: ParsecT s u m String
colon           = forall {u}. String -> ParsecT s u m String
symbol String
":"

    commaSep :: ParsecT s u m a -> ParsecT s u m [a]
commaSep ParsecT s u m a
p      = forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy ParsecT s u m a
p forall {u}. ParsecT s u m String
comma
    semiSep :: ParsecT s u m a -> ParsecT s u m [a]
semiSep ParsecT s u m a
p       = forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy ParsecT s u m a
p forall {u}. ParsecT s u m String
semi

    commaSep1 :: ParsecT s u m a -> ParsecT s u m [a]
commaSep1 ParsecT s u m a
p     = forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 ParsecT s u m a
p forall {u}. ParsecT s u m String
comma
    semiSep1 :: ParsecT s u m a -> ParsecT s u m [a]
semiSep1 ParsecT s u m a
p      = forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 ParsecT s u m a
p forall {u}. ParsecT s u m String
semi


    -----------------------------------------------------------
    -- Chars & Strings
    -----------------------------------------------------------
    charLiteral :: ParsecT s u m Char
charLiteral     = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme (forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\'')
                                      (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\'' forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"end of character")
                                      forall {u}. ParsecT s u m Char
characterChar )
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"character"

    characterChar :: ParsecT s u m Char
characterChar   = forall {u}. ParsecT s u m Char
charLetter forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Char
charEscape
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"literal character"

    charEscape :: ParsecT s u m Char
charEscape      = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\'; forall {u}. ParsecT s u m Char
escapeCode }
    charLetter :: ParsecT s u m Char
charLetter      = forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\'') Bool -> Bool -> Bool
&& (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c forall a. Ord a => a -> a -> Bool
> Char
'\026'))



    stringLiteral :: ParsecT s u m String
stringLiteral   = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme (
                      do{ [Maybe Char]
str <- forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"')
                                         (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'"' forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"end of string")
                                         (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall {u}. ParsecT s u m (Maybe Char)
stringChar)
                        ; forall (m :: * -> *) a. Monad m => a -> m a
return (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id (:)) String
"" [Maybe Char]
str)
                        }
                      forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"literal string")

    stringChar :: ParsecT s u m (Maybe Char)
stringChar      =   do{ Char
c <- forall {u}. ParsecT s u m Char
stringLetter; forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just Char
c) }
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m (Maybe Char)
stringEscape
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"string character"

    stringLetter :: ParsecT s u m Char
stringLetter    = forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'"') Bool -> Bool -> Bool
&& (Char
c forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c forall a. Ord a => a -> a -> Bool
> Char
'\026'))

    stringEscape :: ParsecT s u m (Maybe Char)
stringEscape    = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\'
                        ;     do{ Char
_ <- forall {u}. ParsecT s u m Char
escapeGap  ; forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing }
                          forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ Char
_ <- forall {u}. ParsecT s u m Char
escapeEmpty; forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing }
                          forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ Char
esc <- forall {u}. ParsecT s u m Char
escapeCode; forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just Char
esc) }
                        }

    escapeEmpty :: ParsecT s u m Char
escapeEmpty     = forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'&'
    escapeGap :: ParsecT s u m Char
escapeGap       = do{ String
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space
                        ; forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\\' forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"end of string gap"
                        }



    -- escape codes
    escapeCode :: ParsecT s u m Char
escapeCode      = forall {u}. ParsecT s u m Char
charEsc forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Char
charNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Char
charAscii forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Char
charControl
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"escape code"

    charControl :: ParsecT s u m Char
charControl     = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^'
                        ; Char
code <- forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
upper
                        ; forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Enum a => Int -> a
toEnum (forall a. Enum a => a -> Int
fromEnum Char
code forall a. Num a => a -> a -> a
- forall a. Enum a => a -> Int
fromEnum Char
'A' forall a. Num a => a -> a -> a
+ Int
1))
                        }

    charNum :: ParsecT s u m Char
charNum         = do{ Integer
code <- forall {u}. ParsecT s u m Integer
decimal
                                  forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'o'; forall {s} {u} {m :: * -> *}.
Integer -> ParsecT s u m Char -> ParsecT s u m Integer
number Integer
8 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
octDigit }
                                  forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'x'; forall {s} {u} {m :: * -> *}.
Integer -> ParsecT s u m Char -> ParsecT s u m Integer
number Integer
16 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
hexDigit }
                        ; if Integer
code forall a. Ord a => a -> a -> Bool
> Integer
0x10FFFF
                          then forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid escape sequence"
                          else forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Enum a => Int -> a
toEnum (forall a. Num a => Integer -> a
fromInteger Integer
code))
                        }

    charEsc :: ParsecT s u m Char
charEsc         = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice (forall a b. (a -> b) -> [a] -> [b]
map forall {s} {m :: * -> *} {b} {u}.
Stream s m Char =>
(Char, b) -> ParsecT s u m b
parseEsc [(Char, Char)]
escMap)
                    where
                      parseEsc :: (Char, b) -> ParsecT s u m b
parseEsc (Char
c,b
code)     = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c; forall (m :: * -> *) a. Monad m => a -> m a
return b
code }

    charAscii :: ParsecT s u m Char
charAscii       = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice (forall a b. (a -> b) -> [a] -> [b]
map forall {s} {m :: * -> *} {a} {u}.
Stream s m Char =>
(String, a) -> ParsecT s u m a
parseAscii [(String, Char)]
asciiMap)
                    where
                      parseAscii :: (String, a) -> ParsecT s u m a
parseAscii (String
asc,a
code) = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do{ String
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
asc; forall (m :: * -> *) a. Monad m => a -> m a
return a
code })


    -- escape code tables
    escMap :: [(Char, Char)]
escMap          = forall a b. [a] -> [b] -> [(a, b)]
zip (String
"abfnrtv\\\"\'") (String
"\a\b\f\n\r\t\v\\\"\'")
    asciiMap :: [(String, Char)]
asciiMap        = forall a b. [a] -> [b] -> [(a, b)]
zip ([String]
ascii3codes forall a. [a] -> [a] -> [a]
++ [String]
ascii2codes) (String
ascii3 forall a. [a] -> [a] -> [a]
++ String
ascii2)

    ascii2codes :: [String]
ascii2codes     = [String
"BS",String
"HT",String
"LF",String
"VT",String
"FF",String
"CR",String
"SO",String
"SI",String
"EM",
                       String
"FS",String
"GS",String
"RS",String
"US",String
"SP"]
    ascii3codes :: [String]
ascii3codes     = [String
"NUL",String
"SOH",String
"STX",String
"ETX",String
"EOT",String
"ENQ",String
"ACK",String
"BEL",
                       String
"DLE",String
"DC1",String
"DC2",String
"DC3",String
"DC4",String
"NAK",String
"SYN",String
"ETB",
                       String
"CAN",String
"SUB",String
"ESC",String
"DEL"]

    ascii2 :: String
ascii2          = [Char
'\BS',Char
'\HT',Char
'\LF',Char
'\VT',Char
'\FF',Char
'\CR',Char
'\SO',Char
'\SI',
                       Char
'\EM',Char
'\FS',Char
'\GS',Char
'\RS',Char
'\US',Char
'\SP']
    ascii3 :: String
ascii3          = [Char
'\NUL',Char
'\SOH',Char
'\STX',Char
'\ETX',Char
'\EOT',Char
'\ENQ',Char
'\ACK',
                       Char
'\BEL',Char
'\DLE',Char
'\DC1',Char
'\DC2',Char
'\DC3',Char
'\DC4',Char
'\NAK',
                       Char
'\SYN',Char
'\ETB',Char
'\CAN',Char
'\SUB',Char
'\ESC',Char
'\DEL']


    -----------------------------------------------------------
    -- Numbers
    -----------------------------------------------------------
    naturalOrFloat :: ParsecT s u m (Either Integer Double)
naturalOrFloat  = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme (forall {u}. ParsecT s u m (Either Integer Double)
natFloat) forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"number"

    float :: ParsecT s u m Double
float           = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall {u}. ParsecT s u m Double
floating   forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"float"
    integer :: ParsecT s u m Integer
integer         = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall {u}. ParsecT s u m Integer
int        forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"integer"
    natural :: ParsecT s u m Integer
natural         = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall {u}. ParsecT s u m Integer
nat        forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"natural"


    -- floats
    floating :: ParsecT s u m Double
floating        = do{ Integer
n <- forall {u}. ParsecT s u m Integer
decimal
                        ; forall {t} {a} {a} {u}.
(Stream s m t, Read a, Show a) =>
a -> ParsecT s u m a
fractExponent Integer
n
                        }


    natFloat :: ParsecT s u m (Either Integer Double)
natFloat        = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'0'
                        ; forall {u}. ParsecT s u m (Either Integer Double)
zeroNumFloat
                        }
                      forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m (Either Integer Double)
decimalFloat

    zeroNumFloat :: ParsecT s u m (Either Integer Double)
zeroNumFloat    =  do{ Integer
n <- forall {u}. ParsecT s u m Integer
hexadecimal forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Integer
octal
                         ; forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. a -> Either a b
Left Integer
n)
                         }
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m (Either Integer Double)
decimalFloat
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {t} {b} {a} {u} {a}.
(Stream s m t, Read b, Show a) =>
a -> ParsecT s u m (Either a b)
fractFloat (Integer
0 :: Integer)
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. a -> Either a b
Left Integer
0)

    decimalFloat :: ParsecT s u m (Either Integer Double)
decimalFloat    = do{ Integer
n <- forall {u}. ParsecT s u m Integer
decimal
                        ; forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (forall a b. a -> Either a b
Left Integer
n)
                                 (forall {t} {b} {a} {u} {a}.
(Stream s m t, Read b, Show a) =>
a -> ParsecT s u m (Either a b)
fractFloat Integer
n)
                        }

    fractFloat :: a -> ParsecT s u m (Either a b)
fractFloat a
n    = do{ b
f <- forall {t} {a} {a} {u}.
(Stream s m t, Read a, Show a) =>
a -> ParsecT s u m a
fractExponent a
n
                        ; forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. b -> Either a b
Right b
f)
                        }

    fractExponent :: a -> ParsecT s u m a
fractExponent a
n = do{ String
fract <- forall {u}. ParsecT s u m String
fraction
                        ; String
expo  <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option String
"" forall {u}. ParsecT s u m String
exponent'
                        ; forall {a} {s} {u} {m :: * -> *}.
Read a =>
String -> ParsecT s u m a
readDouble (forall a. Show a => a -> String
show a
n forall a. [a] -> [a] -> [a]
++ String
fract forall a. [a] -> [a] -> [a]
++ String
expo)
                        }
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                      do{ String
expo <- forall {u}. ParsecT s u m String
exponent'
                        ; forall {a} {s} {u} {m :: * -> *}.
Read a =>
String -> ParsecT s u m a
readDouble (forall a. Show a => a -> String
show a
n forall a. [a] -> [a] -> [a]
++ String
expo)
                        }
                      where
                        readDouble :: String -> ParsecT s u m a
readDouble String
s =
                          case forall a. Read a => ReadS a
reads String
s of
                            [(a
x, String
"")] -> forall (m :: * -> *) a. Monad m => a -> m a
return a
x
                            [(a, String)]
_         -> forall s u (m :: * -> *) a. ParsecT s u m a
parserZero

    fraction :: ParsecT s u m String
fraction        = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'.'
                        ; String
digits <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"fraction"
                        ; forall (m :: * -> *) a. Monad m => a -> m a
return (Char
'.' forall a. a -> [a] -> [a]
: String
digits)
                        }
                      forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"fraction"

    exponent' :: ParsecT s u m String
exponent'       = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"eE"
                        ; String
sign' <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> [a] -> [a]
:[]) (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"+-") forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return String
""
                        ; Integer
e <- forall {u}. ParsecT s u m Integer
decimal forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"exponent"
                        ; forall (m :: * -> *) a. Monad m => a -> m a
return (Char
'e' forall a. a -> [a] -> [a]
: String
sign' forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Integer
e)
                        }
                      forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"exponent"


    -- integers and naturals
    int :: ParsecT s u m Integer
int             = do{ Integer -> Integer
f <- forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall {u}. ParsecT s u m (Integer -> Integer)
sign
                        ; Integer
n <- forall {u}. ParsecT s u m Integer
nat
                        ; forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> Integer
f Integer
n)
                        }

    sign :: ParsecT s u m (Integer -> Integer)
sign            =   (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Num a => a -> a
negate)
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'+' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. a -> a
id)
                    forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. a -> a
id

    nat :: ParsecT s u m Integer
nat             = forall {u}. ParsecT s u m Integer
zeroNumber forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Integer
decimal

    zeroNumber :: ParsecT s u m Integer
zeroNumber      = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'0'
                        ; forall {u}. ParsecT s u m Integer
hexadecimal forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Integer
octal forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m Integer
decimal forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return Integer
0
                        }
                      forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
""

    decimal :: ParsecT s u m Integer
decimal         = forall {s} {u} {m :: * -> *}.
Integer -> ParsecT s u m Char -> ParsecT s u m Integer
number Integer
10 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit
    hexadecimal :: ParsecT s u m Integer
hexadecimal     = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"xX"; forall {s} {u} {m :: * -> *}.
Integer -> ParsecT s u m Char -> ParsecT s u m Integer
number Integer
16 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
hexDigit }
    octal :: ParsecT s u m Integer
octal           = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
"oO"; forall {s} {u} {m :: * -> *}.
Integer -> ParsecT s u m Char -> ParsecT s u m Integer
number Integer
8 forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
octDigit  }

    number :: Integer -> ParsecT s u m Char -> ParsecT s u m Integer
number Integer
base ParsecT s u m Char
baseDigit
        = do{ String
digits <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT s u m Char
baseDigit
            ; let n :: Integer
n = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\Integer
x Char
d -> Integer
baseforall a. Num a => a -> a -> a
*Integer
x forall a. Num a => a -> a -> a
+ forall a. Integral a => a -> Integer
toInteger (Char -> Int
digitToInt Char
d)) Integer
0 String
digits
            ; seq :: forall a b. a -> b -> b
seq Integer
n (forall (m :: * -> *) a. Monad m => a -> m a
return Integer
n)
            }

    -----------------------------------------------------------
    -- Operators & reserved ops
    -----------------------------------------------------------
    reservedOp :: String -> ParsecT s u m ()
reservedOp String
name =
        forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
        do{ String
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
name
          ; forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opLetter GenLanguageDef s u m
languageDef) forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> (String
"end of " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show String
name)
          }

    operator :: ParsecT s u m String
operator =
        forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
        do{ String
name <- ParsecT s u m String
oper
          ; if (String -> Bool
isReservedOp String
name)
             then forall s (m :: * -> *) t u a.
Stream s m t =>
String -> ParsecT s u m a
unexpected (String
"reserved operator " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show String
name)
             else forall (m :: * -> *) a. Monad m => a -> m a
return String
name
          }

    oper :: ParsecT s u m String
oper =
        do{ Char
c <- (forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opStart GenLanguageDef s u m
languageDef)
          ; String
cs <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opLetter GenLanguageDef s u m
languageDef)
          ; forall (m :: * -> *) a. Monad m => a -> m a
return (Char
cforall a. a -> [a] -> [a]
:String
cs)
          }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"operator"

    isReservedOp :: String -> Bool
isReservedOp String
name =
        forall {p}. Ord p => [p] -> p -> Bool
isReserved (forall a. Ord a => [a] -> [a]
sort (forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedOpNames GenLanguageDef s u m
languageDef)) String
name


    -----------------------------------------------------------
    -- Identifiers & Reserved words
    -----------------------------------------------------------
    reserved :: String -> ParsecT s u m ()
reserved String
name =
        forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
        do{ String
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
caseString String
name
          ; forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identLetter GenLanguageDef s u m
languageDef) forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> (String
"end of " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show String
name)
          }

    caseString :: String -> ParsecT s u m String
caseString String
name
        | forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
caseSensitive GenLanguageDef s u m
languageDef  = forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
name
        | Bool
otherwise               = do{ forall {s} {m :: * -> *} {u}.
Stream s m Char =>
String -> ParsecT s u m ()
walk String
name; forall (m :: * -> *) a. Monad m => a -> m a
return String
name }
        where
          walk :: String -> ParsecT s u m ()
walk []     = forall (m :: * -> *) a. Monad m => a -> m a
return ()
          walk (Char
c:String
cs) = do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
caseChar Char
c forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
msg; String -> ParsecT s u m ()
walk String
cs }

          caseChar :: Char -> ParsecT s u m Char
caseChar Char
c  | Char -> Bool
isAlpha Char
c  = forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char (Char -> Char
toLower Char
c) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char (Char -> Char
toUpper Char
c)
                      | Bool
otherwise  = forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c

          msg :: String
msg         = forall a. Show a => a -> String
show String
name


    identifier :: ParsecT s u m String
identifier =
        forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
        do{ String
name <- ParsecT s u m String
ident
          ; if (String -> Bool
isReservedName String
name)
             then forall s (m :: * -> *) t u a.
Stream s m t =>
String -> ParsecT s u m a
unexpected (String
"reserved word " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show String
name)
             else forall (m :: * -> *) a. Monad m => a -> m a
return String
name
          }


    ident :: ParsecT s u m String
ident
        = do{ Char
c <- forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identStart GenLanguageDef s u m
languageDef
            ; String
cs <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identLetter GenLanguageDef s u m
languageDef)
            ; forall (m :: * -> *) a. Monad m => a -> m a
return (Char
cforall a. a -> [a] -> [a]
:String
cs)
            }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"identifier"

    isReservedName :: String -> Bool
isReservedName String
name
        = forall {p}. Ord p => [p] -> p -> Bool
isReserved [String]
theReservedNames String
caseName
        where
          caseName :: String
caseName      | forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
caseSensitive GenLanguageDef s u m
languageDef  = String
name
                        | Bool
otherwise               = forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
name


    isReserved :: [p] -> p -> Bool
isReserved [p]
names p
name
        = [p] -> Bool
scan [p]
names
        where
          scan :: [p] -> Bool
scan []       = Bool
False
          scan (p
r:[p]
rs)   = case (forall a. Ord a => a -> a -> Ordering
compare p
r p
name) of
                            Ordering
LT  -> [p] -> Bool
scan [p]
rs
                            Ordering
EQ  -> Bool
True
                            Ordering
GT  -> Bool
False

    theReservedNames :: [String]
theReservedNames
        | forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
caseSensitive GenLanguageDef s u m
languageDef  = forall a. Ord a => [a] -> [a]
sort [String]
reserved
        | Bool
otherwise                  = forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower) forall a b. (a -> b) -> a -> b
$ [String]
reserved
        where
          reserved :: [String]
reserved = forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedNames GenLanguageDef s u m
languageDef



    -----------------------------------------------------------
    -- White space & symbols
    -----------------------------------------------------------
    symbol :: String -> ParsecT s u m String
symbol String
name
        = forall {u} {b}. ParsecT s u m b -> ParsecT s u m b
lexeme (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
name)

    lexeme :: ParsecT s u m b -> ParsecT s u m b
lexeme ParsecT s u m b
p
        = do{ b
x <- ParsecT s u m b
p; forall {u}. ParsecT s u m ()
whiteSpace; forall (m :: * -> *) a. Monad m => a -> m a
return b
x  }


    --whiteSpace
    whiteSpace :: ParsecT s u m ()
whiteSpace
        | Bool
noLine Bool -> Bool -> Bool
&& Bool
noMulti  = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (forall {u}. ParsecT s u m ()
simpleSpace forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"")
        | Bool
noLine             = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (forall {u}. ParsecT s u m ()
simpleSpace forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m ()
multiLineComment forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"")
        | Bool
noMulti            = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (forall {u}. ParsecT s u m ()
simpleSpace forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m ()
oneLineComment forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"")
        | Bool
otherwise          = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (forall {u}. ParsecT s u m ()
simpleSpace forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m ()
oneLineComment forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT s u m ()
multiLineComment forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"")
        where
          noLine :: Bool
noLine  = forall (t :: * -> *) a. Foldable t => t a -> Bool
null (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentLine GenLanguageDef s u m
languageDef)
          noMulti :: Bool
noMulti = forall (t :: * -> *) a. Foldable t => t a -> Bool
null (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentStart GenLanguageDef s u m
languageDef)


    simpleSpace :: ParsecT s u m ()
simpleSpace =
        forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isSpace)

    oneLineComment :: ParsecT s u m ()
oneLineComment =
        do{ String
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentLine GenLanguageDef s u m
languageDef))
          ; forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/= Char
'\n'))
          ; forall (m :: * -> *) a. Monad m => a -> m a
return ()
          }

    multiLineComment :: ParsecT s u m ()
multiLineComment =
        do { String
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentStart GenLanguageDef s u m
languageDef))
           ; ParsecT s u m ()
inComment
           }

    inComment :: ParsecT s u m ()
inComment
        | forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
nestedComments GenLanguageDef s u m
languageDef  = ParsecT s u m ()
inCommentMulti
        | Bool
otherwise                = forall {u}. ParsecT s u m ()
inCommentSingle

    inCommentMulti :: ParsecT s u m ()
inCommentMulti
        =   do{ String
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentEnd GenLanguageDef s u m
languageDef)) ; forall (m :: * -> *) a. Monad m => a -> m a
return () }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ ParsecT s u m ()
multiLineComment                     ; ParsecT s u m ()
inCommentMulti }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
startEnd)          ; ParsecT s u m ()
inCommentMulti }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
startEnd                  ; ParsecT s u m ()
inCommentMulti }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"end of comment"
        where
          startEnd :: String
startEnd   = forall a. Eq a => [a] -> [a]
nub (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentEnd GenLanguageDef s u m
languageDef forall a. [a] -> [a] -> [a]
++ forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentStart GenLanguageDef s u m
languageDef)

    inCommentSingle :: ParsecT s u m ()
inCommentSingle
        =   do{ String
_ <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentEnd GenLanguageDef s u m
languageDef)); forall (m :: * -> *) a. Monad m => a -> m a
return () }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf String
startEnd)         ; ParsecT s u m ()
inCommentSingle }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do{ Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
startEnd                 ; ParsecT s u m ()
inCommentSingle }
        forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"end of comment"
        where
          startEnd :: String
startEnd   = forall a. Eq a => [a] -> [a]
nub (forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentEnd GenLanguageDef s u m
languageDef forall a. [a] -> [a] -> [a]
++ forall s u (m :: * -> *). GenLanguageDef s u m -> String
commentStart GenLanguageDef s u m
languageDef)