mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 04:41:14 -03:00
Remove special && and || error detection
Soon these will no longer be errors.
This commit is contained in:
@@ -3624,9 +3624,6 @@ static void test_new_parser_errors() {
|
|||||||
|
|
||||||
{L"case", parse_error_unbalancing_case},
|
{L"case", parse_error_unbalancing_case},
|
||||||
{L"if true ; case ; end", parse_error_unbalancing_case},
|
{L"if true ; case ; end", parse_error_unbalancing_case},
|
||||||
|
|
||||||
{L"foo || bar", parse_error_double_pipe},
|
|
||||||
{L"foo && bar", parse_error_double_background},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof tests / sizeof *tests; i++) {
|
for (size_t i = 0; i < sizeof tests / sizeof *tests; i++) {
|
||||||
@@ -3742,9 +3739,7 @@ static void test_error_messages() {
|
|||||||
{L"echo \"foo\"$\"bar\"", ERROR_NO_VAR_NAME},
|
{L"echo \"foo\"$\"bar\"", ERROR_NO_VAR_NAME},
|
||||||
{L"echo foo $ bar", ERROR_NO_VAR_NAME},
|
{L"echo foo $ bar", ERROR_NO_VAR_NAME},
|
||||||
{L"echo foo$(foo)bar", ERROR_BAD_VAR_SUBCOMMAND1},
|
{L"echo foo$(foo)bar", ERROR_BAD_VAR_SUBCOMMAND1},
|
||||||
{L"echo \"foo$(foo)bar\"", ERROR_BAD_VAR_SUBCOMMAND1},
|
{L"echo \"foo$(foo)bar\"", ERROR_BAD_VAR_SUBCOMMAND1}};
|
||||||
{L"echo foo || echo bar", ERROR_BAD_OR},
|
|
||||||
{L"echo foo && echo bar", ERROR_BAD_AND}};
|
|
||||||
|
|
||||||
parse_error_list_t errors;
|
parse_error_list_t errors;
|
||||||
for (size_t i = 0; i < sizeof error_tests / sizeof *error_tests; i++) {
|
for (size_t i = 0; i < sizeof error_tests / sizeof *error_tests; i++) {
|
||||||
|
|||||||
@@ -183,10 +183,7 @@ enum parse_error_code_t {
|
|||||||
|
|
||||||
parse_error_unbalancing_end, // end outside of block
|
parse_error_unbalancing_end, // end outside of block
|
||||||
parse_error_unbalancing_else, // else outside of if
|
parse_error_unbalancing_else, // else outside of if
|
||||||
parse_error_unbalancing_case, // case outside of switch
|
parse_error_unbalancing_case // case outside of switch
|
||||||
|
|
||||||
parse_error_double_pipe, // foo || bar, has special error message
|
|
||||||
parse_error_double_background // foo && bar, has special error message
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { PARSER_TEST_ERROR = 1, PARSER_TEST_INCOMPLETE = 2 };
|
enum { PARSER_TEST_ERROR = 1, PARSER_TEST_INCOMPLETE = 2 };
|
||||||
@@ -289,12 +286,6 @@ void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt);
|
|||||||
/// Error issued on $.
|
/// Error issued on $.
|
||||||
#define ERROR_NO_VAR_NAME _(L"Expected a variable name after this $.")
|
#define ERROR_NO_VAR_NAME _(L"Expected a variable name after this $.")
|
||||||
|
|
||||||
/// Error on ||.
|
|
||||||
#define ERROR_BAD_OR _(L"Unsupported use of '||'. In fish, please use 'COMMAND; or COMMAND'.")
|
|
||||||
|
|
||||||
/// Error on &&.
|
|
||||||
#define ERROR_BAD_AND _(L"Unsupported use of '&&'. In fish, please use 'COMMAND; and COMMAND'.")
|
|
||||||
|
|
||||||
/// Error on foo=bar.
|
/// Error on foo=bar.
|
||||||
#define ERROR_BAD_EQUALS_IN_COMMAND5 \
|
#define ERROR_BAD_EQUALS_IN_COMMAND5 \
|
||||||
_(L"Unsupported use of '='. To run '%ls' with a modified environment, please use 'env " \
|
_(L"Unsupported use of '='. To run '%ls' with a modified environment, please use 'env " \
|
||||||
|
|||||||
@@ -674,37 +674,8 @@ void parse_ll_t::parse_error_failed_production(struct parse_stack_element_t &sta
|
|||||||
parse_token_t token) {
|
parse_token_t token) {
|
||||||
fatal_errored = true;
|
fatal_errored = true;
|
||||||
if (this->should_generate_error_messages) {
|
if (this->should_generate_error_messages) {
|
||||||
bool done = false;
|
const wcstring expected = stack_elem.user_presentable_description();
|
||||||
|
this->parse_error_unexpected_token(expected.c_str(), token);
|
||||||
// Check for ||.
|
|
||||||
if (token.type == parse_token_type_pipe && token.source_start > 0) {
|
|
||||||
// Here we wanted a statement and instead got a pipe. See if this is a double pipe: foo
|
|
||||||
// || bar. If so, we have a special error message.
|
|
||||||
const parse_node_t *prev_pipe = nodes.find_node_matching_source_location(
|
|
||||||
parse_token_type_pipe, token.source_start - 1, NULL);
|
|
||||||
if (prev_pipe != NULL) {
|
|
||||||
// The pipe of the previous job abuts our current token. So we have ||.
|
|
||||||
this->parse_error(token, parse_error_double_pipe, ERROR_BAD_OR);
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for &&.
|
|
||||||
if (!done && token.type == parse_token_type_background && token.source_start > 0) {
|
|
||||||
// Check to see if there was a previous token_background.
|
|
||||||
const parse_node_t *prev_background = nodes.find_node_matching_source_location(
|
|
||||||
parse_token_type_background, token.source_start - 1, NULL);
|
|
||||||
if (prev_background != NULL) {
|
|
||||||
// We have &&.
|
|
||||||
this->parse_error(token, parse_error_double_background, ERROR_BAD_AND);
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!done) {
|
|
||||||
const wcstring expected = stack_elem.user_presentable_description();
|
|
||||||
this->parse_error_unexpected_token(expected.c_str(), token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user