Add length also for too-many/few-args error

This commit is contained in:
Fabian Boehm 2022-09-08 20:41:02 +02:00
parent a3ee7da812
commit c284c4ca99
2 changed files with 15 additions and 1 deletions

View File

@ -433,7 +433,9 @@ double state::base() {
std::vector<double> parameters;
int i;
for (i = 0; arity < 0 || i < arity; i++) {
const wchar_t *first_err = nullptr;
for (i = 0; ; i++) {
if (i == arity) first_err = next_;
parameters.push_back(expr());
if (type_ != TOK_SEP) {
break;
@ -461,6 +463,13 @@ double state::base() {
// a closing parenthesis should be more obvious.
error_ = i < arity ? TE_ERROR_TOO_FEW_ARGS : TE_ERROR_TOO_MANY_ARGS;
type_ = TOK_ERROR;
if (first_err) {
errpos_ = first_err;
errlen_ = next_ - first_err;
// TODO: Rationalize where we put the cursor exactly.
// If we have a closing paren it's on it, if we don't it's before the number.
if (type_ != TOK_CLOSE) errlen_++;
}
}
break;
}

View File

@ -254,6 +254,11 @@ math pow sin 3, 5
# CHECKERR: 'pow sin 3, 5'
# CHECKERR: ^
math pow sin 3, 5 + 2
# CHECKERR: math: Error: Too many arguments
# CHECKERR: 'pow sin 3, 5 + 2'
# CHECKERR: ^~~~^
math sin pow 3, 5
# CHECK: -0.890009