From baa086bd025ce49a75d8cc9d64d24615ab960357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 16 Apr 2025 21:44:20 +0200 Subject: Shell interpreter for test script Changelog: Experimental shell interpreter --- src/Parser/Statement.hs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/Parser/Statement.hs') diff --git a/src/Parser/Statement.hs b/src/Parser/Statement.hs index 1846fdb..7c2977d 100644 --- a/src/Parser/Statement.hs +++ b/src/Parser/Statement.hs @@ -21,6 +21,7 @@ import qualified Text.Megaparsec.Char.Lexer as L import Network (Network, Node) import Parser.Core import Parser.Expr +import Parser.Shell import Process (Process) import Script.Expr import Script.Expr.Class @@ -69,6 +70,22 @@ forStatement = do <$> (unpack <$> e) <*> LambdaAbstraction tname body +shellStatement :: TestParser (Expr (TestBlock ())) +shellStatement = do + ref <- L.indentLevel + wsymbol "shell" + wsymbol "as" + pname <- newVarName + wsymbol "on" + node <- typedExpr + symbol ":" + void eol + void $ L.indentGuard scn GT ref + script <- shellScript + cont <- testBlock ref + return $ TestBlockStep EmptyTestBlock <$> + (SpawnShell pname <$> node <*> script <*> LambdaAbstraction pname cont) + exprStatement :: TestParser (Expr (TestBlock ())) exprStatement = do ref <- L.indentLevel @@ -413,22 +430,11 @@ testPacketLoss = command "packet_loss" $ PacketLoss testBlock :: Pos -> TestParser (Expr (TestBlock ())) testBlock indent = blockOf indent testStep -blockOf :: Monoid a => Pos -> TestParser a -> TestParser a -blockOf indent step = go - where - go = do - scn - pos <- L.indentLevel - optional eof >>= \case - Just _ -> return mempty - _ | pos < indent -> return mempty - | pos == indent -> mappend <$> step <*> go - | otherwise -> L.incorrectIndent EQ indent pos - testStep :: TestParser (Expr (TestBlock ())) testStep = choice [ letStatement , forStatement + , shellStatement , testLocal , testWith , testSubnet -- cgit v1.2.3