aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse_tree.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-03-27 11:34:18 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-03-27 11:34:18 -0700
commit42166be22e5bc2ab16d8e9e895696d325aef8246 (patch)
tree480797d0f3e546dca062bf1b38be17aea585ba4e /parse_tree.cpp
parent62b3ed17ba42150e1107b87b0e719cf793ae8d0f (diff)
Make the argument list parsing in complete -a robust against weird
tokens like &. Improve the error message when such tokens are found.
Diffstat (limited to 'parse_tree.cpp')
-rw-r--r--parse_tree.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/parse_tree.cpp b/parse_tree.cpp
index b080cc43..d8aefaff 100644
--- a/parse_tree.cpp
+++ b/parse_tree.cpp
@@ -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)
{
@@ -287,6 +287,9 @@ static wcstring token_type_user_presentable_description(parse_token_type_t type,
case symbol_statement:
return L"a command";
+ case symbol_argument:
+ return L"an argument";
+
case parse_token_type_string:
return L"a string";
@@ -301,7 +304,7 @@ static wcstring token_type_user_presentable_description(parse_token_type_t type,
case parse_token_type_end:
return L"end of the statement";
-
+
default:
return format_string(L"a %ls", token_type_description(type).c_str());
}
@@ -754,8 +757,6 @@ void parse_ll_t::parse_error_unbalancing_token(parse_token_t token)
this->fatal_errored = true;
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)
{
case parse_keyword_end:
@@ -771,8 +772,17 @@ void parse_ll_t::parse_error_unbalancing_token(parse_token_t token)
break;
default:
- fprintf(stderr, "Unexpected token %ls passed to %s\n", token.describe().c_str(), __FUNCTION__);
- PARSER_DIE();
+ // At the moment, this case should only be hit if you parse a freestanding_argument_list
+ // 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;
}
}