diff options
-rw-r--r-- | erebos-tester.cabal | 38 | ||||
-rw-r--r-- | src/Network.hs | 1 | ||||
-rw-r--r-- | src/Parser/Expr.hs | 1 | ||||
-rw-r--r-- | src/Parser/Statement.hs | 1 | ||||
-rw-r--r-- | src/Process.hs | 2 | ||||
-rw-r--r-- | src/Script/Expr/Class.hs | 61 | ||||
-rw-r--r-- | src/Test.hs | 53 |
7 files changed, 86 insertions, 71 deletions
diff --git a/erebos-tester.cabal b/erebos-tester.cabal index 4efdebd..87aa6e2 100644 --- a/erebos-tester.cabal +++ b/erebos-tester.cabal @@ -45,24 +45,26 @@ executable erebos-tester main-is: Main.hs - other-modules: Config - GDB - Network - Network.Ip - Output - Parser - Parser.Core - Parser.Expr - Parser.Statement - Paths_erebos_tester - Process - Run - Run.Monad - Test - Test.Builtins - Util - Version - Version.Git + other-modules: + Config + GDB + Network + Network.Ip + Output + Parser + Parser.Core + Parser.Expr + Parser.Statement + Paths_erebos_tester + Process + Run + Run.Monad + Script.Expr.Class + Test + Test.Builtins + Util + Version + Version.Git autogen-modules: Paths_erebos_tester diff --git a/src/Network.hs b/src/Network.hs index c841acb..6a4f41d 100644 --- a/src/Network.hs +++ b/src/Network.hs @@ -26,6 +26,7 @@ import System.FilePath import System.Process import Network.Ip +import Script.Expr.Class import Test {- diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index 9966d6f..da137af 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -39,6 +39,7 @@ import Text.Regex.TDFA qualified as RE import Text.Regex.TDFA.Text qualified as RE import Parser.Core +import Script.Expr.Class import Test reservedWords :: [ Text ] diff --git a/src/Parser/Statement.hs b/src/Parser/Statement.hs index 7765b12..97ae4fc 100644 --- a/src/Parser/Statement.hs +++ b/src/Parser/Statement.hs @@ -22,6 +22,7 @@ import Network (Network, Node) import Parser.Core import Parser.Expr import Process (Process) +import Script.Expr.Class import Test import Util diff --git a/src/Process.hs b/src/Process.hs index 376b1ba..e74d04d 100644 --- a/src/Process.hs +++ b/src/Process.hs @@ -33,7 +33,7 @@ import Network import Network.Ip import Output import Run.Monad -import Test +import Script.Expr.Class data Process = Process { procName :: ProcName diff --git a/src/Script/Expr/Class.hs b/src/Script/Expr/Class.hs new file mode 100644 index 0000000..590b99c --- /dev/null +++ b/src/Script/Expr/Class.hs @@ -0,0 +1,61 @@ +module Script.Expr.Class ( + ExprType(..), + RecordSelector(..), + ExprListUnpacker(..), + ExprEnumerator(..), +) where + +import Data.Scientific +import Data.Text (Text) +import Data.Text qualified as T +import Data.Typeable +import Data.Void + +class Typeable a => ExprType a where + textExprType :: proxy a -> Text + textExprValue :: a -> Text + + recordMembers :: [(Text, RecordSelector a)] + recordMembers = [] + + exprListUnpacker :: proxy a -> Maybe (ExprListUnpacker a) + exprListUnpacker _ = Nothing + + exprEnumerator :: proxy a -> Maybe (ExprEnumerator a) + exprEnumerator _ = Nothing + +instance ExprType Integer where + textExprType _ = T.pack "integer" + textExprValue x = T.pack (show x) + + exprEnumerator _ = Just $ ExprEnumerator enumFromTo enumFromThenTo + +instance ExprType Scientific where + textExprType _ = T.pack "number" + textExprValue x = T.pack (show x) + +instance ExprType Bool where + textExprType _ = T.pack "bool" + textExprValue True = T.pack "true" + textExprValue False = T.pack "false" + +instance ExprType Text where + textExprType _ = T.pack "string" + textExprValue x = T.pack (show x) + +instance ExprType Void where + textExprType _ = T.pack "void" + textExprValue _ = T.pack "<void>" + +instance ExprType a => ExprType [a] where + textExprType _ = "[" <> textExprType @a Proxy <> "]" + textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]" + + exprListUnpacker _ = Just $ ExprListUnpacker id (const Proxy) + + +data RecordSelector a = forall b. ExprType b => RecordSelector (a -> b) + +data ExprListUnpacker a = forall e. ExprType e => ExprListUnpacker (a -> [e]) (Proxy a -> Proxy e) + +data ExprEnumerator a = ExprEnumerator (a -> a -> [a]) (a -> a -> a -> [a]) diff --git a/src/Test.hs b/src/Test.hs index 3808186..435250e 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -18,9 +18,6 @@ module Test ( someConstValue, fromConstValue, fromSomeVarValue, textSomeVarValue, someVarValueType, - RecordSelector(..), - ExprListUnpacker(..), - ExprEnumerator(..), Expr(..), varExpr, mapExpr, eval, evalSome, evalSomeWith, Traced(..), EvalTrace, VarNameSelectors, gatherVars, AppAnnotation(..), @@ -45,13 +42,13 @@ import Data.String import Data.Text (Text) import Data.Text qualified as T import Data.Typeable -import Data.Void import Text.Regex.TDFA qualified as RE import Text.Regex.TDFA.Text qualified as RE import {-# SOURCE #-} Network import {-# SOURCE #-} Process +import Script.Expr.Class import Util data Module = Module @@ -159,52 +156,10 @@ isInternalVar (LocalVarName (VarName name)) | otherwise = False -class Typeable a => ExprType a where - textExprType :: proxy a -> Text - textExprValue :: a -> Text - - recordMembers :: [(Text, RecordSelector a)] - recordMembers = [] - - exprListUnpacker :: proxy a -> Maybe (ExprListUnpacker a) - exprListUnpacker _ = Nothing - - exprEnumerator :: proxy a -> Maybe (ExprEnumerator a) - exprEnumerator _ = Nothing - -instance ExprType Integer where - textExprType _ = T.pack "integer" - textExprValue x = T.pack (show x) - - exprEnumerator _ = Just $ ExprEnumerator enumFromTo enumFromThenTo - -instance ExprType Scientific where - textExprType _ = T.pack "number" - textExprValue x = T.pack (show x) - -instance ExprType Bool where - textExprType _ = T.pack "bool" - textExprValue True = T.pack "true" - textExprValue False = T.pack "false" - -instance ExprType Text where - textExprType _ = T.pack "string" - textExprValue x = T.pack (show x) - instance ExprType Regex where textExprType _ = T.pack "regex" textExprValue _ = T.pack "<regex>" -instance ExprType Void where - textExprType _ = T.pack "void" - textExprValue _ = T.pack "<void>" - -instance ExprType a => ExprType [a] where - textExprType _ = "[" <> textExprType @a Proxy <> "]" - textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]" - - exprListUnpacker _ = Just $ ExprListUnpacker id (const Proxy) - instance ExprType TestBlock where textExprType _ = "test block" textExprValue _ = "<test block>" @@ -327,12 +282,6 @@ someVarValueType (SomeVarValue (VarValue _ args _ :: VarValue a)) | otherwise = ExprTypeFunction args (Proxy @a) -data RecordSelector a = forall b. ExprType b => RecordSelector (a -> b) - -data ExprListUnpacker a = forall e. ExprType e => ExprListUnpacker (a -> [e]) (Proxy a -> Proxy e) - -data ExprEnumerator a = ExprEnumerator (a -> a -> [a]) (a -> a -> a -> [a]) - data Expr a where Let :: forall a b. ExprType b => SourceLine -> TypedVarName b -> Expr b -> Expr a -> Expr a |