diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-02-27 13:28:22 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-02-27 13:28:22 +0100 |
commit | 461a67cf2e6bea76dd7ad3e1636b68d061002e0d (patch) | |
tree | 9a6c99487d4cde2cc4cd2dbb684b0c53e747674b /src/Test.hs | |
parent | 2dc5e5ead7bc3eb908f528e9dea3a6fb8ccb6a93 (diff) |
Move ExprType to its own module
Diffstat (limited to 'src/Test.hs')
-rw-r--r-- | src/Test.hs | 53 |
1 files changed, 1 insertions, 52 deletions
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 |