From 6ee42f58d7293d810a5406d06020e1fdc9bcdaf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 4 Oct 2025 21:45:02 +0200 Subject: Redirection in shell scripts Changelog: Implemented input/output redirection in shell scripts --- src/Parser/Shell.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/Parser/Shell.hs') diff --git a/src/Parser/Shell.hs b/src/Parser/Shell.hs index ffc8cf1..b575842 100644 --- a/src/Parser/Shell.hs +++ b/src/Parser/Shell.hs @@ -71,9 +71,29 @@ parseTextArgument = lexeme $ fmap (App AnnNone (Pure T.concat) <$> foldr (liftA2 [ char ' ' >> return " " ] +parseRedirection :: TestParser (Expr ShellArgument) +parseRedirection = choice + [ do + osymbol "<" + fmap ShellRedirectStdin <$> parseTextArgument + , do + osymbol ">" + fmap (ShellRedirectStdout False) <$> parseTextArgument + , do + osymbol ">>" + fmap (ShellRedirectStdout True) <$> parseTextArgument + , do + osymbol "2>" + fmap (ShellRedirectStderr False) <$> parseTextArgument + , do + osymbol "2>>" + fmap (ShellRedirectStderr True) <$> parseTextArgument + ] + parseArgument :: TestParser (Expr ShellArgument) parseArgument = choice - [ fmap ShellArgument <$> parseTextArgument + [ parseRedirection + , fmap ShellArgument <$> parseTextArgument ] parseArguments :: TestParser (Expr [ ShellArgument ]) -- cgit v1.2.3