diff --git a/geesh/parser.scm b/geesh/parser.scm index 8a81845..246b0a1 100644 --- a/geesh/parser.scm +++ b/geesh/parser.scm @@ -281,15 +281,19 @@ the same number of times.)" (pipeline (pipe-sequence) - : (if (null? (cdr $1)) (car $1) $1) + : (if (null? (cdr $1)) + (car $1) + `( ,@(reverse! $1))) (Bang pipe-sequence) - : `( ,$2)) + : `( ,(if (null? (cdr $2)) + (car $2) + `( ,@(reverse! $2))))) (pipe-sequence (command) : `(,$1) (pipe-sequence PIPE linebreak command) - : `( ,(append $1 (list $4)))) + : (cons $4 $1)) (command (simple-command) diff --git a/tests/parser.scm b/tests/parser.scm index cf0615e..11730f4 100644 --- a/tests/parser.scm +++ b/tests/parser.scm @@ -123,11 +123,20 @@ ( "echo" "baz")) (parse "echo foo || echo bar && echo baz")) +(test-equal "Parses negations" + '( ( "echo" "foo")) + (parse "! echo foo")) + +(test-equal "Parses negated pipelines" + '( ( ( "echo" "foo") + ( "echo" "bar"))) + (parse "! echo foo | echo bar")) + ;; Pipelines (test-equal "Parses pipelines" - '( (( "cat" "foo.txt") - ( "grep" "bar"))) + '( ( "cat" "foo.txt") + ( "grep" "bar")) (parse "cat foo.txt | grep bar")) ;; Brace groups and subshells