summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-10-08 22:29:35 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-10-08 22:29:35 +0200
commited4dcb61f8a13a3cbfee1c30ea2cb12b5fd3c1ec (patch)
tree221e97031660dd1ce2a7d1bde16a28e551037b15
parentff745aeb332e29566814cec87090f1188bca83ec (diff)
Node command to declare new node variable
-rw-r--r--src/Main.hs4
-rw-r--r--src/Parser.hs6
-rw-r--r--src/Test.hs1
3 files changed, 11 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs
index fda0bb9..494b028 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -317,6 +317,10 @@ evalSteps = mapM_ $ \case
value <- eval expr
withVar name value $ evalSteps inner
+ DeclNode name@(TypedVarName vname) inner -> do
+ createNode name $ \node -> do
+ withVar vname node $ evalSteps inner
+
Spawn (TypedVarName vname@(VarName tname)) nname inner -> do
either createNode ((>>=) . eval) nname $ \node -> do
let pname = ProcName tname
diff --git a/src/Parser.hs b/src/Parser.hs
index 7773bae..a33b429 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -476,6 +476,11 @@ testLocal = do
indent <- L.indentGuard scn GT ref
localState $ testBlock indent
+testNode :: TestParser [TestStep]
+testNode = command "node" $ DeclNode
+ <$> param ""
+ <*> innerBlock
+
testSpawn :: TestParser [TestStep]
testSpawn = command "spawn" $ Spawn
<$> param "as"
@@ -528,6 +533,7 @@ testStep :: TestParser [TestStep]
testStep = choice
[ letStatement
, testLocal
+ , testNode
, testSpawn
, testSend
, testExpect
diff --git a/src/Test.hs b/src/Test.hs
index 5a45930..6b04fac 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -33,6 +33,7 @@ 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]
| Send (Expr Process) (Expr Text)
| Expect SourceLine (Expr Process) (Expr Regex) [TypedVarName Text] [TestStep]