summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parsing/parse.sh46
1 files changed, 40 insertions, 6 deletions
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'