Commit b7070c77 authored by Andrew Gibiansky's avatar Andrew Gibiansky

cleaning, adding :set to affect parsing, closes #169

parent 72060398
......@@ -462,21 +462,29 @@ evalCommand output (Directive SetExtension opts) state = do
evalCommand a (Directive SetOption opts) state = do
write $ "Option: " ++ opts
let (lost, found) = partitionEithers
[ case filter (elem w . getOptionName) kernelOpts of
[x] -> Right (getUpdateKernelState x)
[] -> Left w
ds -> error ("kernelOpts has duplicate:" ++ show (map getOptionName ds))
| w <- words opts ]
warn
| null lost = mempty
| otherwise = displayError ("Could not recognize options: " ++ intercalate "," lost)
let (existing, nonExisting) = partition optionExists $ words opts
if not $ null nonExisting
then
let err = "No such options: " ++ intercalate ", " nonExisting in
return EvalOut {
evalStatus = if null lost then Success else Failure,
evalResult = warn,
evalState = foldl' (flip ($)) state found,
evalStatus = Failure,
evalResult = displayError err,
evalState = state,
evalPager = ""
}
else
let options = mapMaybe findOption $ words opts
updater = foldl' (.) id $ map getUpdateKernelState options in
return EvalOut {
evalStatus = Success,
evalResult = mempty,
evalState = updater state,
evalPager = ""
}
where
optionExists = isJust . findOption
findOption opt =
find (elem opt . getOptionName) kernelOpts
evalCommand _ (Directive GetType expr) state = wrapExecution state $ do
write $ "Type: " ++ expr
......
......@@ -125,7 +125,10 @@ parseString codeString = do
activateParsingExtensions :: GhcMonad m => CodeBlock -> m ()
activateParsingExtensions (Directive SetExtension ext) = void $ setExtension ext
activateParsingExtensions _ = return ()
activateParsingExtensions (Directive SetDynFlag flags) =
case stripPrefix "-X" flags of
Just ext -> void $ setExtension ext
Nothing -> return ()
-- | Parse a single chunk of code, as indicated by the layout of the code.
parseCodeChunk :: GhcMonad m => String -> LineNumber -> m CodeBlock
......@@ -251,16 +254,16 @@ parseDirective (':':directive) line = case find rightDirective directives of
[] -> False
dir:_ -> dir `elem` tail (inits dirname)
directives =
[(GetType, "type")
,(GetInfo, "info")
,(SearchHoogle, "hoogle")
,(GetDoc, "documentation")
,(SetDynFlag, "set")
,(LoadFile, "load")
,(SetOption, "option")
,(SetExtension, "extension")
,(GetHelp, "?")
,(GetHelp, "help")
[ (GetType, "type")
, (GetInfo, "info")
, (SearchHoogle, "hoogle")
, (GetDoc, "documentation")
, (SetDynFlag, "set")
, (LoadFile, "load")
, (SetOption, "option")
, (SetExtension, "extension")
, (GetHelp, "?")
, (GetHelp, "help")
]
parseDirective _ _ = error "Directive must start with colon!"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment