module Language.Haskell.Exts.Parser
(
Parseable(..),
ParseMode(..), defaultParseMode, ParseResult(..), fromParseResult,
parseModule, parseModuleWithMode, parseModuleWithComments,
parseExp, parseExpWithMode, parseExpWithComments,
parseStmt, parseStmtWithMode, parseStmtWithComments,
parsePat, parsePatWithMode, parsePatWithComments,
parseDecl, parseDeclWithMode, parseDeclWithComments,
parseType, parseTypeWithMode, parseTypeWithComments,
getTopPragmas
) where
import Language.Haskell.Exts.InternalParser ( ParseMode(..), defaultParseMode, ParseResult(..), fromParseResult )
import qualified Language.Haskell.Exts.InternalParser as P
import Language.Haskell.Exts.Annotated.Syntax
import qualified Language.Haskell.Exts.Syntax as S
import Language.Haskell.Exts.Annotated.Simplify
import Language.Haskell.Exts.SrcLoc
import Language.Haskell.Exts.Comments
getTopPragmas :: String -> ParseResult [S.ModulePragma]
getTopPragmas = fmap (map sModulePragma) . P.getTopPragmas
class Parseable ast where
parse :: String -> ParseResult ast
parseWithMode :: ParseMode -> String -> ParseResult ast
parseWithComments :: ParseMode -> String -> ParseResult (ast, [Comment])
instance SrcInfo loc => Parseable (Module loc) where
parse = fmap (fmap fromSrcInfo) . P.parseModule
parseWithMode = (fmap (fmap fromSrcInfo) .) . P.parseModuleWithMode
parseWithComments md s = P.parseModuleWithComments md s >>= \(r, cs) -> return (fmap fromSrcInfo r, cs)
instance SrcInfo loc => Parseable (Exp loc) where
parse = fmap (fmap fromSrcInfo) . P.parseExp
parseWithMode = (fmap (fmap fromSrcInfo) .) . P.parseExpWithMode
parseWithComments md s = P.parseExpWithComments md s >>= \(r, cs) -> return (fmap fromSrcInfo r, cs)
instance SrcInfo loc => Parseable (Pat loc) where
parse = fmap (fmap fromSrcInfo) . P.parsePat
parseWithMode = (fmap (fmap fromSrcInfo) .) . P.parsePatWithMode
parseWithComments md s = P.parsePatWithComments md s >>= \(r, cs) -> return (fmap fromSrcInfo r, cs)
instance SrcInfo loc => Parseable (Decl loc) where
parse = fmap (fmap fromSrcInfo) . P.parseDecl
parseWithMode = (fmap (fmap fromSrcInfo) .) . P.parseDeclWithMode
parseWithComments md s = P.parseDeclWithComments md s >>= \(r, cs) -> return (fmap fromSrcInfo r, cs)
instance SrcInfo loc => Parseable (Type loc) where
parse = fmap (fmap fromSrcInfo) . P.parseType
parseWithMode = (fmap (fmap fromSrcInfo) .) . P.parseTypeWithMode
parseWithComments md s = P.parseTypeWithComments md s >>= \(r, cs) -> return (fmap fromSrcInfo r, cs)
instance SrcInfo loc => Parseable (Stmt loc) where
parse = fmap (fmap fromSrcInfo) . P.parseStmt
parseWithMode = (fmap (fmap fromSrcInfo) .) . P.parseStmtWithMode
parseWithComments md s = P.parseStmtWithComments md s >>= \(r, cs) -> return (fmap fromSrcInfo r, cs)
parseModule :: String -> ParseResult S.Module
parseModule = fmap sModule . P.parseModule
parseModuleWithMode :: ParseMode -> String -> ParseResult S.Module
parseModuleWithMode = (fmap sModule .) . P.parseModuleWithMode
parseModuleWithComments :: ParseMode -> String -> ParseResult (S.Module, [Comment])
parseModuleWithComments = (fmap (\(mod, cs) -> (sModule mod, cs)) .) . P.parseModuleWithComments
parseExp :: String -> ParseResult S.Exp
parseExp = fmap sExp . P.parseExp
parseExpWithMode :: ParseMode -> String -> ParseResult S.Exp
parseExpWithMode = (fmap sExp .) . P.parseExpWithMode
parseExpWithComments :: ParseMode -> String -> ParseResult (S.Exp, [Comment])
parseExpWithComments = (fmap (\(e, cs) -> (sExp e, cs)) .) . P.parseExpWithComments
parsePat :: String -> ParseResult S.Pat
parsePat = fmap sPat . P.parsePat
parsePatWithMode :: ParseMode -> String -> ParseResult S.Pat
parsePatWithMode = (fmap sPat .) . P.parsePatWithMode
parsePatWithComments :: ParseMode -> String -> ParseResult (S.Pat, [Comment])
parsePatWithComments = (fmap (\(p, cs) -> (sPat p, cs)) .) . P.parsePatWithComments
parseDecl :: String -> ParseResult S.Decl
parseDecl = fmap sDecl . P.parseDecl
parseDeclWithMode :: ParseMode -> String -> ParseResult S.Decl
parseDeclWithMode = (fmap sDecl .) . P.parseDeclWithMode
parseDeclWithComments :: ParseMode -> String -> ParseResult (S.Decl, [Comment])
parseDeclWithComments = (fmap (\(decl, cs) -> (sDecl decl, cs)) .) . P.parseDeclWithComments
parseType :: String -> ParseResult S.Type
parseType = fmap sType . P.parseType
parseTypeWithMode :: ParseMode -> String -> ParseResult S.Type
parseTypeWithMode = (fmap sType .) . P.parseTypeWithMode
parseTypeWithComments :: ParseMode -> String -> ParseResult (S.Type, [Comment])
parseTypeWithComments = (fmap (\(t, cs) -> (sType t, cs)) .) . P.parseTypeWithComments
parseStmt :: String -> ParseResult S.Stmt
parseStmt = fmap sStmt . P.parseStmt
parseStmtWithMode :: ParseMode -> String -> ParseResult S.Stmt
parseStmtWithMode = (fmap sStmt .) . P.parseStmtWithMode
parseStmtWithComments :: ParseMode -> String -> ParseResult (S.Stmt, [Comment])
parseStmtWithComments = (fmap (\(s, cs) -> (sStmt s, cs)) .) . P.parseStmtWithComments
instance Parseable S.Module where
parse = parseModule
parseWithMode = parseModuleWithMode
parseWithComments = parseModuleWithComments
instance Parseable S.Exp where
parse = parseExp
parseWithMode = parseExpWithMode
parseWithComments = parseExpWithComments
instance Parseable S.Pat where
parse = parsePat
parseWithMode = parsePatWithMode
parseWithComments = parsePatWithComments
instance Parseable S.Decl where
parse = parseDecl
parseWithMode = parseDeclWithMode
parseWithComments = parseDeclWithComments
instance Parseable S.Type where
parse = parseType
parseWithMode = parseTypeWithMode
parseWithComments = parseTypeWithComments