ghc-mod "expand" to expand TH.
This commit is contained in:
parent
e795b35502
commit
2c69ee4c8a
4
Check.hs
4
Check.hs
@ -25,4 +25,6 @@ check opt fileName = withGHC $ checkIt `gcatch` handleErrMsg
|
|||||||
setTargetFile file
|
setTargetFile file
|
||||||
load LoadAllTargets
|
load LoadAllTargets
|
||||||
liftIO readLog
|
liftIO readLog
|
||||||
options = ["-Wall","-fno-warn-unused-do-bind"] ++ ghcOpts opt
|
options
|
||||||
|
| expandSplice opt = ghcOpts opt
|
||||||
|
| otherwise = ["-Wall","-fno-warn-unused-do-bind"] ++ ghcOpts opt
|
||||||
|
10
GHCApi.hs
10
GHCApi.hs
@ -31,20 +31,24 @@ initSession opt cmdOpts idirs logging = do
|
|||||||
dflags <- getSessionDynFlags
|
dflags <- getSessionDynFlags
|
||||||
let opts = map noLoc cmdOpts
|
let opts = map noLoc cmdOpts
|
||||||
(dflags',_,_) <- parseDynamicFlags dflags opts
|
(dflags',_,_) <- parseDynamicFlags dflags opts
|
||||||
(dflags'',readLog) <- liftIO . (>>= setLogger logging) . setGhcFlags opt . setFlags dflags' $ idirs
|
(dflags'',readLog) <- liftIO . (>>= setLogger logging) . setGhcFlags opt . setFlags opt dflags' $ idirs
|
||||||
setSessionDynFlags dflags''
|
setSessionDynFlags dflags''
|
||||||
return readLog
|
return readLog
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
setFlags :: DynFlags -> [FilePath] -> DynFlags
|
setFlags :: Options -> DynFlags -> [FilePath] -> DynFlags
|
||||||
setFlags d idirs = d'
|
setFlags opt d idirs = d'
|
||||||
where
|
where
|
||||||
d' = d {
|
d' = d {
|
||||||
packageFlags = ghcPackage : packageFlags d
|
packageFlags = ghcPackage : packageFlags d
|
||||||
, importPaths = idirs
|
, importPaths = idirs
|
||||||
, ghcLink = NoLink
|
, ghcLink = NoLink
|
||||||
, hscTarget = HscInterpreted
|
, hscTarget = HscInterpreted
|
||||||
|
, flags = if expandSplice opt then
|
||||||
|
flags d ++ [Opt_D_dump_splices]
|
||||||
|
else
|
||||||
|
flags d
|
||||||
}
|
}
|
||||||
|
|
||||||
ghcPackage :: PackageFlag
|
ghcPackage :: PackageFlag
|
||||||
|
11
GHCMod.hs
11
GHCMod.hs
@ -35,6 +35,7 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
|
|||||||
++ "\t ghc-mod flag [-l]\n"
|
++ "\t ghc-mod flag [-l]\n"
|
||||||
++ "\t ghc-mod browse" ++ ghcOptHelp ++ "[-l] [-o] <module> [<module> ...]\n"
|
++ "\t ghc-mod browse" ++ ghcOptHelp ++ "[-l] [-o] <module> [<module> ...]\n"
|
||||||
++ "\t ghc-mod check" ++ ghcOptHelp ++ "<HaskellFile>\n"
|
++ "\t ghc-mod check" ++ ghcOptHelp ++ "<HaskellFile>\n"
|
||||||
|
++ "\t ghc-mod expand" ++ ghcOptHelp ++ "<HaskellFile>\n"
|
||||||
++ "\t ghc-mod info" ++ ghcOptHelp ++ "<HaskellFile> <module> <expression>\n"
|
++ "\t ghc-mod info" ++ ghcOptHelp ++ "<HaskellFile> <module> <expression>\n"
|
||||||
++ "\t ghc-mod type" ++ ghcOptHelp ++ "<HaskellFile> <module> <line-no> <column-no>\n"
|
++ "\t ghc-mod type" ++ ghcOptHelp ++ "<HaskellFile> <module> <line-no> <column-no>\n"
|
||||||
++ "\t ghc-mod lint [-h opt] <HaskellFile>\n"
|
++ "\t ghc-mod lint [-h opt] <HaskellFile>\n"
|
||||||
@ -43,14 +44,6 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
|
|||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
defaultOptions :: Options
|
|
||||||
defaultOptions = Options {
|
|
||||||
outputStyle = PlainStyle
|
|
||||||
, hlintOpts = []
|
|
||||||
, ghcOpts = []
|
|
||||||
, operators = False
|
|
||||||
}
|
|
||||||
|
|
||||||
argspec :: [OptDescr (Options -> Options)]
|
argspec :: [OptDescr (Options -> Options)]
|
||||||
argspec = [ Option "l" ["tolisp"]
|
argspec = [ Option "l" ["tolisp"]
|
||||||
(NoArg (\opts -> opts { outputStyle = LispStyle }))
|
(NoArg (\opts -> opts { outputStyle = LispStyle }))
|
||||||
@ -91,6 +84,8 @@ main = flip catches handlers $ do
|
|||||||
"browse" -> concat <$> mapM (browseModule opt) (tail cmdArg)
|
"browse" -> concat <$> mapM (browseModule opt) (tail cmdArg)
|
||||||
"list" -> listModules opt
|
"list" -> listModules opt
|
||||||
"check" -> withFile (checkSyntax opt) (safelist cmdArg 1)
|
"check" -> withFile (checkSyntax opt) (safelist cmdArg 1)
|
||||||
|
"expand" -> withFile (checkSyntax opt { expandSplice = True })
|
||||||
|
(safelist cmdArg 1)
|
||||||
"type" -> withFile (typeExpr opt (safelist cmdArg 2) (read $ safelist cmdArg 3) (read $ safelist cmdArg 4)) (safelist cmdArg 1)
|
"type" -> withFile (typeExpr opt (safelist cmdArg 2) (read $ safelist cmdArg 3) (read $ safelist cmdArg 4)) (safelist cmdArg 1)
|
||||||
"info" -> withFile (infoExpr opt (safelist cmdArg 2) (safelist cmdArg 3)) (safelist cmdArg 1)
|
"info" -> withFile (infoExpr opt (safelist cmdArg 2) (safelist cmdArg 3)) (safelist cmdArg 1)
|
||||||
"lint" -> withFile (lintSyntax opt) (safelist cmdArg 1)
|
"lint" -> withFile (lintSyntax opt) (safelist cmdArg 1)
|
||||||
|
18
Types.hs
18
Types.hs
@ -5,10 +5,20 @@ module Types where
|
|||||||
data OutputStyle = LispStyle | PlainStyle
|
data OutputStyle = LispStyle | PlainStyle
|
||||||
|
|
||||||
data Options = Options {
|
data Options = Options {
|
||||||
outputStyle :: OutputStyle
|
outputStyle :: OutputStyle
|
||||||
, hlintOpts :: [String]
|
, hlintOpts :: [String]
|
||||||
, ghcOpts :: [String]
|
, ghcOpts :: [String]
|
||||||
, operators :: Bool
|
, operators :: Bool
|
||||||
|
, expandSplice :: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultOptions :: Options
|
||||||
|
defaultOptions = Options {
|
||||||
|
outputStyle = PlainStyle
|
||||||
|
, hlintOpts = []
|
||||||
|
, ghcOpts = []
|
||||||
|
, operators = False
|
||||||
|
, expandSplice = False
|
||||||
}
|
}
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user