aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parse_productions.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-12-19 14:45:45 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-12-19 14:49:07 -0800
commit594b460ba2d8dca59a3bfd282397c5f33aa9da6f (patch)
tree6ed47cc5b6b1015e8680b7ce8cf1b526cd555a95 /src/parse_productions.cpp
parent0a6f62358b990e1f1c393ce1eb9ce4f978680866 (diff)
Allow and/or statements to attach to the if/while header
For example: if false; or true; echo hello; end will output 'hello' now. Fixes #1428
Diffstat (limited to 'src/parse_productions.cpp')
-rw-r--r--src/parse_productions.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/parse_productions.cpp b/src/parse_productions.cpp
index 4d1ec227..1a44ff48 100644
--- a/src/parse_productions.cpp
+++ b/src/parse_productions.cpp
@@ -173,7 +173,7 @@ RESOLVE(statement)
}
RESOLVE_ONLY(if_statement) = {symbol_if_clause, symbol_else_clause, symbol_end_command, symbol_arguments_or_redirections_list};
-RESOLVE_ONLY(if_clause) = { KEYWORD(parse_keyword_if), symbol_job, parse_token_type_end, symbol_job_list };
+RESOLVE_ONLY(if_clause) = { KEYWORD(parse_keyword_if), symbol_job, parse_token_type_end, symbol_andor_job_list, symbol_job_list };
RESOLVE(else_clause)
{
@@ -216,6 +216,29 @@ RESOLVE(case_item_list)
RESOLVE_ONLY(case_item) = {KEYWORD(parse_keyword_case), symbol_argument_list, parse_token_type_end, symbol_job_list};
+RESOLVE(andor_job_list)
+{
+ P list_end = {};
+ P andor_job = {symbol_job, symbol_andor_job_list};
+ P empty_line = {parse_token_type_end, symbol_andor_job_list};
+
+ if (token1.type == parse_token_type_end)
+ {
+ return &empty_line;
+ }
+ else if (token1.keyword == parse_keyword_and || token1.keyword == parse_keyword_or)
+ {
+ // Check that the argument to and/or is a string that's not help
+ // Otherwise it's either 'and --help' or a naked 'and', and not part of this list
+ if (token2.type == parse_token_type_string && !token2.is_help_argument)
+ {
+ return &andor_job;
+ }
+ }
+ // All other cases end the list
+ return &list_end;
+}
+
RESOLVE(argument_list)
{
P empty = {};
@@ -272,7 +295,7 @@ RESOLVE(block_header)
RESOLVE_ONLY(for_header) = {KEYWORD(parse_keyword_for), parse_token_type_string, KEYWORD
(parse_keyword_in), symbol_argument_list, parse_token_type_end};
-RESOLVE_ONLY(while_header) = {KEYWORD(parse_keyword_while), symbol_job, parse_token_type_end};
+RESOLVE_ONLY(while_header) = {KEYWORD(parse_keyword_while), symbol_job, parse_token_type_end, symbol_andor_job_list};
RESOLVE_ONLY(begin_header) = {KEYWORD(parse_keyword_begin)};
RESOLVE_ONLY(function_header) = {KEYWORD(parse_keyword_function), symbol_argument, symbol_argument_list, parse_token_type_end};
@@ -415,6 +438,7 @@ const production_t *parse_productions::production_for_token(parse_token_type_t n
TEST(begin_header)
TEST(function_header)
TEST(plain_statement)
+ TEST(andor_job_list)
TEST(arguments_or_redirections_list)
TEST(argument_or_redirection)
TEST(argument)