@@ -36,11 +36,13 @@ import System.Environment.XDG.BaseDir
3636import System.FilePath ((</>), isPathSeparator)
3737import System.Process
3838
39+import qualified Parser
40+
3941import qualified Data.Map as M
4042import qualified Language.PureScript as P
4143import qualified Paths_purescript as Paths
4244import 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)
4446
4547-- |
4648-- The PSCI state.
@@ -115,7 +117,7 @@ getPreludeFilename = Paths.getDataFileName "prelude/prelude.purs"
115117-- Loads a file for use with imports.
116118--
117119loadModule :: 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
119121
120122-- |
121123-- Expands tilde in path.
@@ -233,23 +235,6 @@ handleTypeOf value (PSCI imports loadedModules lets) = do
233235 Just (ty, _) -> outputStrLn . P.prettyPrintType $ ty
234236 Nothing -> outputStrLn "Could not find type"
235237
236−-- Parser helpers
237−
238−-- |
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@.
242−--
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)
246−
247−-- |
248−-- Parser for any other valid expression.
249−--
250−parseExpression :: Parsec.Parsec String P.ParseState P.Value
251−parseExpression = P.whiteSpace *> P.parseValue <* Parsec.eof
252−
253238-- Commands
254239
255240-- |
@@ -258,7 +243,7 @@ parseExpression = P.whiteSpace *> P.parseValue <* Parsec.eof
258243handleCommand :: Command -> StateT PSCI (InputT IO) ()
259244handleCommand Empty = return ()
260245handleCommand (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
262247 Left err -> inputTToState $ outputStrLn (show err)
263248 Right (Left l) -> modify (updateLets l)
264249 Right (Right decl) -> get >>= inputTToState . handleDeclaration decl
@@ -275,7 +260,7 @@ handleCommand Reload = do
275260 (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
276261 put (PSCI defaultImports prelude [])
277262handleCommand (TypeOf expr) =
278− case P.runIndentParser "" parseExpression expr of
263+ case Parser.psciParser Parser.parseExpression expr of
279264 Left err -> inputTToState $ outputStrLn (show err)
280265 Right expr' -> get >>= inputTToState . handleTypeOf expr'
281266handleCommand _ = outputTStrLn "Unknown command"