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/Core.hs | 2 +- src/Parser/Shell.hs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/Parser') diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs index f44e721..786fb2e 100644 --- a/src/Parser/Core.hs +++ b/src/Parser/Core.hs @@ -236,7 +236,7 @@ osymbol str = void $ try $ (string (TL.pack str) <* notFollowedBy operatorChar) wsymbol str = void $ try $ (string (TL.pack str) <* notFollowedBy wordChar) <* sc operatorChar :: (MonadParsec e s m, Token s ~ Char) => m (Token s) -operatorChar = satisfy $ (`elem` ['.', '+', '-', '*', '/', '=']) +operatorChar = satisfy $ (`elem` [ '.', '+', '-', '*', '/', '=', '<', '>', '|' ]) {-# INLINE operatorChar #-} localState :: TestParser a -> TestParser a 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