Improve error messages for double square brackets -

https://github.com/fish-shell/fish-shell/issues/875
This commit is contained in:
ridiculousfish 2013-09-11 14:22:16 -07:00
parent ee3b355c34
commit 46452e7634
2 changed files with 22 additions and 4 deletions

View file

@ -3535,8 +3535,8 @@ int parser_t::test(const wchar_t *buff, int *block_level, wcstring *out, const w
} }
else else
{ {
err = 1; // Only print errors once
if (out) if (out && ! err)
{ {
error(SYNTAX_ERROR, error(SYNTAX_ERROR,
tok_get_pos(&tok), 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); print_errors(*out, prefix);
} }
err = 1;
} }
break; break;

View file

@ -36,6 +36,12 @@ segments.
*/ */
#define PARAN_ERROR _( L"Unexpected end of string, parenthesis do not match" ) #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 Error string for invalid redirections
*/ */
@ -237,7 +243,6 @@ static void read_string(tokenizer_t *tok)
while (1) while (1)
{ {
if (!myal(*tok->buff)) if (!myal(*tok->buff))
{ {
if (*tok->buff == L'\\') if (*tok->buff == L'\\')
@ -390,7 +395,19 @@ static void read_string(tokenizer_t *tok)
if ((!tok->accept_unfinished) && (mode != mode_regular_text)) 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; return;
} }