@@ -16,6 +16,7 @@
16{-# LANGUAGE DoAndIfThenElse #-}
16{-# LANGUAGE DoAndIfThenElse #-}
17{-# LANGUAGE GeneralizedNewtypeDeriving #-}
17{-# LANGUAGE GeneralizedNewtypeDeriving #-}
18{-# LANGUAGE RecordWildCards #-}
18{-# LANGUAGE RecordWildCards #-}
19+{-# LANGUAGE TupleSections #-}
20module PSCi where
21module PSCi where
@@ -491,14 +492,20 @@ loop PSCiOptions{..} = do
491 Right modules -> do
492 Right modules -> do
492 historyFilename <- getHistoryFilename
493 historyFilename <- getHistoryFilename
493 let settings = defaultSettings { historyFile = Just historyFilename }
494 let settings = defaultSettings { historyFile = Just historyFilename }
495+ foreignsOrError <- runMake $ do
496+ foreignFiles <- forM psciForeignInputFiles (\inFile -> (inFile,) <$> makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile inFile)) (readFile inFile))
497+ P.parseForeignModulesFromFiles foreignFiles
498+ case foreignsOrError of
499+ Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> exitFailure
494− flip evalStateT (PSCiState psciInputFile defaultImports modules [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
501+ flip evalStateT (PSCiState psciInputFile defaultImports modules foreigns [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
495− outputStrLn prologueMessage
502+ outputStrLn prologueMessage
496− traverse_ (mapM_ (runPSCI . handleCommand)) config
503+ traverse_ (mapM_ (runPSCI . handleCommand)) config
497− unless (consoleIsDefined (map snd modules)) . outputStrLn $ unlines
504+ unless (consoleIsDefined (map snd modules)) . outputStrLn $ unlines
498− [ "PSCi requires the purescript-console module to be installed."
505+ [ "PSCi requires the purescript-console module to be installed."
499− , "For help getting started, visit http://wiki.purescript.org/PSCi"
506+ , "For help getting started, visit http://wiki.purescript.org/PSCi"
503 go :: InputT (StateT PSCiState IO) ()
510 go :: InputT (StateT PSCiState IO) ()
@@ -520,6 +527,12 @@ inputFile = strArgument $
520 metavar "FILE"
527 metavar "FILE"
521 <> Opts.help "Optional .purs files to load on start"
528 <> Opts.help "Optional .purs files to load on start"
530+inputForeignFile :: Parser FilePath
531+inputForeignFile = strOption $
534+ <> help "The input .js file(s) providing foreign import implementations"
523nodeFlagsFlag :: Parser [String]
536nodeFlagsFlag :: Parser [String]
524nodeFlagsFlag = option parser $
537nodeFlagsFlag = option parser $
525 long "node-opts"
538 long "node-opts"
@@ -532,6 +545,7 @@ nodeFlagsFlag = option parser $
532psciOptions :: Parser PSCiOptions
545psciOptions :: Parser PSCiOptions
533psciOptions = PSCiOptions <$> multiLineMode
546psciOptions = PSCiOptions <$> multiLineMode
534 <*> many inputFile
547 <*> many inputFile
548+ <*> many inputForeignFile
535 <*> nodeFlagsFlag
549 <*> nodeFlagsFlag
537runPSCi :: IO ()
551runPSCi :: IO ()