Commit Graph

10 Commits

Author SHA1 Message Date
Fabian Homborg
97cd87f3b2 math: Use wchar
This was doing a bunch of work narrowing strings for no reason.
2020-12-14 22:54:53 +01:00
Fabian Homborg
921fce3a51 math: Complain about unknown *function*, not *variable*
We removed variables from tinyexpr, so we shouldn't use that error.
2020-02-07 17:43:22 +01:00
Fabian Homborg
c0d8439f3a math: Print special error for logical operators
Until now, something like

`math '7 = 2'`

would complain about a "missing" operator.

Now we print an error about logical operators not being supported and
point the user towards `test`.

Fixes #6096
2019-11-01 08:43:13 +01:00
0x005c
067b30208d Fix math incorrect parenthesis error on missing term 2019-10-31 22:10:54 +01:00
Fabian Homborg
cbc25d7829 [tinyexpr] Port to C++
This removes the need to run c-compilation on one file, and allows us
to in future c++-ify this a bit.

There's a lot of bit-fiddling here that is quite unnecessary, better
error-handling would be nice...

So far this removes a few more unused things (because I would have had
to port them), including:

- Functions with ARITY > 3 (even 3 isn't used, but just so we don't
get complacent)

- Variables

- Most functions moved out of the header, because only te_interp is used.

- The te_print function
2018-12-30 19:34:06 +01:00
Fabian Homborg
f60e1549a9 [math] Better error for 2 + 2 4
This now reports "TOO_MANY_ARGS" instead of no error (and triggering
an assertion).

We might want to add a new error type or report the missing operator
before, but this is okay for now.
2018-03-01 13:09:35 +01:00
Fabian Homborg
d90d0ee08e [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".
2018-03-01 13:09:35 +01:00
Fabian Homborg
4f39cc4d82 [tinyexpr] Remove closures
These are only available as a customization point. Since we don't use
that, it's dead code.
2018-03-01 13:09:35 +01:00
Fabian Homborg
7b9c75094c [tinyexpr] Add error handling
This turns a bunch of ifs on their heads.

We often see this pattern in te:

```c
if (s->type != SOME_TYPE) {
   // error handling
}  else {
   // normal code
}
```

Only, since we want to return the first error, we do

```c
if (s->type == SOME_TYPE) {
    // normal code
} else if (s->type != TOK_ERROR) {
    // Add a new error - if it already has type error
    // this should already be handled.
}
```

One big issue is the comma operator, that means arity-1 functions can
take an arbitrary number of arguments. E.g.

```fish
math "sin(5,9)"
```

will return the value of sin for _9_, since this is read as "5 COMMA
9".
2018-03-01 13:09:35 +01:00
Fabian Homborg
b75c3b968c Replace muparser with tinyexpr 2018-03-01 13:09:35 +01:00