Fix parsing of for loops

* geesh/parser.scm (make-parser): When parsing for loops, make all
word-lists actual lists, and make an empty word-list with the 'in'
keyword yield an empty list rather than a reference to '$@'.
* tests/parser.scm: Update tests.
This commit is contained in:
Timothy Sample 2018-11-21 14:15:41 -05:00
parent 91cfdac307
commit 9d834d0767
2 changed files with 6 additions and 6 deletions

View File

@ -352,11 +352,11 @@ the same number of times.)"
(for-clause
(For name do-group)
: `(<sh-for> (,$2 (<sh-ref> "@")) ,$3)
: `(<sh-for> (,$2 ((<sh-quote> (<sh-ref> "@")))) ,$3)
(For name sequential-sep do-group)
: `(<sh-for> (,$2 (<sh-ref> "@")) ,$4)
: `(<sh-for> (,$2 ((<sh-quote> (<sh-ref> "@")))) ,$4)
(For name linebreak in sequential-sep do-group)
: `(<sh-for> (,$2 (<sh-ref> "@")) ,$6)
: `(<sh-for> (,$2 ()) ,$6)
(For name linebreak in wordlist sequential-sep do-group)
: `(<sh-for> (,$2 ,$5) ,$7))

View File

@ -209,17 +209,17 @@
;; For loops
(test-equal "Parses for loops over parameters without seperator"
'(<sh-for> ("x" (<sh-ref> "@"))
'(<sh-for> ("x" ((<sh-quote> (<sh-ref> "@"))))
(<sh-exec> "echo" (<sh-ref> "x")))
(parse "for x do echo $x; done"))
(test-equal "Parses for loops over parameters with seperator"
'(<sh-for> ("x" (<sh-ref> "@"))
'(<sh-for> ("x" ((<sh-quote> (<sh-ref> "@"))))
(<sh-exec> "echo" (<sh-ref> "x")))
(parse "for x; do echo $x; done"))
(test-equal "Parses for loops over parameters with \"in\""
'(<sh-for> ("x" (<sh-ref> "@"))
'(<sh-for> ("x" ())
(<sh-exec> "echo" (<sh-ref> "x")))
(parse "for x in; do echo $x; done"))