Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions app/Command/REPL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/Language/PureScript/Interactive/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
--
Expand Down Expand Up @@ -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.
--
Expand Down