A GoLang library for simple expression evaluation.
expr.Eval("true && true") # true
expr.Eval("2+3") # 5
expr.Eval("1+3>3") # true
expr.Eval("('fo'!='bar')&&(2!=3)") # true
Supported logical operations are &&
and ||
.
- On text,
"true"
or'true'
(case insensitive) istrue
, elsefalse
- On numbers greater zero is
true
, elsefalse
Supported comparisons are ==
, !=
, <
, >
, <=
or >=
.
While equal and not equal directly uses the value. Greater(equal) and smaller(equal) will behave different:
- On boolean a
0
and1
is used (true>0
=true
,false>0
=false
). - On text the length is used (
"hello">"hey"
=true
).
Supported arithmetics are +
, -
, *
, /
and %
.
- On boolean a
0
and1
is used (true+0
=1
,false+0
=0
). - On text the length is used (
"foo"+"bar"
=6
).
Context can be used to group a part of the expression to prioritize the evaluation.