diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-11-19 17:05:19 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-11-19 20:26:08 +0100 |
commit | 7971bd30d86eb292a65bffe90eba18f8428cd0aa (patch) | |
tree | 6de9812d238f69b49c43d3037bed414185cc67a9 /src/Test.hs | |
parent | 20a510e824a52526d9b5e48497dbf52df4c2d7f6 (diff) |
Network expression type and context
Diffstat (limited to 'src/Test.hs')
-rw-r--r-- | src/Test.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Test.hs b/src/Test.hs index 836992c..16936bb 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -34,8 +34,8 @@ data Test = Test } data TestStep = forall a. ExprType a => Let SourceLine VarName (Expr a) [TestStep] - | DeclNode (TypedVarName Node) [TestStep] - | Spawn (TypedVarName Process) (Either (TypedVarName Node) (Expr Node)) [TestStep] + | DeclNode (TypedVarName Node) (Expr Network) [TestStep] + | Spawn (TypedVarName Process) (Either (TypedVarName Node) (Either (Expr Network) (Expr Node))) [TestStep] | Send (Expr Process) (Expr Text) | Expect SourceLine (Expr Process) (Expr Regex) [TypedVarName Text] [TestStep] | Guard SourceLine (Expr Bool) @@ -50,12 +50,13 @@ newtype SourceLine = SourceLine Text class MonadFail m => MonadEval m where lookupVar :: VarName -> m SomeVarValue + rootNetwork :: m Network newtype VarName = VarName Text deriving (Eq, Ord) -newtype TypedVarName a = TypedVarName VarName +newtype TypedVarName a = TypedVarName { fromTypedVarName :: VarName } deriving (Eq, Ord) textVarName :: VarName -> Text @@ -118,6 +119,7 @@ data Expr a where Regex :: [Expr Regex] -> Expr Regex UnOp :: (b -> a) -> Expr b -> Expr a BinOp :: (b -> c -> a) -> Expr b -> Expr c -> Expr a + RootNetwork :: Expr Network eval :: MonadEval m => Expr a -> m a eval (Variable name) = fromSomeVarValue name =<< lookupVar name @@ -130,6 +132,7 @@ eval (Regex xs) = mapM eval xs >>= \case Right re -> return re eval (UnOp f x) = f <$> eval x eval (BinOp f x y) = f <$> eval x <*> eval y +eval (RootNetwork) = rootNetwork gatherVars :: forall a m. MonadEval m => Expr a -> m [(VarName, SomeVarValue)] gatherVars = fmap (uniqOn fst . sortOn fst) . helper @@ -141,6 +144,7 @@ gatherVars = fmap (uniqOn fst . sortOn fst) . helper helper (Regex es) = concat <$> mapM helper es helper (UnOp _ e) = helper e helper (BinOp _ e f) = (++) <$> helper e <*> helper f + helper (RootNetwork) = return [] data Regex = RegexCompiled Text RE.Regex |