@@ -36,11 +36,13 @@ import System.Environment.XDG.BaseDir
36import System.FilePath ((</>), isPathSeparator)
36import System.FilePath ((</>), isPathSeparator)
37import System.Process
37import System.Process
39+import qualified Parser
39import qualified Data.Map as M
41import qualified Data.Map as M
40import qualified Language.PureScript as P
42import qualified Language.PureScript as P
41import qualified Paths_purescript as Paths
43import qualified Paths_purescript as Paths
42import qualified System.IO.UTF8 as U (readFile)
44import qualified System.IO.UTF8 as U (readFile)
43−import qualified Text.Parsec as Parsec (Parsec, eof, try)
45+import qualified Text.Parsec as Parsec (try)
46-- The PSCI state.
48-- The PSCI state.
@@ -115,7 +117,7 @@ getPreludeFilename = Paths.getDataFileName "prelude/prelude.purs"
115-- Loads a file for use with imports.
117-- Loads a file for use with imports.
117loadModule :: FilePath -> IO (Either String [P.Module])
119loadModule :: FilePath -> IO (Either String [P.Module])
118−loadModule = fmap (either (Left . show) Right . P.runIndentParser "" P.parseModules) . U.readFile
120+loadModule = fmap (either (Left . show) Right . Parser.parseModules) . U.readFile
121-- Expands tilde in path.
123-- Expands tilde in path.
@@ -233,23 +235,6 @@ handleTypeOf value (PSCI imports loadedModules lets) = do
233 Just (ty, _) -> outputStrLn . P.prettyPrintType $ ty
235 Just (ty, _) -> outputStrLn . P.prettyPrintType $ ty
234 Nothing -> outputStrLn "Could not find type"
236 Nothing -> outputStrLn "Could not find type"
239−-- Parser for our PSCI version of @let@.
240−-- This is essentially let from do-notation.
241−-- However, since we don't support the @Eff@ monad, we actually want the normal @let@.
243−parseLet :: Parsec.Parsec String P.ParseState (P.Value -> P.Value)
244−parseLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
245− <*> (P.indented *> P.reservedOp "=" *> P.parseValue)
248−-- Parser for any other valid expression.
250−parseExpression :: Parsec.Parsec String P.ParseState P.Value
251−parseExpression = P.whiteSpace *> P.parseValue <* Parsec.eof
253-- Commands
238-- Commands
@@ -258,7 +243,7 @@ parseExpression = P.whiteSpace *> P.parseValue <* Parsec.eof
258handleCommand :: Command -> StateT PSCI (InputT IO) ()
243handleCommand :: Command -> StateT PSCI (InputT IO) ()
259handleCommand Empty = return ()
244handleCommand Empty = return ()
260handleCommand (Expression ls) =
245handleCommand (Expression ls) =
261− case P.runIndentParser "" (Left <$> Parsec.try parseLet <|> Right <$> parseExpression) (unlines ls) of
246+ case Parser.psciParser (Left <$> Parsec.try Parser.parseLet <|> Right <$> Parser.parseExpression) (unlines ls) of
262 Left err -> inputTToState $ outputStrLn (show err)
247 Left err -> inputTToState $ outputStrLn (show err)
263 Right (Left l) -> modify (updateLets l)
248 Right (Left l) -> modify (updateLets l)
264 Right (Right decl) -> get >>= inputTToState . handleDeclaration decl
249 Right (Right decl) -> get >>= inputTToState . handleDeclaration decl
@@ -275,7 +260,7 @@ handleCommand Reload = do
275 (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
260 (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
276 put (PSCI defaultImports prelude [])
261 put (PSCI defaultImports prelude [])
277handleCommand (TypeOf expr) =
262handleCommand (TypeOf expr) =
278− case P.runIndentParser "" parseExpression expr of
263+ case Parser.psciParser Parser.parseExpression expr of
279 Left err -> inputTToState $ outputStrLn (show err)
264 Left err -> inputTToState $ outputStrLn (show err)
280 Right expr' -> get >>= inputTToState . handleTypeOf expr'
265 Right expr' -> get >>= inputTToState . handleTypeOf expr'
281handleCommand _ = outputTStrLn "Unknown command"
266handleCommand _ = outputTStrLn "Unknown command"