mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-19 21:21:15 -03:00
[tinyexpr] Let specific errors take precedence over generic ones
Fixes the case where `sin()` reported the generic "bogus" error instead of "too few arguments". Also rename the constant to "TE_ERROR_UNKNOWN".
This commit is contained in:
@@ -239,8 +239,9 @@ void next_token(state *s) {
|
||||
s->function = var->address;
|
||||
break;
|
||||
}
|
||||
} else if (s->type != TOK_ERROR) {
|
||||
// TODO: Better error - "Not a variable"?
|
||||
} else if (s->type != TOK_ERROR
|
||||
|| s->error == TE_ERROR_UNKNOWN) {
|
||||
// Our error is more specific, so it takes precedence.
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_UNKNOWN_VARIABLE;
|
||||
}
|
||||
@@ -295,8 +296,8 @@ static te_expr *base(state *s) {
|
||||
next_token(s);
|
||||
if (s->type == TOK_CLOSE) {
|
||||
next_token(s);
|
||||
} else if (s->type != TOK_ERROR) {
|
||||
// TODO: Better error - "Missing closing parenthesis"?
|
||||
} else if (s->type != TOK_ERROR
|
||||
|| s->error == TE_ERROR_UNKNOWN) {
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_MISSING_CLOSING_PAREN;
|
||||
}
|
||||
@@ -323,15 +324,14 @@ static te_expr *base(state *s) {
|
||||
}
|
||||
if(s->type == TOK_CLOSE && i == arity - 1) {
|
||||
next_token(s);
|
||||
} else if (s->type != TOK_ERROR) {
|
||||
// TODO: Either a closing paren was needed,
|
||||
// or too few arguments were given?
|
||||
} else if (s->type != TOK_ERROR
|
||||
|| s->error == TE_ERROR_UNKNOWN) {
|
||||
s->type = TOK_ERROR;
|
||||
s->error = i < arity ? TE_ERROR_TOO_FEW_ARGS
|
||||
: TE_ERROR_TOO_MANY_ARGS;
|
||||
}
|
||||
} else if (s->type != TOK_ERROR) {
|
||||
// TODO: Better error - "Expected opening parenthesis"?
|
||||
} else if (s->type != TOK_ERROR
|
||||
|| s->error == TE_ERROR_UNKNOWN) {
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_MISSING_OPENING_PAREN;
|
||||
}
|
||||
@@ -343,8 +343,8 @@ static te_expr *base(state *s) {
|
||||
ret = expr(s);
|
||||
if (s->type == TOK_CLOSE) {
|
||||
next_token(s);
|
||||
} else if (s->type != TOK_ERROR) {
|
||||
// TODO: Error - missing closing paren?
|
||||
} else if (s->type != TOK_ERROR
|
||||
|| s->error == TE_ERROR_UNKNOWN) {
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_MISSING_CLOSING_PAREN;
|
||||
}
|
||||
@@ -352,9 +352,8 @@ static te_expr *base(state *s) {
|
||||
|
||||
default:
|
||||
ret = new_expr(0, 0);
|
||||
// TODO: Error - expression is bogus?
|
||||
s->type = TOK_ERROR;
|
||||
s->error = TE_ERROR_BOGUS;
|
||||
s->error = TE_ERROR_UNKNOWN;
|
||||
ret->value = NAN;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user