diff options
-rw-r--r-- | bruijn.cabal | 9 | ||||
-rw-r--r-- | package.yaml | 2 | ||||
-rw-r--r-- | src/Eval.hs | 12 | ||||
-rw-r--r-- | src/Helper.hs | 2 | ||||
-rw-r--r-- | src/Parser.hs | 7 |
5 files changed, 29 insertions, 3 deletions
diff --git a/bruijn.cabal b/bruijn.cabal index 927172e..3046549 100644 --- a/bruijn.cabal +++ b/bruijn.cabal @@ -19,8 +19,6 @@ extra-source-files: data-files: config std/Binary.bruijn - std/Byte.bruijn - std/Church.bruijn std/Combinator.bruijn std/Float.bruijn std/List.bruijn @@ -31,6 +29,7 @@ data-files: std/Pair.bruijn std/Result.bruijn std/String.bruijn + std/Unary.bruijn source-repository head type: git @@ -56,6 +55,7 @@ library , binary , bitstring , bytestring + , clock , containers , directory , filepath @@ -63,6 +63,7 @@ library , megaparsec , mtl , random + , time default-language: Haskell2010 executable bruijn @@ -81,6 +82,7 @@ executable bruijn , bitstring , bruijn , bytestring + , clock , containers , directory , filepath @@ -88,6 +90,7 @@ executable bruijn , megaparsec , mtl , random + , time default-language: Haskell2010 test-suite bruijn-test @@ -107,6 +110,7 @@ test-suite bruijn-test , bitstring , bruijn , bytestring + , clock , containers , directory , filepath @@ -114,4 +118,5 @@ test-suite bruijn-test , megaparsec , mtl , random + , time default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 536a5ee..e9d5d04 100644 --- a/package.yaml +++ b/package.yaml @@ -31,6 +31,8 @@ dependencies: - binary - bitstring - bytestring +- clock +- time - containers - directory - filepath diff --git a/src/Eval.hs b/src/Eval.hs index 5b0c9d0..95f0a34 100644 --- a/src/Eval.hs +++ b/src/Eval.hs @@ -4,6 +4,7 @@ module Eval ) where import Binary +import Control.Concurrent import Control.Exception import Control.Monad.State import qualified Control.Monad.State.Strict as StrictState @@ -13,6 +14,7 @@ import Data.Function ( on ) import Data.List import qualified Data.Map as M import Data.Maybe +import Data.Time.Clock import Helper import Parser import Paths_bruijn @@ -185,6 +187,16 @@ evalCommand inp s@(EnvState env@(Environment envDefs) conf cache) = \case $ M.union (_imported cache) (_imported cache') } pure $ EnvState (Environment $ M.union env' envDefs) conf cache'' -- import => _isRepl = False + Watch path -> + let + monitor mtime = do + threadDelay 100000 + full <- fullPath path + t <- getModificationTime full + if t > mtime + then putStrLn "reload" >> evalCommand inp s (Input full) >> monitor t + else monitor t + in getCurrentTime >>= monitor Import path namespace -> do -- TODO: Merge with Input (very similar) full <- fullPath path if full `elem` _evalPaths conf diff --git a/src/Helper.hs b/src/Helper.hs index 6f17b15..a0a563a 100644 --- a/src/Helper.hs +++ b/src/Helper.hs @@ -136,7 +136,7 @@ instance Show Expression where show (MixfixChain ms) = "\ESC[33m(\ESC[0m" <> (intercalate " " $ map show ms) <> "\ESC[33m)\ESC[0m" show (Prefix p e) = show p <> " " <> show e -data Command = Input String | Import String String | Test Expression Expression | ClearState | Time Expression +data Command = Input String | Watch String | Import String String | Test Expression Expression | ClearState | Time Expression deriving (Show) data Instruction = Define Identifier Expression [Instruction] | Evaluate Expression | Comment | Commands [Command] | ContextualInstruction Instruction String deriving (Show) diff --git a/src/Parser.hs b/src/Parser.hs index b572f9a..b82a266 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -289,6 +289,12 @@ parseInput = do path <- importPath pure $ Input $ path ++ ".bruijn" +parseWatch :: Parser Command +parseWatch = do + _ <- string ":watch" <* sc <?> "watch instruction" + path <- importPath + pure $ Watch $ path ++ ".bruijn" + parseTest :: Parser Command parseTest = do _ <- string ":test" <* sc <?> "test" @@ -328,6 +334,7 @@ parseReplLine = try parseReplDefine -- TODO: This is kinda hacky <|> ((Commands . (: [])) <$> try parseTest) <|> ((Commands . (: [])) <$> try parseInput) + <|> ((Commands . (: [])) <$> try parseWatch) <|> ((Commands . (: [])) <$> try parseImport) <|> ((Commands . (: [])) <$> try parseTime) <|> ((Commands . (: [])) <$> try parseClearState) |