From 067b30208d6624b5134138e524c9d12fb7c776a3 Mon Sep 17 00:00:00 2001 From: 0x005c <52650857+0x005c@users.noreply.github.com> Date: Wed, 30 Oct 2019 20:49:13 +0900 Subject: [PATCH] Fix `math` incorrect parenthesis error on missing term --- src/builtin_math.cpp | 2 ++ src/tinyexpr.cpp | 4 ++-- src/tinyexpr.h | 3 ++- tests/checks/math.fish | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index d7a3c7fc8..822040930 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -147,6 +147,8 @@ static const wchar_t *math_describe_error(te_error_t &error) { return _(L"Too many arguments"); case TE_ERROR_MISSING_OPERATOR: return _(L"Missing operator"); + case TE_ERROR_UNEXPECTED_TOKEN: + return _(L"Unexpected token"); case TE_ERROR_UNKNOWN: return _(L"Expression is bogus"); default: diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index d9d1cea72..61c007e17 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -367,7 +367,7 @@ 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_UNKNOWN) { + } else if (s->type != TOK_ERROR || s->error == TE_ERROR_UNEXPECTED_TOKEN) { s->type = TOK_ERROR; 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: ret = new_expr(0, 0); s->type = TOK_ERROR; - s->error = TE_ERROR_UNKNOWN; + s->error = TE_ERROR_UNEXPECTED_TOKEN; ret->value = NAN; break; } diff --git a/src/tinyexpr.h b/src/tinyexpr.h index 193cc706b..fb945525b 100644 --- a/src/tinyexpr.h +++ b/src/tinyexpr.h @@ -35,7 +35,8 @@ typedef enum { TE_ERROR_TOO_FEW_ARGS = 4, TE_ERROR_TOO_MANY_ARGS = 5, TE_ERROR_MISSING_OPERATOR = 6, - TE_ERROR_UNKNOWN = 7 + TE_ERROR_UNEXPECTED_TOKEN = 7, + TE_ERROR_UNKNOWN = 8 } te_error_type_t; typedef struct te_error_t { diff --git a/tests/checks/math.fish b/tests/checks/math.fish index 3513f26bf..a66e9937a 100644 --- a/tests/checks/math.fish +++ b/tests/checks/math.fish @@ -91,7 +91,7 @@ not math 'ncr(1)' # CHECKERR: 'ncr(1)' # CHECKERR: ^ not math 'max()' -# CHECKERR: math: Error: Expression is bogus +# CHECKERR: math: Error: Unexpected token # CHECKERR: 'max()' # CHECKERR: ^ not math 'sin()'