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.
This commit is contained in:
ridiculousfish 2018-01-22 13:18:34 -08:00
parent f81eef5ee1
commit 9d48c68f24
5 changed files with 9 additions and 35 deletions

View file

@ -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<parse_token_type_t> 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"},

View file

@ -213,7 +213,7 @@ bool parse_execution_context_t::job_is_simple_block(tnode_t<g::job> job_node) co
// Helper to check if an argument or redirection list has no redirections.
auto is_empty = [](tnode_t<g::arguments_or_redirections_list> lst) -> bool {
return !lst.next_in_list<g::argument_or_redirection>();
return !lst.next_in_list<g::redirection>();
};
// 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<g::arguments_or_redirections_list> args = statement.child<1>();
if (!args.try_get_child<g::argument_or_redirection, 0>()) {
if (!args.try_get_child<g::argument, 0>() && !args.try_get_child<g::redirection, 0>()) {
// 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<g::arguments_or_redir
bool errored = false;
// Get all redirection nodes underneath the statement.
while (auto arg_or_redir = node.next_in_list<g::argument_or_redirection>()) {
tnode_t<g::redirection> redirect_node = arg_or_redir.try_get_child<g::redirection, 0>();
if (!redirect_node) continue;
while (auto redirect_node = node.next_in_list<g::redirection>()) {
int source_fd = -1; // source fd
wcstring target; // file path or target fd
enum token_type redirect_type =

View file

@ -327,14 +327,9 @@ DEF_ALT(argument_list) {
DEF_ALT(arguments_or_redirections_list) {
using empty = grammar::empty;
using value = seq<argument_or_redirection, arguments_or_redirections_list>;
ALT_BODY(arguments_or_redirections_list, empty, value);
};
DEF_ALT(argument_or_redirection) {
using arg = single<argument>;
using redir = single<redirection>;
ALT_BODY(argument_or_redirection, arg, redir);
using arg = seq<argument, arguments_or_redirections_list>;
using redir = seq<redirection, arguments_or_redirections_list>;
ALT_BODY(arguments_or_redirections_list, empty, arg, redir);
};
DEF(argument) produces_single<tok_string>{BODY(argument)};

View file

@ -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)

View file

@ -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<value>();
}
default: { return production_for<empty>(); }
}
}
RESOLVE(argument_or_redirection) {
UNUSED(token2);
UNUSED(out_tag);
switch (token1.type) {
case parse_token_type_string: {
return production_for<arg>();
}
case parse_token_type_redirection: {
case parse_token_type_redirection:
return production_for<redir>();
}
default: { return NO_PRODUCTION; }
default:
return production_for<empty>();
}
}
@ -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)