diff --git a/src/tinyexpr.c b/src/tinyexpr.c index b91717706..259ed1bc8 100755 --- a/src/tinyexpr.c +++ b/src/tinyexpr.c @@ -350,6 +350,17 @@ static te_expr *base(state *s) { } break; + case TOK_END: + // The expression ended before we expected it. + // e.g. `2 - `. + // This means we have too few things. + // Instead of introducing another error, just call it + // "too few args". + ret = new_expr(0, 0); + s->type = TOK_ERROR; + s->error = TE_ERROR_TOO_FEW_ARGS; + ret->value = NAN; + break; default: ret = new_expr(0, 0); s->type = TOK_ERROR; diff --git a/tests/math.err b/tests/math.err index 8282dedae..323287cb6 100644 --- a/tests/math.err +++ b/tests/math.err @@ -7,7 +7,7 @@ #################### # Validate math error reporting -math: Error: Expression is bogus +math: Error: Too few arguments '2 - ' ^ math: Error: Too few arguments