summaryrefslogtreecommitdiffstats
path: root/parsing
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-20 02:11:59 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-20 02:11:59 (EST)
commita872bf87e2949019e457242a3099a22087ef79e9 (patch)
treecb9c1e84d28190893d986ba99568e6031352717a /parsing
parent899b2d00b7e26699c68d8b73cf6e85ce755a28b4 (diff)
downloadeggshell-a872bf87e2949019e457242a3099a22087ef79e9.zip
eggshell-a872bf87e2949019e457242a3099a22087ef79e9.tar.gz
eggshell-a872bf87e2949019e457242a3099a22087ef79e9.tar.bz2
Implement "case" construct
Diffstat (limited to 'parsing')
-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'