{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolymorphicComponents #-}
{-# LANGUAGE Safe #-}
{-# 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
type LanguageDef st = GenLanguageDef String st Identity
data GenLanguageDef s u m
= LanguageDef {
:: String,
:: String,
:: String,
:: Bool,
forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identStart :: ParsecT s u m Char,
forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identLetter :: ParsecT s u m Char,
forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opStart :: ParsecT s u m Char,
forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opLetter :: ParsecT s u m Char,
forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedNames :: [String],
forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedOpNames:: [String],
forall s u (m :: * -> *). GenLanguageDef s u m -> Bool
caseSensitive :: Bool
}
#if MIN_VERSION_base(4,7,0)
deriving ( Typeable )
#endif
type TokenParser st = GenTokenParser String st Identity
data GenTokenParser s u m
= TokenParser {
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
identifier :: ParsecT s u m String,
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
reserved :: String -> ParsecT s u m (),
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
operator :: ParsecT s u m String,
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m ()
reservedOp :: String -> ParsecT s u m (),
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Char
charLiteral :: ParsecT s u m Char,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
stringLiteral :: ParsecT s u m String,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
natural :: ParsecT s u m Integer,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
integer :: ParsecT s u m Integer,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Double
float :: ParsecT s u m Double,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m (Either Integer Double)
naturalOrFloat :: ParsecT s u m (Either Integer Double),
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
decimal :: ParsecT s u m Integer,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
hexadecimal :: ParsecT s u m Integer,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m Integer
octal :: ParsecT s u m Integer,
forall s u (m :: * -> *).
GenTokenParser s u m -> String -> ParsecT s u m String
symbol :: String -> ParsecT s u m String,
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,
forall s u (m :: * -> *). GenTokenParser s u m -> ParsecT s u m ()
whiteSpace :: ParsecT s u m (),
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,
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,
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,
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,
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,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
semi :: ParsecT s u m String,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
comma :: ParsecT s u m String,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
colon :: ParsecT s u m String,
forall s u (m :: * -> *).
GenTokenParser s u m -> ParsecT s u m String
dot :: ParsecT s u m String,
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],
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],
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],
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
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
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
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"
}
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 })
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']
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"
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"
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)
}
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
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
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 :: 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)