From 06268aa82c194d6be6cbba05001ba9016ba0d507 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 20 Feb 2016 01:09:50 -0500 Subject: Implement "if" construct --- (limited to 'parsing') 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' -- cgit v0.9.1