mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-30 06:03:49 +08:00
Improve error reporting in new parser. Tests now pass.
This commit is contained in:
parent
7a3f5afee7
commit
383b6aabf5
|
@ -608,7 +608,7 @@ void parse_ll_t::parse_error_unbalancing_token(parse_token_t token)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case parse_keyword_case:
|
case parse_keyword_case:
|
||||||
this->parse_error(token, parse_error_unbalancing_case, L"'case' builtin not inside of if block");
|
this->parse_error(token, parse_error_unbalancing_case, L"'case' builtin not inside of switch block");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -712,20 +712,36 @@ bool parse_ll_t::top_node_handle_terminal_types(parse_token_t token)
|
||||||
// Failure
|
// Failure
|
||||||
if (stack_top.type == parse_token_type_string && token.type == parse_token_type_string)
|
if (stack_top.type == parse_token_type_string && token.type == parse_token_type_string)
|
||||||
{
|
{
|
||||||
// Must be different keywords. We should unify this with the 'matched' computation above.
|
// Keyword failure. We should unify this with the 'matched' computation above.
|
||||||
assert(stack_top.keyword != parse_keyword_none && stack_top.keyword != token.keyword);
|
assert(stack_top.keyword != parse_keyword_none && stack_top.keyword != token.keyword);
|
||||||
const wcstring expected = keyword_description(stack_top.keyword);
|
|
||||||
wcstring actual;
|
// Check to see which keyword we got which was considered wrong
|
||||||
if (token.keyword == parse_keyword_none)
|
switch (token.keyword)
|
||||||
{
|
{
|
||||||
// This is a random other string (not a keyword)
|
// Some keywords are only valid in certain contexts. If this cascaded all the way down through the outermost job_list, it was not in a valid context.
|
||||||
this->parse_error(token, parse_error_generic, L"Expected keyword '%ls'", expected.c_str());
|
case parse_keyword_case:
|
||||||
}
|
case parse_keyword_end:
|
||||||
else
|
case parse_keyword_else:
|
||||||
{
|
this->parse_error_unbalancing_token(token);
|
||||||
// Got a real keyword we can report
|
break;
|
||||||
const wcstring actual = (token.keyword == parse_keyword_none ? token.describe() : keyword_description(token.keyword));
|
|
||||||
this->parse_error(token, parse_error_generic, L"Expected keyword '%ls', instead got keyword '%ls'", expected.c_str(), actual.c_str());
|
case parse_keyword_none:
|
||||||
|
{
|
||||||
|
// This is a random other string (not a keyword)
|
||||||
|
const wcstring expected = keyword_description(stack_top.keyword);
|
||||||
|
this->parse_error(token, parse_error_generic, L"Expected keyword '%ls'", expected.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// Got a real keyword we can report
|
||||||
|
const wcstring actual = (token.keyword == parse_keyword_none ? token.describe() : keyword_description(token.keyword));
|
||||||
|
const wcstring expected = keyword_description(stack_top.keyword);
|
||||||
|
this->parse_error(token, parse_error_generic, L"Expected keyword '%ls', instead got keyword '%ls'", expected.c_str(), actual.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user