summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Parser/Shell.hs25
-rw-r--r--test/asset/shell/expansion.et6
-rw-r--r--test/script/shell.et3
3 files changed, 28 insertions, 6 deletions
diff --git a/src/Parser/Shell.hs b/src/Parser/Shell.hs
index a09eb43..8c8ef46 100644
--- a/src/Parser/Shell.hs
+++ b/src/Parser/Shell.hs
@@ -107,12 +107,25 @@ parseArguments = do
parseCommand :: TestParser (Expr ShellCommand)
parseCommand = label "shell statement" $ do
line <- getSourceLine
- command <- parseTextArgument
- args <- parseArguments
- return $ ShellCommand
- <$> command
- <*> args
- <*> pure line
+ choice
+ [ do
+ args <- expressionExpansion "shell command" <* sc
+ args' <- parseArguments
+ return $ commandFromArgLists line <$> args <*> args'
+ , do
+ command <- parseTextArgument
+ args <- parseArguments
+ return $ ShellCommand
+ <$> command
+ <*> args
+ <*> pure line
+ ]
+
+ where
+ commandFromArgLists line (ShellArguments (ShellArgument cmd : args)) (ShellArguments args') =
+ ShellCommand cmd (ShellArguments (args ++ args')) line
+ commandFromArgLists line (ShellArguments args) (ShellArguments args') =
+ ShellCommand "" (ShellArguments (args ++ args')) line
parsePipeline :: Maybe (Expr ShellPipeline) -> TestParser (Expr ShellPipeline)
parsePipeline mbupper = do
diff --git a/test/asset/shell/expansion.et b/test/asset/shell/expansion.et
index 050efba..3f318ab 100644
--- a/test/asset/shell/expansion.et
+++ b/test/asset/shell/expansion.et
@@ -6,8 +6,14 @@ test Test:
let num = 4.5
let list = [ "a b", "c d", "e", "f" ]
let ilist = [ 1 .. 5 ]
+ let cmd = "echo"
+ let cmdlist = [ "echo", "w", "x y", " z " ]
+ let special = [ "<", ">", "| &", ";" ]
shell on n as sh:
echo A $str B $int $num C
echo D $list E
echo F $ilist G
+ $cmd H I
+ $cmdlist J
+ $cmdlist K $ilist L $int M $special N
diff --git a/test/script/shell.et b/test/script/shell.et
index 4dca4a2..36eaff7 100644
--- a/test/script/shell.et
+++ b/test/script/shell.et
@@ -194,6 +194,9 @@ test ShellVariableExpansion:
expect /child-stdout sh A some string B 2 4.5 C/
expect /child-stdout sh D a b c d e f E/
expect /child-stdout sh F 1 2 3 4 5 G/
+ expect /child-stdout sh H I/
+ expect /child-stdout sh w x y z J/
+ expect /child-stdout sh w x y z K 1 2 3 4 5 L 2 M < > \| \& \; N/
expect /run-test-result Test done/
expect /run-done 1 1 0 0/
flush