mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Correct the caret position for unbalanced square brackets
This commit is contained in:
parent
e34a8da5d7
commit
aa76f64a94
5 changed files with 23 additions and 2 deletions
|
@ -493,6 +493,16 @@ static void test_tok()
|
||||||
do_test(token.error_offset == 4);
|
do_test(token.error_offset == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
tok_t token;
|
||||||
|
tokenizer_t t(L"abc defg[hij (klm)", 0);
|
||||||
|
do_test(t.next(&token));
|
||||||
|
do_test(t.next(&token));
|
||||||
|
do_test(token.type == TOK_ERROR);
|
||||||
|
do_test(token.error == TOK_UNTERMINATED_SLICE);
|
||||||
|
do_test(token.error_offset == 4);
|
||||||
|
}
|
||||||
|
|
||||||
/* Test redirection_type_for_string */
|
/* Test redirection_type_for_string */
|
||||||
if (redirection_type_for_string(L"<") != TOK_REDIRECT_IN) err(L"redirection_type_for_string failed on line %ld", (long)__LINE__);
|
if (redirection_type_for_string(L"<") != TOK_REDIRECT_IN) err(L"redirection_type_for_string failed on line %ld", (long)__LINE__);
|
||||||
if (redirection_type_for_string(L"^") != TOK_REDIRECT_OUT) err(L"redirection_type_for_string failed on line %ld", (long)__LINE__);
|
if (redirection_type_for_string(L"^") != TOK_REDIRECT_OUT) err(L"redirection_type_for_string failed on line %ld", (long)__LINE__);
|
||||||
|
|
|
@ -134,6 +134,7 @@ enum parse_error_code_t
|
||||||
//tokenizer errors
|
//tokenizer errors
|
||||||
parse_error_tokenizer_unterminated_quote,
|
parse_error_tokenizer_unterminated_quote,
|
||||||
parse_error_tokenizer_unterminated_subshell,
|
parse_error_tokenizer_unterminated_subshell,
|
||||||
|
parse_error_tokenizer_unterminated_slice,
|
||||||
parse_error_tokenizer_unterminated_escape,
|
parse_error_tokenizer_unterminated_escape,
|
||||||
parse_error_tokenizer_other,
|
parse_error_tokenizer_other,
|
||||||
|
|
||||||
|
|
|
@ -909,6 +909,10 @@ void parse_ll_t::report_tokenizer_error(const tok_t &tok)
|
||||||
parse_error_code = parse_error_tokenizer_unterminated_subshell;
|
parse_error_code = parse_error_tokenizer_unterminated_subshell;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TOK_UNTERMINATED_SLICE:
|
||||||
|
parse_error_code = parse_error_tokenizer_unterminated_slice;
|
||||||
|
break;
|
||||||
|
|
||||||
case TOK_UNTERMINATED_ESCAPE:
|
case TOK_UNTERMINATED_ESCAPE:
|
||||||
parse_error_code = parse_error_tokenizer_unterminated_escape;
|
parse_error_code = parse_error_tokenizer_unterminated_escape;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -164,6 +164,9 @@ void tokenizer_t::read_string()
|
||||||
const size_t paran_offsets_max = 96;
|
const size_t paran_offsets_max = 96;
|
||||||
size_t paran_offsets[paran_offsets_max];
|
size_t paran_offsets[paran_offsets_max];
|
||||||
|
|
||||||
|
// where the open bracket is
|
||||||
|
size_t offset_of_bracket = 0;
|
||||||
|
|
||||||
const wchar_t * const start = this->buff;
|
const wchar_t * const start = this->buff;
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
|
|
||||||
|
@ -219,7 +222,10 @@ void tokenizer_t::read_string()
|
||||||
case L'[':
|
case L'[':
|
||||||
{
|
{
|
||||||
if (this->buff != start)
|
if (this->buff != start)
|
||||||
|
{
|
||||||
mode = mode_array_brackets;
|
mode = mode_array_brackets;
|
||||||
|
offset_of_bracket = this->buff - this->orig_buff;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,8 +367,7 @@ void tokenizer_t::read_string()
|
||||||
case mode_array_brackets:
|
case mode_array_brackets:
|
||||||
case mode_array_brackets_and_subshell:
|
case mode_array_brackets_and_subshell:
|
||||||
{
|
{
|
||||||
size_t offset_of_bracket = 0;
|
TOK_CALL_ERROR(this, TOK_UNTERMINATED_SLICE, SQUARE_BRACKET_ERROR, this->orig_buff + offset_of_bracket);
|
||||||
TOK_CALL_ERROR(this, TOK_UNTERMINATED_SUBSHELL, SQUARE_BRACKET_ERROR, this->orig_buff + offset_of_bracket); // TOK_UNTERMINATED_SUBSHELL is a lie but nobody actually looks at it
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ enum tokenizer_error
|
||||||
TOK_ERROR_NONE,
|
TOK_ERROR_NONE,
|
||||||
TOK_UNTERMINATED_QUOTE,
|
TOK_UNTERMINATED_QUOTE,
|
||||||
TOK_UNTERMINATED_SUBSHELL,
|
TOK_UNTERMINATED_SUBSHELL,
|
||||||
|
TOK_UNTERMINATED_SLICE,
|
||||||
TOK_UNTERMINATED_ESCAPE,
|
TOK_UNTERMINATED_ESCAPE,
|
||||||
TOK_OTHER
|
TOK_OTHER
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue