Simple expression evaluation syntax

33 views Asked by At

I'm working on a dashboard/gui with small widgets. For each widget, the end user should be able to specify on which conditions a widget is visible (based on values from other objects). For example, the widget for showing the state of motion sensors should be hidden when somebody is home. (because it's only used to detect presence of unwanted visitors, not to track/follow residents when they are at home).

A sample 'expression' the user should be able to insert manually, could be {value} = 0, where {value} will be based on the state of the alarm system.

To allow more situations, we've already come up with expressions such as: {value} > 0, {value} >= 0, {value} != 0, {value} < 0, {value} <= 0, but also more complex ones like , {value & 2} = 2 (bitwise operations), {value % 3} = 1 (modulo) or {value} in 0-10 (for a range).

In order to prevent me from comming up with my own syntax, I've searched for any existing ones. I've already found math.js, but that's not exactly what i'm looking for. Otherwise, I'm ending up in the documentation of operators for Javacript for example.

And of course, I can use regular expressions/eval myself in order to evaluate the user defined expression in order to check if there's a match, so the widget can be show/hidden. But when there already is something like that (and documented), why reinvent the wheel.

Despite all the manuals for programming languages, is there some general syntax for evaluating expressions?

0

There are 0 answers