A peer-to-peer stack for code collaboration
Move REPL effects into their own package radicle-repl
Fintan Halpennya760cb36a01a
diff --git a/radicle-lang/src/Radicle.hs b/radicle-lang/src/Radicle.hsindex 3da827e..04b1bda 100644--- a/radicle-lang/src/Radicle.hs+++ b/radicle-lang/src/Radicle.hs@@ -57,7 +57,6 @@ module Radicle, Lang, runLang, Bindings(..)- , replBindings-- ** To/FromRadicle, ToRad(..), FromRad(..)@@ -77,18 +76,10 @@ module Radicle, PageWidth(..), Pretty- -- * Repl- , repl-- -- * Script- , script--- * PrimFns, PrimFns(..), purePrimFns- , replPrimFns, addPrimFns- , ReplM-- * CLI, getHistoryFile@@ -98,7 +89,6 @@ module Radicle, ($$), kwLookup, (??)- , ignoreShebang) where@@ -107,7 +97,6 @@ import Data.Text.Prettyprint.Docimport Radicle.Internal.Annotationimport Radicle.Internal.CLIimport Radicle.Internal.Core-import Radicle.Internal.Effectsimport Radicle.Internal.Evalimport Radicle.Internal.Identifierimport Radicle.Internal.Interpretdiff --git a/radicle-lang/src/Radicle/Internal/Pretty.hs b/radicle-lang/src/Radicle/Internal/Pretty.hsindex 6f8cdb3..1bd98f3 100644--- a/radicle-lang/src/Radicle/Internal/Pretty.hs+++ b/radicle-lang/src/Radicle/Internal/Pretty.hs@@ -18,10 +18,13 @@ import Text.Megaparsec.Pos (sourcePosPretty)import qualified Radicle.Internal.Annotation as Annimport Radicle.Internal.Core-import Radicle.Internal.Effects.Capabilities (Stdout(..))import Radicle.Internal.Identifier (Ident(..))import Radicle.Internal.Type+data ANSISupport+ = ANSISupport+ | NoANSISupport+class PrettyV a whereprettyV :: a -> Doc Type@@ -174,15 +177,12 @@ renderPrettyDef :: PrettyV v => v -> TextrenderPrettyDef = renderStrict . layoutSmart defaultLayoutOptions . prettyV-- | Pretty print the value with colors if @m@ supports it.-putPrettyAnsi :: (PrettyV v, Stdout m) => v -> m ()-putPrettyAnsi value = do- supportsANSI' <- supportsANSI+putPrettyAnsi :: PrettyV v => (Text -> m ()) -> ANSISupport -> v -> m ()+putPrettyAnsi putStrS supportsANSI value =let docStream = layoutSmart defaultLayoutOptions $ prettyV value- if supportsANSI'- then- putStrS $ Term.renderStrict $ reAnnotateS toAnsi docStream- else- putStrS $ renderStrict docStream+ in case supportsANSI of+ ANSISupport -> putStrS $ Term.renderStrict $ reAnnotateS toAnsi docStream+ NoANSISupport -> putStrS $ renderStrict docStreamtoAnsi :: Type -> Term.AnsiStyletoAnsi = \casediff --git a/radicle-repl/.gitignore b/radicle-repl/.gitignorenew file mode 100644index 0000000..6f0dd92--- /dev/null+++ b/radicle-repl/.gitignore@@ -0,0 +1,3 @@+.stack-work/+radicle-repl.cabal+*~\ No newline at end of filediff --git a/radicle-repl/ChangeLog.md b/radicle-repl/ChangeLog.mdnew file mode 100644index 0000000..c24a165--- /dev/null+++ b/radicle-repl/ChangeLog.md@@ -0,0 +1,3 @@+# Changelog for radicle-repl++## Unreleased changesdiff --git a/radicle-repl/LICENSE b/radicle-repl/LICENSEnew file mode 100644index 0000000..102126f--- /dev/null+++ b/radicle-repl/LICENSE@@ -0,0 +1,30 @@+Copyright Author name here (c) 2019++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.diff --git a/radicle-repl/README.md b/radicle-repl/README.mdnew file mode 100644index 0000000..25e4b7d--- /dev/null+++ b/radicle-repl/README.md@@ -0,0 +1 @@+# radicle-repldiff --git a/radicle-repl/Setup.hs b/radicle-repl/Setup.hsnew file mode 100644index 0000000..9a994af--- /dev/null+++ b/radicle-repl/Setup.hs@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMaindiff --git a/radicle-repl/package.yaml b/radicle-repl/package.yamlnew file mode 100644index 0000000..e75e2d3--- /dev/null+++ b/radicle-repl/package.yaml@@ -0,0 +1,80 @@+name: radicle-repl+version: 0.1.0.0+github: "githubuser/radicle-repl"+license: BSD3+author: "Author name here"+maintainer: "[email protected]"+copyright: "2019 Author name here"++extra-source-files:+- README.md+- ChangeLog.md++# Metadata used when publishing your package+# synopsis: Short description of your package+# category: Web++# To avoid duplicated efforts in documentation and dealing with the+# complications of embedding Haddock markup inside cabal files, it is+# common to point users to the README.md file.+description: Please see the README on GitHub at <https://github.com/githubuser/radicle-repl#readme>++dependencies:+- base >= 4.7 && < 5+- protolude+- radicle-lang++library:+ source-dirs: src+ dependencies:+ - ansi-terminal+ - bytestring+ - containers+ - directory+ - filepath+ - haskeline+ - prettyprinter+ - process+ - text+ - time++tests:+ spec:+ main: Main.hs+ source-dirs:+ - test/spec+ dependencies:+ - async+ - containers+ - cryptonite+ - interpolate+ - megaparsec+ - process+ - protolude+ - QuickCheck+ - quickcheck-instances+ - radicle-lang+ - scientific+ - serialise+ - stm+ - string-qq+ - tasty+ - tasty-hunit+ - tasty-quickcheck+ - text+ - time+ build-tools:+ - tasty-discover+ ghc-options: [-threaded, -rtsopts, -with-rtsopts=-N]++default-extensions:+- ConstraintKinds+- FlexibleContexts+- FlexibleInstances+- FunctionalDependencies+- LambdaCase+- MultiParamTypeClasses+- NoImplicitPrelude+- OverloadedStrings+- ScopedTypeVariables+- TypeFamiliesdiff --git a/radicle-lang/src/Radicle/Internal/Effects.hs b/radicle-repl/src/Radicle/Repl.hssimilarity index 96%rename from radicle-lang/src/Radicle/Internal/Effects.hsrename to radicle-repl/src/Radicle/Repl.hsindex 7654c0a..2796568 100644--- a/radicle-lang/src/Radicle/Internal/Effects.hs+++ b/radicle-repl/src/Radicle/Repl.hs@@ -1,6 +1,6 @@{-# OPTIONS_GHC -fno-warn-orphans #-}-module Radicle.Internal.Effects where+module Radicle.Repl whereimport Protolude hiding (TypeError, toList)@@ -22,7 +22,6 @@ import System.Console.Haskelineimport Radicle.Internal.Coreimport Radicle.Internal.Crypto-import Radicle.Internal.Effects.Capabilitiesimport Radicle.Internal.Evalimport Radicle.Internal.Identifier (Ident(..), unsafeToIdent)import Radicle.Internal.Interpret@@ -33,6 +32,7 @@ import Radicle.Internal.PrimFnsimport Radicle.Internal.Time as Timeimport Radicle.Internal.Type (Type(..))import qualified Radicle.Internal.UUID as UUID+import Radicle.Repl.Capabilitiestype ReplM m =( Monad m, Stdout (Lang m), Stdin (Lang m)@@ -54,14 +54,19 @@ instance UUID.MonadUUID (InputT IO) whereinstance UUID.MonadUUID m => UUID.MonadUUID (LangT (Bindings (PrimFns m)) m) whereuuid = lift UUID.uuid+putPrettyAnsi' :: (PrettyV v, Stdout m) => v -> m ()+putPrettyAnsi' value = do+ supportsANSI' <- bool NoANSISupport ANSISupport <$> supportsANSI+ putPrettyAnsi putStrS supportsANSI' value+script :: Text -> Text -> Bindings (PrimFns IO) -> IO ExitCodescript fileName code bindings = dor <- fmap fst <$> runLang bindings $ interpretMany fileName $ ignoreShebang codecase r ofLeft (LangError _ (Exit n)) -> pure (exitCode n)- Left e -> do putPrettyAnsi e+ Left e -> do putPrettyAnsi' epure $ ExitFailure 1- Right x -> do putPrettyAnsi x+ Right x -> do putPrettyAnsi' xpure ExitSuccess-- TODO: restore error preCode?@@ -83,8 +88,8 @@ repl histFile _ bindings = doRight v -> do(res, newSt) <- runLang st (eval v)case res of- Left e' -> putPrettyAnsi e' >> loop st- Right v' -> putPrettyAnsi v' >> loop newSt+ Left e' -> putPrettyAnsi' e' >> loop st+ Right v' -> putPrettyAnsi' v' >> loop newStexitCode :: Int -> ExitCodeexitCode 0 = ExitSuccess@@ -170,10 +175,10 @@ replPrimFns sysArgs = fromList $ allDocs $(\err -> case err ofLangError _ (Exit _) -> pure (pure nil)LangError _ (Impossible _) -> do- putPrettyAnsi err+ putPrettyAnsi' errthrowError err_ -> do- putPrettyAnsi err+ putPrettyAnsi' errput stpure (loop action))go = dodiff --git a/radicle-lang/src/Radicle/Internal/Effects/Capabilities.hs b/radicle-repl/src/Radicle/Repl/Capabilities.hssimilarity index 98%rename from radicle-lang/src/Radicle/Internal/Effects/Capabilities.hsrename to radicle-repl/src/Radicle/Repl/Capabilities.hsindex 320009c..64fbdf7 100644--- a/radicle-lang/src/Radicle/Internal/Effects/Capabilities.hs+++ b/radicle-repl/src/Radicle/Repl/Capabilities.hs@@ -2,14 +2,14 @@---- The intent is that any set of primops may wear on their sleaves (i.e.-- constraints) what effects they do.-module Radicle.Internal.Effects.Capabilities where+module Radicle.Repl.Capabilities whereimport Protoludeimport qualified Data.ByteString as BSimport Data.Text.Prettyprint.Doc (PageWidth)import Data.Time-import Paths_radicle_lang+import Paths_radicle_replimport System.Console.ANSI (hSupportsANSI)import System.Console.Haskeline hiding (catch)import System.Directory (doesFileExist, setCurrentDirectory)diff --git a/radicle-repl/test/Spec.hs b/radicle-repl/test/Spec.hsnew file mode 100644index 0000000..cd4753f--- /dev/null+++ b/radicle-repl/test/Spec.hs@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"diff --git a/radicle-repl/test/spec/Main.hs b/radicle-repl/test/spec/Main.hsnew file mode 100644index 0000000..70c55f5--- /dev/null+++ b/radicle-repl/test/spec/Main.hs@@ -0,0 +1 @@+{-# OPTIONS_GHC -F -pgmF tasty-discover #-}diff --git a/stack.yaml b/stack.yamlindex 46d2d63..ed18a24 100644--- a/stack.yaml+++ b/stack.yaml@@ -38,6 +38,7 @@ resolver: snapshot.yamlpackages:- .- radicle-lang+- radicle-repl# Add extra deps as `packages` to `snapshot.yaml`.# extra-deps: