From 9d48c68f244503cf4065871b37e579e9bd006e00 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 22 Jan 2018 13:18:34 -0800 Subject: [PATCH] Remove argument_or_redirection type This was a symbol that represented either an argument or a redirection. This was only used as part of argument_or_redirection_list. It's simpler to just have these types be alternatives in the list type. --- src/parse_constants.h | 2 -- src/parse_execution.cpp | 9 +++------ src/parse_grammar.h | 11 +++-------- src/parse_grammar_elements.inc | 1 - src/parse_productions.cpp | 21 +++------------------ 5 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/parse_constants.h b/src/parse_constants.h index afeb81843..ca6e739e4 100644 --- a/src/parse_constants.h +++ b/src/parse_constants.h @@ -37,7 +37,6 @@ enum parse_token_type_t { symbol_decorated_statement, symbol_plain_statement, symbol_arguments_or_redirections_list, - symbol_argument_or_redirection, symbol_andor_job_list, symbol_argument_list, // Freestanding argument lists are parsed from the argument list supplied to 'complete -a'. @@ -81,7 +80,6 @@ const enum_map token_enum_map[] = { {symbol_andor_job_list, L"symbol_andor_job_list"}, {symbol_argument, L"symbol_argument"}, {symbol_argument_list, L"symbol_argument_list"}, - {symbol_argument_or_redirection, L"symbol_argument_or_redirection"}, {symbol_arguments_or_redirections_list, L"symbol_arguments_or_redirections_list"}, {symbol_begin_header, L"symbol_begin_header"}, {symbol_block_header, L"symbol_block_header"}, diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 8a01c056c..93cc240a2 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -213,7 +213,7 @@ bool parse_execution_context_t::job_is_simple_block(tnode_t job_node) co // Helper to check if an argument or redirection list has no redirections. auto is_empty = [](tnode_t lst) -> bool { - return !lst.next_in_list(); + return !lst.next_in_list(); }; // Check if we're a block statement with redirections. We do it this obnoxious way to preserve @@ -793,7 +793,7 @@ parse_execution_result_t parse_execution_context_t::populate_plain_process( if (!has_command && get_decoration(statement) == parse_statement_decoration_none) { // Implicit cd requires an empty argument and redirection list. tnode_t args = statement.child<1>(); - if (!args.try_get_child()) { + if (!args.try_get_child() && !args.try_get_child()) { // Ok, no arguments or redirections; check to see if the first argument is a // directory. wcstring implicit_cd_path; @@ -905,10 +905,7 @@ bool parse_execution_context_t::determine_io_chain(tnode_t()) { - tnode_t redirect_node = arg_or_redir.try_get_child(); - if (!redirect_node) continue; - + while (auto redirect_node = node.next_in_list()) { int source_fd = -1; // source fd wcstring target; // file path or target fd enum token_type redirect_type = diff --git a/src/parse_grammar.h b/src/parse_grammar.h index edca76448..c6ea29dee 100644 --- a/src/parse_grammar.h +++ b/src/parse_grammar.h @@ -327,14 +327,9 @@ DEF_ALT(argument_list) { DEF_ALT(arguments_or_redirections_list) { using empty = grammar::empty; - using value = seq; - ALT_BODY(arguments_or_redirections_list, empty, value); -}; - -DEF_ALT(argument_or_redirection) { - using arg = single; - using redir = single; - ALT_BODY(argument_or_redirection, arg, redir); + using arg = seq; + using redir = seq; + ALT_BODY(arguments_or_redirections_list, empty, arg, redir); }; DEF(argument) produces_single{BODY(argument)}; diff --git a/src/parse_grammar_elements.inc b/src/parse_grammar_elements.inc index 6f38cf99d..4142db65f 100644 --- a/src/parse_grammar_elements.inc +++ b/src/parse_grammar_elements.inc @@ -22,7 +22,6 @@ ELEM(decorated_statement) ELEM(plain_statement) ELEM(argument_list) ELEM(arguments_or_redirections_list) -ELEM(argument_or_redirection) ELEM(argument) ELEM(redirection) ELEM(optional_background) diff --git a/src/parse_productions.cpp b/src/parse_productions.cpp index 20dd556a6..28d371d51 100644 --- a/src/parse_productions.cpp +++ b/src/parse_productions.cpp @@ -301,25 +301,11 @@ RESOLVE(arguments_or_redirections_list) { switch (token1.type) { case parse_token_type_string: - case parse_token_type_redirection: { - return production_for(); - } - default: { return production_for(); } - } -} - -RESOLVE(argument_or_redirection) { - UNUSED(token2); - UNUSED(out_tag); - - switch (token1.type) { - case parse_token_type_string: { return production_for(); - } - case parse_token_type_redirection: { + case parse_token_type_redirection: return production_for(); - } - default: { return NO_PRODUCTION; } + default: + return production_for(); } } @@ -380,7 +366,6 @@ const production_element_t *parse_productions::production_for_token(parse_token_ TEST(plain_statement) TEST(andor_job_list) TEST(arguments_or_redirections_list) - TEST(argument_or_redirection) TEST(argument) TEST(redirection) TEST(optional_background)