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:
parent
c79cea756d
commit
2d61e91b27
|
@ -281,15 +281,19 @@ the same number of times.)"
|
||||||
|
|
||||||
(pipeline
|
(pipeline
|
||||||
(pipe-sequence)
|
(pipe-sequence)
|
||||||
: (if (null? (cdr $1)) (car $1) $1)
|
: (if (null? (cdr $1))
|
||||||
|
(car $1)
|
||||||
|
`(<sh-pipeline> ,@(reverse! $1)))
|
||||||
(Bang pipe-sequence)
|
(Bang pipe-sequence)
|
||||||
: `(<sh-not> ,$2))
|
: `(<sh-not> ,(if (null? (cdr $2))
|
||||||
|
(car $2)
|
||||||
|
`(<sh-pipeline> ,@(reverse! $2)))))
|
||||||
|
|
||||||
(pipe-sequence
|
(pipe-sequence
|
||||||
(command)
|
(command)
|
||||||
: `(,$1)
|
: `(,$1)
|
||||||
(pipe-sequence PIPE linebreak command)
|
(pipe-sequence PIPE linebreak command)
|
||||||
: `(<sh-pipeline> ,(append $1 (list $4))))
|
: (cons $4 $1))
|
||||||
|
|
||||||
(command
|
(command
|
||||||
(simple-command)
|
(simple-command)
|
||||||
|
|
|
@ -123,11 +123,20 @@
|
||||||
(<sh-exec> "echo" "baz"))
|
(<sh-exec> "echo" "baz"))
|
||||||
(parse "echo foo || echo bar && 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
|
;; Pipelines
|
||||||
|
|
||||||
(test-equal "Parses pipelines"
|
(test-equal "Parses pipelines"
|
||||||
'(<sh-pipeline> ((<sh-exec> "cat" "foo.txt")
|
'(<sh-pipeline> (<sh-exec> "cat" "foo.txt")
|
||||||
(<sh-exec> "grep" "bar")))
|
(<sh-exec> "grep" "bar"))
|
||||||
(parse "cat foo.txt | grep bar"))
|
(parse "cat foo.txt | grep bar"))
|
||||||
|
|
||||||
;; Brace groups and subshells
|
;; Brace groups and subshells
|
||||||
|
|
Loading…
Reference in New Issue