Skip to content

Commit e764355

Browse files
Allow redirection and piping with aliases (#1983)
* Redo Co-authored-by: Ana Pantilie <ana.pantilie95@gmail.com> * Pass unit tests * Test attempt * Tests * Stylish * Addressed comment: add test for >> Co-authored-by: Ana Pantilie <ana.pantilie95@gmail.com>
1 parent 909c4e2 commit e764355

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

kore/src/Kore/Repl/Parser.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ commandParser = commandParser0 eof
8080

8181
commandParser0 :: Parser () -> Parser ReplCommand
8282
commandParser0 endParser =
83-
alias <|> logCommand <|> commandParserExceptAlias endParser <|> tryAlias
83+
alias <|> logCommand <|> commandParserExceptAlias endParser
8484

8585
commandParserExceptAlias :: Parser () -> Parser ReplCommand
8686
commandParserExceptAlias endParser = do
@@ -121,6 +121,7 @@ nonRecursiveCommand =
121121
, loadScript
122122
, proofStatus
123123
, exit
124+
, tryAlias
124125
]
125126

126127
pipeWith
@@ -407,7 +408,7 @@ tryAlias :: Parser ReplCommand
407408
tryAlias = do
408409
name <- some (noneOf [' ']) <* Char.space
409410
arguments <- many
410-
(QuotedArgument <$> quotedWord <|> SimpleArgument <$> wordWithout "")
411+
(QuotedArgument <$> quotedWord <|> SimpleArgument <$> wordWithout "|>")
411412
return . TryAlias $ ReplAlias { name, arguments }
412413

413414
infixr 2 <$$>

kore/test/Test/Kore/Repl/Parser.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ test_replParser =
7070
, loadScriptTests `tests` "load file"
7171
, initScriptTests `testsScript` "repl script"
7272
, aliasesWithArgs `tests` "aliases with arguments"
73+
, aliasRedirectionTests `tests` "alias with redirection"
7374
, proofStatus `tests` "proof-status"
7475
, logTests `tests` "log"
7576
, debugAttemptEquationTests `tests` "debug-attempt-equation"
@@ -454,6 +455,38 @@ aliasesWithArgs =
454455
alias name arguments command =
455456
Alias $ AliasDefinition { name, arguments, command }
456457

458+
aliasRedirectionTests :: [ParserTest ReplCommand]
459+
aliasRedirectionTests =
460+
[ parsesTo_
461+
"myAlias > file"
462+
( Redirect
463+
( TryAlias
464+
ReplAlias {name = "myAlias", arguments = []}
465+
)
466+
"file"
467+
)
468+
, parsesTo_
469+
"myAlias >> file"
470+
( AppendTo
471+
( TryAlias
472+
ReplAlias {name = "myAlias", arguments = []}
473+
)
474+
"file"
475+
)
476+
, parsesTo_
477+
"myAlias | script > file"
478+
( Redirect
479+
( Pipe
480+
( TryAlias
481+
ReplAlias {name = "myAlias", arguments = []}
482+
)
483+
"script"
484+
[]
485+
)
486+
"file"
487+
)
488+
]
489+
457490
loadScriptTests :: [ParserTest ReplCommand]
458491
loadScriptTests =
459492
[ "load file" `parsesTo_` LoadScript "file"

0 commit comments

Comments
 (0)