math: Actually report closing paren error

This was typically overridden by "too many/few arguments", but it's
actually incorrect:

    sin(55

has the correct number of arguments to `sin`, but it's lacking
the closing `)`.
This commit is contained in:
Fabian Homborg 2020-10-25 21:28:49 +01:00
parent cef84cf2c2
commit a84d57b02b
2 changed files with 18 additions and 1 deletions

View file

@ -395,9 +395,16 @@ static te_expr *base(state *s) {
if (s->type == TOK_CLOSE && i == arity - 1) {
next_token(s);
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNEXPECTED_TOKEN) {
s->type = TOK_ERROR;
// If we had the right number of arguments, we're missing a closing paren.
if (i == arity - 1 && s->type != TOK_ERROR) {
s->error = TE_ERROR_MISSING_CLOSING_PAREN;
} else {
// Otherwise we complain about the number of arguments *first*,
// a closing parenthesis should be more obvious.
s->error = i < arity ? TE_ERROR_TOO_FEW_ARGS : TE_ERROR_TOO_MANY_ARGS;
}
s->type = TOK_ERROR;
}
} else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNKNOWN) {
s->type = TOK_ERROR;
s->error = TE_ERROR_MISSING_OPENING_PAREN;

View file

@ -154,3 +154,13 @@ math "bitand(5.5, 1)"
math "bitor(37 ^ 5, 255)"
# CHECK: 69343999
math 'log 16'
# CHECKERR: math: Error: Missing opening parenthesis
# CHECKERR: 'log 16'
# CHECKERR: ^
math 'log(16'
# CHECKERR: math: Error: Missing closing parenthesis
# CHECKERR: 'log(16'
# CHECKERR: ^