diff --git a/parser.cpp b/parser.cpp index c6cbd9b50..93e068d78 100644 --- a/parser.cpp +++ b/parser.cpp @@ -3535,8 +3535,8 @@ int parser_t::test(const wchar_t *buff, int *block_level, wcstring *out, const w } else { - err = 1; - if (out) + // Only print errors once + if (out && ! err) { error(SYNTAX_ERROR, tok_get_pos(&tok), @@ -3546,6 +3546,7 @@ int parser_t::test(const wchar_t *buff, int *block_level, wcstring *out, const w print_errors(*out, prefix); } + err = 1; } break; diff --git a/tokenizer.cpp b/tokenizer.cpp index 831197ee5..4521c164d 100644 --- a/tokenizer.cpp +++ b/tokenizer.cpp @@ -36,6 +36,12 @@ segments. */ #define PARAN_ERROR _( L"Unexpected end of string, parenthesis do not match" ) +/** + Error string for mismatched square brackets +*/ +#define SQUARE_BRACKET_ERROR _( L"Unexpected end of string, square brackets do not match" ) + + /** Error string for invalid redirections */ @@ -237,7 +243,6 @@ static void read_string(tokenizer_t *tok) while (1) { - if (!myal(*tok->buff)) { if (*tok->buff == L'\\') @@ -390,7 +395,19 @@ static void read_string(tokenizer_t *tok) if ((!tok->accept_unfinished) && (mode != mode_regular_text)) { - TOK_CALL_ERROR(tok, TOK_UNTERMINATED_SUBSHELL, PARAN_ERROR); + switch (mode) + { + case mode_subshell: + TOK_CALL_ERROR(tok, TOK_UNTERMINATED_SUBSHELL, PARAN_ERROR); + break; + case mode_array_brackets: + case mode_array_brackets_and_subshell: + TOK_CALL_ERROR(tok, TOK_UNTERMINATED_SUBSHELL, SQUARE_BRACKET_ERROR); // TOK_UNTERMINATED_SUBSHELL is a lie but nobody actually looks at it + break; + default: + assert(0 && "Unexpected mode in read_string"); + break; + } return; }