diff --git a/app/Command/REPL.hs b/app/Command/REPL.hs index c07db590d0..04033b57eb 100644 --- a/app/Command/REPL.hs +++ b/app/Command/REPL.hs @@ -360,13 +360,10 @@ command = loop <$> options configFile <- ( ".purs-repl") <$> liftIO getCurrentDirectory exists <- liftIO $ doesFileExist configFile when exists $ do - ls <- lines <$> liftIO (readUTF8File configFile) - for_ ls $ \l -> do - liftIO (putStrLn l) - case parseCommand l of - Left err -> liftIO (putStrLn err >> exitFailure) - Right cmd@Import{} -> handleCommand' state cmd - Right _ -> liftIO (putStrLn "The .purs-repl file only supports import declarations") + cf <- liftIO (readUTF8File configFile) + case parseDotFile configFile cf of + Left err -> liftIO (putStrLn err >> exitFailure) + Right cmds -> liftIO (putStrLn cf) >> for_ cmds (handleCommand' state) handleCommandWithInterrupts :: state diff --git a/src/Language/PureScript/Interactive/Parser.hs b/src/Language/PureScript/Interactive/Parser.hs index 9a13b22a63..9d6df35f69 100644 --- a/src/Language/PureScript/Interactive/Parser.hs +++ b/src/Language/PureScript/Interactive/Parser.hs @@ -2,11 +2,13 @@ -- Parser for PSCI. -- module Language.PureScript.Interactive.Parser - ( parseCommand + ( parseDotFile + , parseCommand ) where import Prelude.Compat hiding (lex) +import Control.Applicative ((<|>)) import Control.Monad (join) import Data.Bifunctor (first) import Data.Char (isSpace) @@ -18,6 +20,16 @@ import qualified Language.PureScript.Interactive.Directive as D import Language.PureScript.Interactive.Types import Language.PureScript.Parser.Common (mark, same) +-- | +-- Parses a limited set of commands from from .purs-repl +-- +parseDotFile :: FilePath -> String -> Either String [Command] +parseDotFile filePath s = first show $ do + ts <- P.lex filePath (T.pack s) + P.runTokenParser filePath (many parser <* eof) ts + where + parser = psciImport <|> fail "The .purs-repl file only supports import declarations" + -- | -- Parses PSCI metacommands or expressions input from the user. -- @@ -72,6 +84,7 @@ parseDirective cmd = Type -> TypeOf <$> parseRest P.parseValue arg Kind -> KindOf <$> parseRest P.parseType arg Complete -> return (CompleteStr arg) + -- | -- Parses expressions entered at the PSCI repl. --