packages feed

elm-repl 0.2.2 → 0.2.2.1

raw patch · 3 files changed

+61/−4 lines, 3 files

Files

changelog.txt view
@@ -1,5 +1,5 @@-Upcoming Release-================+Release 0.2.1+============= Features:   * Basic auto-completion.   * Better error messages.
elm-repl.cabal view
@@ -1,5 +1,5 @@ Name:                elm-repl-Version:             0.2.2+Version:             0.2.2.1 Synopsis:            a REPL for Elm Description:         A read-eval-print-loop (REPL) for evaluating Elm expressions,                      definitions, ADTs, and module imports. This tool is meant to@@ -36,7 +36,8 @@                        Evaluator,                        Flags,                        Monad,-                       Parse+                       Parse,+                       Repl    Build-depends:       base >=4.2 && <5,                        bytestring,
+ src/Repl.hs view
@@ -0,0 +1,56 @@+module Repl (run) where++import Control.Monad.Trans+import System.Console.Haskeline hiding (handle)+import System.Exit++import Monad++import qualified Action      as Act+import qualified Command     as Cmd+import qualified Evaluator   as Eval+import qualified Environment as Env+import qualified Flags+import qualified Parse++run :: Flags.Flags -> Settings ReplM -> IO ExitCode+run flags settings =+    runReplM flags initialEnv . runInputT settings $ withInterrupt repl+  where+    initialEnv = Env.empty (Flags.compiler flags)++repl :: InputT ReplM ExitCode+repl = do+  str' <- handleInterrupt (return $ Just "") getInput+  case str' of+    Nothing -> return ExitSuccess+    Just str -> do+      let action = Parse.input str+      result <- lift $ handle action+      case result of+        Just exit -> return exit+        Nothing   -> repl++handle :: Act.Action -> ReplM (Maybe ExitCode)+handle action =+    case action of+      Act.Command cmd -> Cmd.run cmd++      Act.Skip -> return Nothing++      Act.Code src ->+          do Eval.evalPrint src+             return Nothing++getInput :: (MonadException m) => InputT m (Maybe String)+getInput = go "> " ""+    where+      go str old = do+        input <- getInputLine str+        case input of+          Nothing  -> return Nothing+          Just new -> continueWith (old ++ new)++      continueWith str+        | null str || last str /= '\\' = return $ Just str+        | otherwise = go "| " (init str ++ "\n")