math: Add length to missing operator error

This commit is contained in:
Fabian Boehm 2022-09-08 18:45:41 +02:00
parent 52e065e479
commit a3ee7da812
2 changed files with 9 additions and 5 deletions

View File

@ -383,7 +383,6 @@ double state::base() {
/* <base> = <constant> | <function-0> {"(" ")"} | <function-1> <power> |
* <function-X> "(" <expr> {"," <expr>} ")" | "(" <list> ")" */
auto previous = start_;
auto next = next_;
switch (type_) {
case TOK_NUMBER: {
@ -398,10 +397,10 @@ double state::base() {
error_ = TE_ERROR_MISSING_OPERATOR;
// The error should be given *between*
// the last two tokens.
// Since these are two separate numbers there is at least
// one space between.
start_ = previous;
next_ = next + 1;
errpos_ = next + 1;
// Go to the end of whitespace.
while (wcschr(L" \t\n\r", next++[0]));
errlen_ = next - errpos_;
}
return val;
}

View File

@ -131,6 +131,11 @@ not math '2 + 2 4'
# This regex to check whitespace - the error appears between the second 2 and the 4!
# (right after the 2)
# CHECKERR: {{^}} ^
printf '<%s>\n' (math '2 + 2 4' 2>&1)
# CHECK: <math: Error: Missing operator>
# CHECK: <'2 + 2 4'>
# CHECK: < ^~~~~^>
not math '(1 2)'
# CHECKERR: math: Error: Missing operator
# CHECKERR: '(1 2)'