Skip to content

Commit

Permalink
fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
melrief committed Aug 18, 2013
1 parent c8106aa commit 3a7f7a5
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/System/Console/Hawk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ import System.Console.Hawk.Config
import System.Console.Hawk.Options


-- missing error handling!!
readImportsFromFile :: FilePath -> IO [(String,Maybe String)]
readImportsFromFile fp = P.read <$> IO.readFile fp

initInterpreter :: (String, String) -- ^ config file and module nme
-> Maybe FilePath
-> InterpreterT IO ()
Expand All @@ -55,18 +51,19 @@ initInterpreter config moduleFile = do
-- load the config file
loadModules [P.fst config]

let modules = (P.snd config,Nothing):defaultModules

maybe (setImportsQ modules)
(setImportsQFromFile modules)
moduleFile
where
setImportsQFromFile :: [(String,Maybe String)]
-> FilePath
-> InterpreterT IO ()
setImportsQFromFile requiredImports confFile = do
imports <- lift (readImportsFromFile confFile)
setImportsQ $ imports ++ requiredImports
-- load the config module plus representable
let requiredModules = (P.snd config,Nothing):defaultModules
userModules <- lift $ maybe (return []) loadFromFile moduleFile

let modules = requiredModules ++ userModules

let modulesWithPrelude = if "Prelude" `L.notElem` fmap P.fst modules
then ("Prelude",Nothing):modules
else modules

setImportsQ modulesWithPrelude
where loadFromFile :: FilePath -> IO [(String,Maybe String)]
loadFromFile fp = P.read <$> IO.readFile fp

printErrors :: InterpreterError -> IO ()
printErrors e = case e of
Expand Down

0 comments on commit 3a7f7a5

Please sign in to comment.