Support elif.

This commit is contained in:
Jan Nieuwenhuizen 2018-11-10 10:59:08 +01:00
parent 90325b22a2
commit 9a96816b5d
8 changed files with 35 additions and 0 deletions

View File

@ -45,6 +45,11 @@ tests="
10-if
10-if-false
10-if-word-variable
10-if-multiple
10-if-else
10-else-multiple
10-if-elif
11-for
11-for-split-sequence

View File

@ -350,6 +350,8 @@
(('substitution o) `(substitution ,(transform o)))
(('if-clause expr then) `(if-clause ,(transform expr) ,(transform then)))
(('if-clause expr then else) `(if-clause ,(transform expr) ,(transform then) ,(transform else)))
(('elif-part expr then) `(if-clause ,(transform expr) ,(transform then)))
(('elif-part expr then else) `(if-clause ,(transform expr) ,(transform then) ,(transform else)))
(('then-part o ...) `(begin ,@(map transform o)))
(('else-part o ...) `(begin ,@(map transform o)))
(('word 'singlequotes) "")

6
test/10-else-multiple.sh Normal file
View File

@ -0,0 +1,6 @@
if false; then
:
else
echo one
echo two
fi

View File

@ -0,0 +1,2 @@
one
two

8
test/10-if-elif.sh Normal file
View File

@ -0,0 +1,8 @@
if false; then
exit 1
elif false; then
exit 2
else
exit 0
fi
exit 1

6
test/10-if-else.sh Normal file
View File

@ -0,0 +1,6 @@
if false; then
exit 1
else
exit 0
fi
exit 1

4
test/10-if-multiple.sh Normal file
View File

@ -0,0 +1,4 @@
if true; then
echo one
echo two
fi

View File

@ -0,0 +1,2 @@
one
two