diff options
author | P. J. McDermott <pj@pehjota.net> | 2016-02-20 01:09:50 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-20 01:09:50 (EST) |
commit | 06268aa82c194d6be6cbba05001ba9016ba0d507 (patch) | |
tree | 129b1d3f0d5672e78be8d546b7b8f36c5c84e025 | |
parent | f98bb90a61b6bf98dfe831777482592ea4147976 (diff) | |
download | eggshell-06268aa82c194d6be6cbba05001ba9016ba0d507.zip eggshell-06268aa82c194d6be6cbba05001ba9016ba0d507.tar.gz eggshell-06268aa82c194d6be6cbba05001ba9016ba0d507.tar.bz2 |
Implement "if" construct
-rw-r--r-- | parsing/parse.sh | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/parsing/parse.sh b/parsing/parse.sh index 444ccc5..577b41e 100644 --- a/parsing/parse.sh +++ b/parsing/parse.sh @@ -212,13 +212,29 @@ pattern() if_clause() { - : TODO: Implement + if accept T_IF; then + if compound_list && expect T_THEN && compound_list; then + else_part + expect T_FI + return 0 + fi + fi return 1 } else_part() { - : TODO: Implement + while accept T_ELIF; do + if compound_list && expect T_THEN && compound_list; then + continue + fi + return 1 + done + if accept T_ELSE; then + if compound_list; then + return 0 + fi + fi return 1 } @@ -447,3 +463,6 @@ try() #try '{ foo; }' #try '( foo )' #try 'for i in 1 2 3; do stuff; done' +try 'if foo; then bar; fi' +try 'if foo; then bar; elif baz; then qux; else quux; fi' +try 'if ; then ; fi' |