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