egison 3.2.6 → 3.2.7
raw patch · 5 files changed
+41/−9 lines, 5 filesdep +unixPVP ok
version bump matches the API change (PVP)
Dependencies added: unix
API changes (from Hackage documentation)
+ Language.Egison.Types: UserInterruption :: EgisonError
+ Language.Egison.Types: instance Exception EgisonError
+ Language.Egison.Types: instance Typeable EgisonError
Files
- egison.cabal +2/−2
- hs-src/Interpreter/egisoni.hs +20/−5
- hs-src/Language/Egison/Types.hs +9/−1
- lib/core/base.egi +10/−0
- lib/core/collection.egi +0/−1
egison.cabal view
@@ -1,5 +1,5 @@ Name: egison-Version: 3.2.6+Version: 3.2.7 Synopsis: Programming language with non-linear pattern-matching against unfree data types Description: An interpreter for Egison, the programming langugage that realized non-linear pattern-matching with unfree data types. With Egison, you can represent pattern-matching with unfree data types intuitively,@@ -51,6 +51,6 @@ Executable egison Main-is: egisoni.hs- Build-depends: egison, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, strict-io, bytestring+ Build-depends: egison, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, strict-io, bytestring, unix Other-modules: Paths_egison Hs-Source-Dirs: hs-src/Interpreter
hs-src/Interpreter/egisoni.hs view
@@ -1,5 +1,12 @@ module Main where +import Prelude hiding (catch)+import Control.Exception ( SomeException(..),+ AsyncException(..),+ catch, handle, throw)+import System.Posix.Signals+import Control.Concurrent+ import Control.Applicative ((<$>), (<*>)) import Control.Monad.Error @@ -11,9 +18,10 @@ import System.Environment import System.Directory (getHomeDirectory) import System.FilePath ((</>))-import System.Console.Haskeline+import System.Console.Haskeline hiding (handle, catch, throwTo) import System.Console.GetOpt import System.Exit (ExitCode (..), exitWith, exitFailure)+import System.IO import Language.Egison main :: IO ()@@ -104,17 +112,25 @@ showByebyeMessage = do putStrLn $ "Leaving Egison Interpreter." +onAbort :: EgisonError -> IO (Either EgisonError a)+onAbort e = do+ let x = show e+ return $ Left e+ repl :: Env -> String -> IO () repl env prompt = do home <- getHomeDirectory- liftIO (runInputT (settings home) $ loop env prompt "")+ liftIO (runInputT (settings home) $ (loop env prompt "")) where settings :: MonadIO m => FilePath -> Settings m settings home = defaultSettings { historyFile = Just (home </> ".egison_history") } loop :: Env -> String -> String -> InputT IO () loop env prompt' rest = do+ _ <- liftIO $ installHandler keyboardSignal (Catch (do {putStr "^C"; hFlush stdout})) Nothing input <- getInputLine prompt'+ tid <- liftIO $ myThreadId+ _ <- liftIO $ installHandler keyboardSignal (Catch (throwTo tid UserInterruption)) Nothing case input of Nothing -> return () Just "quit" -> return () @@ -124,12 +140,12 @@ _ -> loop env (take (length prompt) (repeat ' ')) rest Just input' -> do let newInput = rest ++ input'- result <- liftIO $ runEgisonTopExpr env newInput+ result <- liftIO $ handle onAbort $ runEgisonTopExpr env newInput case result of Left err | show err =~ "unexpected end of input" -> do loop env (take (length prompt) (repeat ' ')) $ newInput ++ "\n" Left err | show err =~ "expecting (top-level|\"define\")" -> do- result <- liftIO $ fromEgisonM (readExpr newInput) >>= either (return . Left) (evalEgisonExpr env)+ result <- liftIO $ handle onAbort $ fromEgisonM (readExpr newInput) >>= either (return . Left) (evalEgisonExpr env) case result of Left err | show err =~ "unexpected end of input" -> do loop env (take (length prompt) (repeat ' ')) $ newInput ++ "\n"@@ -144,4 +160,3 @@ loop env prompt "" Right env' -> loop env' prompt ""-
hs-src/Language/Egison/Types.hs view
@@ -1,9 +1,12 @@ {-# Language TypeSynonymInstances, FlexibleInstances, GeneralizedNewtypeDeriving,- MultiParamTypeClasses, UndecidableInstances #-}+ MultiParamTypeClasses, UndecidableInstances, DeriveDataTypeable #-} module Language.Egison.Types where import Prelude hiding (foldr) +import Control.Exception+import Data.Typeable+ import Control.Applicative import Control.Monad.Error import Control.Monad.State@@ -356,7 +359,9 @@ | Match String | Parser String | Desugar String+ | UserInterruption | Default String+ deriving Typeable instance Show EgisonError where show (Parser error) = "Parse error at: " ++ error@@ -368,7 +373,10 @@ show (NotImplemented message) = "Not implemented: " ++ message show (Assertion message) = "Assertion failed: " ++ message show (Desugar message) = "Error: " ++ message+ show UserInterruption = "Aborted: User interruption" show (Default message) = "Error: " ++ message++instance Exception EgisonError instance Error EgisonError where noMsg = Default "An error has occurred"
lib/core/base.egi view
@@ -46,3 +46,13 @@ (match x a {[,y #t] [_ #f]}))))++(define $compose+ (lambda [$f $g]+ (lambda $x+ (apply g (apply f x)))))++(define $compose3+ (lambda [$f $g $h]+ (lambda $x+ (apply h (apply g (apply f x))))))
lib/core/collection.egi view
@@ -310,4 +310,3 @@ [$ [something] {[$tgt {tgt}]}] })))-