From a872bf87e2949019e457242a3099a22087ef79e9 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 20 Feb 2016 02:11:59 -0500 Subject: Implement "case" construct --- (limited to 'parsing') diff --git a/parsing/parse.sh b/parsing/parse.sh index 93699f8..5ac622d 100644 --- a/parsing/parse.sh +++ b/parsing/parse.sh @@ -176,37 +176,70 @@ wordlist() case_clause() { - : TODO: Implement + if accept T_CASE; then + if expect T_WORD && linebreak && expect T_IN && linebreak; then + case_list || case_list_ns + expect T_ESAC + return 0 + fi + fi return 1 } case_list_ns() { - : TODO: Implement + if case_list && case_item_ns; then + return 0 + elif case_item_ns; then + return 0 + fi return 1 } case_list() { - : TODO: Implement + if case_item; then + while case_item; do + : + done + return 0 + fi return 1 } case_item_ns() { - : TODO: Implement + accept T_LPAREN + if pattern && expect RPAREN; then + compound_list + if linebreak; then + return 0 + fi + fi return 1 } case_item() { - : TODO: Implement + accept T_LPAREN + if pattern && expect T_RPAREN; then + if compound_list || linebreak; then + if expect T_DSEMI && linebreak; then + return 0 + fi + fi + fi return 1 } pattern() { - : TODO: Implement + if accept T_CMDNAME; then + while accept T_PIPE; do + expect T_WORD + done + return 0 + fi return 1 } @@ -486,3 +519,4 @@ try() #try 'while foo; do bar; done' #try 'while ; do ; done' #try 'foo(){ bar; }' +try 'case foo in bar) baz;; (qux) quux;; quux);; esac' -- cgit v0.9.1