Make string syntax error location a bit more precise

String tokens are subdivided by command substitutions. Some syntax errors
can occur in the gap between two command substitutions. Make the caret point
to the start of that gap, instead of the token start.
This commit is contained in:
Johannes Altmanninger 2022-04-03 16:29:13 +02:00
parent e717b13e75
commit 4b5b56452b
2 changed files with 7 additions and 2 deletions

View file

@ -959,7 +959,7 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(const ast::argumen
wcstring unesc;
if (!unescape_string(arg_src.c_str() + begin, end - begin, &unesc, UNESCAPE_SPECIAL)) {
if (out_errors) {
append_syntax_error(out_errors, source_start, L"Invalid token '%ls'",
append_syntax_error(out_errors, source_start + begin, L"Invalid token '%ls'",
arg_src.c_str());
}
return 1;

View file

@ -39,6 +39,11 @@ $fish -c 'echo "unfinished "$(subshell' 2>| string replace -r '.*' '<$0>'
# CHECK: <echo "unfinished "$(subshell>
# CHECK: < ^>
$fish -c 'echo "ok $(echo still ok)syntax error: \x"' 2>| string replace -r '.*' '<$0>'
# CHECK: <fish: Invalid token '"ok $(echo still ok)syntax error: \x"'>
# CHECK: <echo "ok $(echo still ok)syntax error: \x">
# CHECK: < ^>
echo "function error" >$TMPDIR/error.fish
$fish -c "set -g fish_function_path $(string escape $TMPDIR); error"
# CHECKERR: ~/temp/error.fish (line 1): Missing end to balance this function definition