module Language.Haskell.Exts.Parser
(
Parseable(parse, parseWithMode, parseWithComments),
ParseMode(..), defaultParseMode, ParseResult(..), fromParseResult,
parseModule, parseModuleWithMode, parseModuleWithComments,
parseExp, parseExpWithMode, parseExpWithComments,
parseStmt, parseStmtWithMode, parseStmtWithComments,
parsePat, parsePatWithMode, parsePatWithComments,
parseDecl, parseDeclWithMode, parseDeclWithComments,
parseType, parseTypeWithMode, parseTypeWithComments,
parseImportDecl, parseImportDeclWithMode,
parseImportDeclWithComments,
NonGreedy(..),
getTopPragmas,
PragmasAndModuleName(..),
PragmasAndModuleHead(..),
ModuleHeadAndImports(..)
) where
import Data.Data (Data, Typeable)
import Language.Haskell.Exts.Annotated.Fixity
import Language.Haskell.Exts.Annotated.Parser (unListOf, ListOf, NonGreedy(..))
import qualified Language.Haskell.Exts.Annotated.Parser as A
import Language.Haskell.Exts.Annotated.Simplify
import Language.Haskell.Exts.Annotated.Syntax
import Language.Haskell.Exts.Comments
import Language.Haskell.Exts.ParseMonad hiding (getModuleName)
import Language.Haskell.Exts.SrcLoc
import qualified Language.Haskell.Exts.Syntax as S
parseWithSimplify :: Parseable a => a -> (a -> a') -> Maybe [Fixity] -> P a'
parseWithSimplify _witness simpl mfixs = parser mfixs >>= return . simpl
instance Parseable S.Decl where parser = parseWithSimplify (undefined :: Decl SrcSpanInfo) sDecl
instance Parseable S.Exp where parser = parseWithSimplify (undefined :: Exp SrcSpanInfo) sExp
instance Parseable S.Module where parser = parseWithSimplify (undefined :: Module SrcSpanInfo) sModule
instance Parseable S.Pat where parser = parseWithSimplify (undefined :: Pat SrcSpanInfo) sPat
instance Parseable S.Stmt where parser = parseWithSimplify (undefined :: Stmt SrcSpanInfo) sStmt
instance Parseable S.Type where parser = parseWithSimplify (undefined :: Type SrcSpanInfo) sType
instance Parseable S.ImportDecl where parser = parseWithSimplify (undefined :: ImportDecl SrcSpanInfo) sImportDecl
instance Parseable (NonGreedy [S.ModulePragma]) where
parser = parseWithSimplify
(undefined :: NonGreedy (ListOf (ModulePragma SrcSpanInfo)))
(fmap (map sModulePragma . unListOf))
parseModule :: String -> ParseResult S.Module
parseModule = parse
parseModuleWithMode :: ParseMode -> String -> ParseResult S.Module
parseModuleWithMode = parseWithMode
parseModuleWithComments :: ParseMode -> String -> ParseResult (S.Module, [Comment])
parseModuleWithComments = parseWithComments
parseExp :: String -> ParseResult S.Exp
parseExp = parse
parseExpWithMode :: ParseMode -> String -> ParseResult S.Exp
parseExpWithMode = parseWithMode
parseExpWithComments :: ParseMode -> String -> ParseResult (S.Exp, [Comment])
parseExpWithComments = parseWithComments
parsePat :: String -> ParseResult S.Pat
parsePat = parse
parsePatWithMode :: ParseMode -> String -> ParseResult S.Pat
parsePatWithMode = parseWithMode
parsePatWithComments :: ParseMode -> String -> ParseResult (S.Pat, [Comment])
parsePatWithComments = parseWithComments
parseDecl :: String -> ParseResult S.Decl
parseDecl = parse
parseDeclWithMode :: ParseMode -> String -> ParseResult S.Decl
parseDeclWithMode = parseWithMode
parseDeclWithComments :: ParseMode -> String -> ParseResult (S.Decl, [Comment])
parseDeclWithComments = parseWithComments
parseType :: String -> ParseResult S.Type
parseType = parse
parseTypeWithMode :: ParseMode -> String -> ParseResult S.Type
parseTypeWithMode = parseWithMode
parseTypeWithComments :: ParseMode -> String -> ParseResult (S.Type, [Comment])
parseTypeWithComments = parseWithComments
parseStmt :: String -> ParseResult S.Stmt
parseStmt = parse
parseStmtWithMode :: ParseMode -> String -> ParseResult S.Stmt
parseStmtWithMode = parseWithMode
parseStmtWithComments :: ParseMode -> String -> ParseResult (S.Stmt, [Comment])
parseStmtWithComments = parseWithComments
parseImportDecl :: String -> ParseResult S.ImportDecl
parseImportDecl = parse
parseImportDeclWithMode :: ParseMode -> String -> ParseResult S.ImportDecl
parseImportDeclWithMode = parseWithMode
parseImportDeclWithComments :: ParseMode -> String -> ParseResult (S.ImportDecl, [Comment])
parseImportDeclWithComments = parseWithComments
getTopPragmas :: String -> ParseResult [S.ModulePragma]
getTopPragmas = fmap (fmap unNonGreedy) parse
data PragmasAndModuleName = PragmasAndModuleName
[S.ModulePragma]
S.ModuleName
deriving (Eq,Ord,Show,Typeable,Data)
instance Parseable (NonGreedy PragmasAndModuleName) where
parser fixs = do
NonGreedy (A.PragmasAndModuleName _ ps mmn) <- parser fixs
return $ NonGreedy $ PragmasAndModuleName
(map sModulePragma (ps :: [ModulePragma SrcSpanInfo]))
(maybe S.main_mod sModuleName mmn)
data PragmasAndModuleHead = PragmasAndModuleHead
[S.ModulePragma]
(S.ModuleName, Maybe S.WarningText, Maybe [S.ExportSpec])
deriving (Eq,Ord,Show,Typeable,Data)
instance Parseable (NonGreedy PragmasAndModuleHead) where
parser fixs = do
NonGreedy (A.PragmasAndModuleHead _ ps mmh) <- parser fixs
return $ NonGreedy $ PragmasAndModuleHead
(map sModulePragma (ps :: [ModulePragma SrcSpanInfo]))
(sModuleHead mmh)
data ModuleHeadAndImports = ModuleHeadAndImports
[S.ModulePragma]
(S.ModuleName, Maybe S.WarningText, Maybe [S.ExportSpec])
[S.ImportDecl]
deriving (Eq,Ord,Show,Typeable,Data)
instance Parseable (NonGreedy ModuleHeadAndImports) where
parser fixs = do
NonGreedy (A.ModuleHeadAndImports _ ps mmh imps) <- parser fixs
return $ NonGreedy $ ModuleHeadAndImports
(map sModulePragma (ps :: [ModulePragma SrcSpanInfo]))
(sModuleHead mmh)
(map sImportDecl imps)