mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 22:14:53 +00:00
Make the argument list parsing in complete -a robust against weird
tokens like &. Improve the error message when such tokens are found.
This commit is contained in:
parent
62b3ed17ba
commit
42166be22e
1 changed files with 16 additions and 6 deletions
|
@ -274,7 +274,7 @@ wcstring keyword_description(parse_keyword_t k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static wcstring token_type_user_presentable_description(parse_token_type_t type, parse_keyword_t keyword)
|
static wcstring token_type_user_presentable_description(parse_token_type_t type, parse_keyword_t keyword = parse_keyword_none)
|
||||||
{
|
{
|
||||||
if (keyword != parse_keyword_none)
|
if (keyword != parse_keyword_none)
|
||||||
{
|
{
|
||||||
|
@ -287,6 +287,9 @@ static wcstring token_type_user_presentable_description(parse_token_type_t type,
|
||||||
case symbol_statement:
|
case symbol_statement:
|
||||||
return L"a command";
|
return L"a command";
|
||||||
|
|
||||||
|
case symbol_argument:
|
||||||
|
return L"an argument";
|
||||||
|
|
||||||
case parse_token_type_string:
|
case parse_token_type_string:
|
||||||
return L"a string";
|
return L"a string";
|
||||||
|
|
||||||
|
@ -754,8 +757,6 @@ void parse_ll_t::parse_error_unbalancing_token(parse_token_t token)
|
||||||
this->fatal_errored = true;
|
this->fatal_errored = true;
|
||||||
if (this->should_generate_error_messages)
|
if (this->should_generate_error_messages)
|
||||||
{
|
{
|
||||||
assert(token.type == parse_token_type_string);
|
|
||||||
assert(token.keyword == parse_keyword_end || token.keyword == parse_keyword_else || token.keyword == parse_keyword_case);
|
|
||||||
switch (token.keyword)
|
switch (token.keyword)
|
||||||
{
|
{
|
||||||
case parse_keyword_end:
|
case parse_keyword_end:
|
||||||
|
@ -771,8 +772,17 @@ void parse_ll_t::parse_error_unbalancing_token(parse_token_t token)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unexpected token %ls passed to %s\n", token.describe().c_str(), __FUNCTION__);
|
// At the moment, this case should only be hit if you parse a freestanding_argument_list
|
||||||
PARSER_DIE();
|
// For example, 'complete -c foo -a 'one & three'
|
||||||
|
// Hackish error message for that case
|
||||||
|
if (! symbol_stack.empty() && symbol_stack.back().type == symbol_freestanding_argument_list)
|
||||||
|
{
|
||||||
|
this->parse_error(token, parse_error_generic, L"Expected %ls, but found %ls", token_type_user_presentable_description(symbol_argument).c_str(), token.user_presentable_description().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->parse_error(token, parse_error_generic, L"Did not expect %ls", token.user_presentable_description().c_str());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue