mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-14 10:26:07 +00:00
Starting support for -F -pgmF
This commit is contained in:
parent
4d8d50ffe5
commit
1c78b09292
@ -960,6 +960,42 @@ evalCommand output (Pragma PragmaLanguage pragmas) state = do
|
||||
write state $ "Got LANGUAGE pragma " ++ show pragmas
|
||||
evalCommand output (Directive SetExtension $ unwords pragmas) state
|
||||
|
||||
evalCommand output (Pragma PragmaOptionsGhc pragmas) state = do
|
||||
write state $ "Got OPTIONS_GHC pragma " ++ show pragmas
|
||||
let hasPreprocessor = "-F" `elem` pragmas
|
||||
when hasPreprocessor $ do
|
||||
let -- Divide a list into pairs, if its evenly divisible.
|
||||
pairs :: [a] -> Maybe [(a, a)]
|
||||
pairs [] = Just []
|
||||
pairs [_] = Nothing
|
||||
pairs (x1:x2:xs) = (:) <$> Just (x1, x2) <*> pairs xs
|
||||
|
||||
wrong = return . displayError . ("Error in GHC options: " ++ )
|
||||
|
||||
-- Process a list of arguments, returning the pgmF command and any options to it.
|
||||
process :: [(String, String)] -> Either String (String, [String])
|
||||
process (("-pgmF", cmd):rest) = do
|
||||
(_, opts) <- process rest
|
||||
Right (cmd, opts)
|
||||
process (("-optF", opt):rest) = do
|
||||
(cmd, opts) <- process rest
|
||||
Right (cmd, opt:opts)
|
||||
process [] = Right ("", [])
|
||||
process ((arg, _):_) = Left $ "Unknown argument " ++ arg
|
||||
|
||||
otherOpts = pairs $ tail pragmas
|
||||
case otherOpts of
|
||||
Nothing -> wrong "Not an even number of arguments after -F. Only -F -pgmF supported."
|
||||
Just ps ->
|
||||
case process ps of
|
||||
Left err -> wrong err
|
||||
Right ("", args) -> wrong "No -pgmF specified"
|
||||
Right (cmd, args) ->
|
||||
setCellPreprocessor cmd args
|
||||
|
||||
|
||||
evalCommand output (Directive SetExtension $ unwords pragmas) state
|
||||
|
||||
hoogleResults :: KernelState -> [Hoogle.HoogleResult] -> EvalOut
|
||||
hoogleResults state results =
|
||||
EvalOut
|
||||
|
@ -65,9 +65,10 @@ data DirectiveType = GetType -- ^ Get the type of an expression via ':type'
|
||||
| LoadModule -- ^ Load and unload modules via ':module'.
|
||||
deriving (Show, Eq)
|
||||
|
||||
-- | Pragma types. Only LANGUAGE pragmas are currently supported. Other pragma types are kept around
|
||||
-- as a string for error reporting.
|
||||
-- | Pragma types. Only LANGUAGE and OPTIONS_GHC pragmas are currently supported. Other pragma types
|
||||
-- are kept around as a string for error reporting.
|
||||
data PragmaType = PragmaLanguage
|
||||
| PragmaOptionsGhc
|
||||
| PragmaUnsupported String
|
||||
deriving (Show, Eq)
|
||||
|
||||
@ -243,6 +244,7 @@ parsePragma ('{':'-':'#':pragma) line =
|
||||
--empty string pragmas are unsupported
|
||||
[] -> Pragma (PragmaUnsupported "") []
|
||||
"LANGUAGE":xs -> Pragma PragmaLanguage xs
|
||||
"OPTIONS_GHC":xs -> Pragma PragmaOptionsGhc xs
|
||||
x:xs -> Pragma (PragmaUnsupported x) xs
|
||||
|
||||
-- | Parse a directive of the form :directiveName.
|
||||
|
Loading…
x
Reference in New Issue
Block a user