Flatten AST form for pipelines

* geesh/parser.scm (make-parser): Splice in commands to keep
'<sh-pipeline>' flat.
* tests/parser.scm: Adjust and add tests accordingly.
This commit is contained in:
Timothy Sample 2018-07-19 01:28:43 -04:00
parent c79cea756d
commit 2d61e91b27
2 changed files with 18 additions and 5 deletions

View File

@ -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)
`(<sh-pipeline> ,@(reverse! $1)))
(Bang pipe-sequence)
: `(<sh-not> ,$2))
: `(<sh-not> ,(if (null? (cdr $2))
(car $2)
`(<sh-pipeline> ,@(reverse! $2)))))
(pipe-sequence
(command)
: `(,$1)
(pipe-sequence PIPE linebreak command)
: `(<sh-pipeline> ,(append $1 (list $4))))
: (cons $4 $1))
(command
(simple-command)

View File

@ -123,11 +123,20 @@
(<sh-exec> "echo" "baz"))
(parse "echo foo || echo bar && echo baz"))
(test-equal "Parses negations"
'(<sh-not> (<sh-exec> "echo" "foo"))
(parse "! echo foo"))
(test-equal "Parses negated pipelines"
'(<sh-not> (<sh-pipeline> (<sh-exec> "echo" "foo")
(<sh-exec> "echo" "bar")))
(parse "! echo foo | echo bar"))
;; Pipelines
(test-equal "Parses pipelines"
'(<sh-pipeline> ((<sh-exec> "cat" "foo.txt")
(<sh-exec> "grep" "bar")))
'(<sh-pipeline> (<sh-exec> "cat" "foo.txt")
(<sh-exec> "grep" "bar"))
(parse "cat foo.txt | grep bar"))
;; Brace groups and subshells