{-# LANGUAGE Safe #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Parsec.Language
-- 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 non-portable module Text.Parsec.Token)
--
-- A helper module that defines some language definitions that can be used
-- to instantiate a token parser (see "Text.Parsec.Token").
--
-----------------------------------------------------------------------------

module Text.Parsec.Language
    ( haskellDef, haskell
    , mondrianDef, mondrian
    , emptyDef
    , haskellStyle
    , javaStyle
    , LanguageDef
    , GenLanguageDef
    ) where

import Text.Parsec
import Text.Parsec.Token

-----------------------------------------------------------
-- Styles: haskellStyle, javaStyle
-----------------------------------------------------------

-- | This is a minimal token definition for Haskell style languages. It
-- defines the style of comments, valid identifiers and case
-- sensitivity. It does not define any reserved words or operators.

haskellStyle :: LanguageDef st
haskellStyle :: forall st. LanguageDef st
haskellStyle = forall st. LanguageDef st
emptyDef
                { commentStart :: String
commentStart   = String
"{-"
                , commentEnd :: String
commentEnd     = String
"-}"
                , commentLine :: String
commentLine    = String
"--"
                , nestedComments :: Bool
nestedComments = Bool
True
                , identStart :: ParsecT String st Identity Char
identStart     = forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter
                , identLetter :: ParsecT String st Identity Char
identLetter    = forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum 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 =>
String -> ParsecT s u m Char
oneOf String
"_'"
                , opStart :: ParsecT String st Identity Char
opStart        = forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opLetter forall st. LanguageDef st
haskellStyle
                , opLetter :: ParsecT String st Identity Char
opLetter       = forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
":!#$%&*+./<=>?@\\^|-~"
                , reservedOpNames :: [String]
reservedOpNames= []
                , reservedNames :: [String]
reservedNames  = []
                , caseSensitive :: Bool
caseSensitive  = Bool
True
                }

-- | This is a minimal token definition for Java style languages. It
-- defines the style of comments, valid identifiers and case
-- sensitivity. It does not define any reserved words or operators.

javaStyle  :: LanguageDef st
javaStyle :: forall st. LanguageDef st
javaStyle   = forall st. LanguageDef st
emptyDef
                { commentStart :: String
commentStart   = String
"/*"
                , commentEnd :: String
commentEnd     = String
"*/"
                , commentLine :: String
commentLine    = String
"//"
                , nestedComments :: Bool
nestedComments = Bool
True
                , identStart :: ParsecT String st Identity Char
identStart     = forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter
                , identLetter :: ParsecT String st Identity Char
identLetter    = forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum 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 =>
String -> ParsecT s u m Char
oneOf String
"_'"
                , reservedNames :: [String]
reservedNames  = []
                , reservedOpNames :: [String]
reservedOpNames= []
                , caseSensitive :: Bool
caseSensitive  = Bool
False
                }

-----------------------------------------------------------
-- minimal language definition
--------------------------------------------------------

-- | This is the most minimal token definition. It is recommended to use
-- this definition as the basis for other definitions. @emptyDef@ has
-- no reserved names or operators, is case sensitive and doesn't accept
-- comments, identifiers or operators.

emptyDef   :: LanguageDef st
emptyDef :: forall st. LanguageDef st
emptyDef    = LanguageDef
               { commentStart :: String
commentStart   = String
""
               , commentEnd :: String
commentEnd     = String
""
               , commentLine :: String
commentLine    = String
""
               , nestedComments :: Bool
nestedComments = Bool
True
               , identStart :: ParsecT String st Identity Char
identStart     = forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter 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
'_'
               , identLetter :: ParsecT String st Identity Char
identLetter    = forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum 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 =>
String -> ParsecT s u m Char
oneOf String
"_'"
               , opStart :: ParsecT String st Identity Char
opStart        = forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
opLetter forall st. LanguageDef st
emptyDef
               , opLetter :: ParsecT String st Identity Char
opLetter       = forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf String
":!#$%&*+./<=>?@\\^|-~"
               , reservedOpNames :: [String]
reservedOpNames= []
               , reservedNames :: [String]
reservedNames  = []
               , caseSensitive :: Bool
caseSensitive  = Bool
True
               }



-----------------------------------------------------------
-- Haskell
-----------------------------------------------------------

-- | A lexer for the Haskell language.

haskell :: TokenParser st
haskell :: forall st. TokenParser st
haskell      = forall s (m :: * -> *) u.
Stream s m Char =>
GenLanguageDef s u m -> GenTokenParser s u m
makeTokenParser forall st. LanguageDef st
haskellDef

-- | The language definition for the Haskell language.

haskellDef  :: LanguageDef st
haskellDef :: forall st. LanguageDef st
haskellDef   = forall st. LanguageDef st
haskell98Def
                { identLetter :: ParsecT String st Identity Char
identLetter    = forall s u (m :: * -> *).
GenLanguageDef s u m -> ParsecT s u m Char
identLetter forall st. LanguageDef st
haskell98Def 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
'#'
                , reservedNames :: [String]
reservedNames  = forall s u (m :: * -> *). GenLanguageDef s u m -> [String]
reservedNames forall st. LanguageDef st
haskell98Def forall a. [a] -> [a] -> [a]
++
                                   [String
"foreign",String
"import",String
"export",String
"primitive"
                                   ,String
"_ccall_",String
"_casm_"
                                   ,String
"forall"
                                   ]
                }

-- | The language definition for the language Haskell98.

haskell98Def :: LanguageDef st
haskell98Def :: forall st. LanguageDef st
haskell98Def = forall st. LanguageDef st
haskellStyle
                { reservedOpNames :: [String]
reservedOpNames= [String
"::",String
"..",String
"=",String
"\\",String
"|",String
"<-",String
"->",String
"@",String
"~",String
"=>"]
                , reservedNames :: [String]
reservedNames  = [String
"let",String
"in",String
"case",String
"of",String
"if",String
"then",String
"else",
                                    String
"data",String
"type",
                                    String
"class",String
"default",String
"deriving",String
"do",String
"import",
                                    String
"infix",String
"infixl",String
"infixr",String
"instance",String
"module",
                                    String
"newtype",String
"where",
                                    String
"primitive"
                                    -- "as","qualified","hiding"
                                   ]
                }


-----------------------------------------------------------
-- Mondrian
-----------------------------------------------------------

-- | A lexer for the Mondrian language.

mondrian :: TokenParser st
mondrian :: forall st. TokenParser st
mondrian    = forall s (m :: * -> *) u.
Stream s m Char =>
GenLanguageDef s u m -> GenTokenParser s u m
makeTokenParser forall st. LanguageDef st
mondrianDef

-- | The language definition for the language Mondrian.

mondrianDef :: LanguageDef st
mondrianDef :: forall st. LanguageDef st
mondrianDef = forall st. LanguageDef st
javaStyle
                { reservedNames :: [String]
reservedNames = [ String
"case", String
"class", String
"default", String
"extends"
                                  , String
"import", String
"in", String
"let", String
"new", String
"of", String
"package"
                                  ]
                , caseSensitive :: Bool
caseSensitive  = Bool
True
                }