Fix math incorrect parenthesis error on missing term

This commit is contained in:
0x005c 2019-10-30 20:49:13 +09:00 committed by Fabian Homborg
parent 326f5586de
commit 067b30208d
4 changed files with 7 additions and 4 deletions

View File

@ -147,6 +147,8 @@ static const wchar_t *math_describe_error(te_error_t &error) {
return _(L"Too many arguments"); return _(L"Too many arguments");
case TE_ERROR_MISSING_OPERATOR: case TE_ERROR_MISSING_OPERATOR:
return _(L"Missing operator"); return _(L"Missing operator");
case TE_ERROR_UNEXPECTED_TOKEN:
return _(L"Unexpected token");
case TE_ERROR_UNKNOWN: case TE_ERROR_UNKNOWN:
return _(L"Expression is bogus"); return _(L"Expression is bogus");
default: default:

View File

@ -367,7 +367,7 @@ static te_expr *base(state *s) {
} }
if (s->type == TOK_CLOSE && i == arity - 1) { if (s->type == TOK_CLOSE && i == arity - 1) {
next_token(s); next_token(s);
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) { } else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNEXPECTED_TOKEN) {
s->type = TOK_ERROR; s->type = TOK_ERROR;
s->error = i < arity ? TE_ERROR_TOO_FEW_ARGS : TE_ERROR_TOO_MANY_ARGS; s->error = i < arity ? TE_ERROR_TOO_FEW_ARGS : TE_ERROR_TOO_MANY_ARGS;
} }
@ -403,7 +403,7 @@ static te_expr *base(state *s) {
default: default:
ret = new_expr(0, 0); ret = new_expr(0, 0);
s->type = TOK_ERROR; s->type = TOK_ERROR;
s->error = TE_ERROR_UNKNOWN; s->error = TE_ERROR_UNEXPECTED_TOKEN;
ret->value = NAN; ret->value = NAN;
break; break;
} }

View File

@ -35,7 +35,8 @@ typedef enum {
TE_ERROR_TOO_FEW_ARGS = 4, TE_ERROR_TOO_FEW_ARGS = 4,
TE_ERROR_TOO_MANY_ARGS = 5, TE_ERROR_TOO_MANY_ARGS = 5,
TE_ERROR_MISSING_OPERATOR = 6, TE_ERROR_MISSING_OPERATOR = 6,
TE_ERROR_UNKNOWN = 7 TE_ERROR_UNEXPECTED_TOKEN = 7,
TE_ERROR_UNKNOWN = 8
} te_error_type_t; } te_error_type_t;
typedef struct te_error_t { typedef struct te_error_t {

View File

@ -91,7 +91,7 @@ not math 'ncr(1)'
# CHECKERR: 'ncr(1)' # CHECKERR: 'ncr(1)'
# CHECKERR: ^ # CHECKERR: ^
not math 'max()' not math 'max()'
# CHECKERR: math: Error: Expression is bogus # CHECKERR: math: Error: Unexpected token
# CHECKERR: 'max()' # CHECKERR: 'max()'
# CHECKERR: ^ # CHECKERR: ^
not math 'sin()' not math 'sin()'