@@ -28,6 +28,7 @@ import Control.Monad.Trans.State
28import Data.List (intercalate, isPrefixOf, nub, sortBy)
28import Data.List (intercalate, isPrefixOf, nub, sortBy)
29import Data.Maybe (mapMaybe)
29import Data.Maybe (mapMaybe)
30import Data.Traversable (traverse)
30import Data.Traversable (traverse)
31+import Data.Version (showVersion)
32import Parser
33import Parser
@@ -36,6 +37,7 @@ import System.Directory (doesFileExist, findExecutable, getHomeDirectory)
36import System.Exit
37import System.Exit
37import System.Environment.XDG.BaseDir
38import System.Environment.XDG.BaseDir
38import System.FilePath ((</>), isPathSeparator)
39import System.FilePath ((</>), isPathSeparator)
40+import qualified System.Console.CmdTheLine as Cmd
39import System.Process
41import System.Process
41import Text.Parsec (ParseError)
43import Text.Parsec (ParseError)
@@ -256,7 +258,6 @@ getCommand = do
256-- Performs an action for each meta-command given, and also for expressions..
258-- Performs an action for each meta-command given, and also for expressions..
258handleCommand :: Command -> StateT PSCI (InputT IO) ()
260handleCommand :: Command -> StateT PSCI (InputT IO) ()
259−handleCommand Empty = return ()
260handleCommand (Expression val) = get >>= inputTToState . handleDeclaration val
261handleCommand (Expression val) = get >>= inputTToState . handleDeclaration val
261handleCommand (Let l) = modify (updateLets l)
262handleCommand (Let l) = modify (updateLets l)
262handleCommand Help = inputTToState $ outputStrLn helpMessage
263handleCommand Help = inputTToState $ outputStrLn helpMessage
@@ -268,7 +269,7 @@ handleCommand (LoadFile filePath) = do
268 either outputTStrLn (modify . updateModules) =<< ioToState (loadModule absPath)
269 either outputTStrLn (modify . updateModules) =<< ioToState (loadModule absPath)
270 outputTStrLn $ "Couldn't locate: " ++ filePath
271 outputTStrLn $ "Couldn't locate: " ++ filePath
271−handleCommand Reload = do
272+handleCommand Reset = do
272 (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
273 (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
273 put (PSCI defaultImports prelude [])
274 put (PSCI defaultImports prelude [])
274handleCommand (TypeOf val) = get >>= inputTToState . handleTypeOf val
275handleCommand (TypeOf val) = get >>= inputTToState . handleTypeOf val
@@ -288,24 +289,44 @@ outputTStrLn = inputTToState . outputStrLn
288outprintT :: Show a => a -> StateT PSCI (InputT IO) ()
289outprintT :: Show a => a -> StateT PSCI (InputT IO) ()
289outprintT = outputTStrLn . show
290outprintT = outputTStrLn . show
292+inputFiles :: Cmd.Term [FilePath]
293+inputFiles = Cmd.value $ Cmd.posAny [] $ Cmd.posInfo { Cmd.posDoc = "The input .ps files" }
292-- The PSCI main loop.
296-- The PSCI main loop.
294−main :: IO ()
298+loop :: [FilePath] -> IO ()
295−main = do
299+loop files = do
296 preludeFilename <- getPreludeFilename
300 preludeFilename <- getPreludeFilename
297− (Right prelude) <- loadModule preludeFilename
301+ modulesOrFirstError <- fmap concat . sequence <$> mapM loadModule (preludeFilename : files)
302+ case modulesOrFirstError of
303+ Left err -> putStrLn err >> exitFailure
298− historyFilename <- getHistoryFilename
305+ historyFilename <- getHistoryFilename
299− let settings = defaultSettings {historyFile = Just historyFilename}
306+ let settings = defaultSettings {historyFile = Just historyFilename}
300− runInputT (setComplete (completion prelude) settings) $ do
307+ runInputT (setComplete (completion modules) settings) $ do
301− outputStrLn prologueMessage
308+ outputStrLn prologueMessage
302− evalStateT go (PSCI defaultImports prelude [])
309+ evalStateT go (PSCI defaultImports modules [])
304− go :: StateT PSCI (InputT IO) ()
311+ go :: StateT PSCI (InputT IO) ()
306− c <- inputTToState getCommand
313+ c <- inputTToState getCommand
307− case c of
314+ case c of
308− Left err -> outputTStrLn (show err) >> go
315+ Left err -> outputTStrLn (show err) >> go
309− Right Nothing -> go
316+ Right Nothing -> go
310− Right (Just Quit) -> outputTStrLn quitMessage
317+ Right (Just Quit) -> outputTStrLn quitMessage
311− Right (Just c') -> handleCommand c' >> go
318+ Right (Just c') -> handleCommand c' >> go
320+term :: Cmd.Term (IO ())
321+term = loop <$> inputFiles
323+termInfo :: Cmd.TermInfo
325+ { Cmd.termName = "psci"
326+ , Cmd.version = showVersion $ Paths.version
327+ , Cmd.termDoc = "Interactive mode for PureScript"
331+main = Cmd.run (term, termInfo)