ezylang / EvalEx

EvalEx is a handy expression evaluator for Java, that allows to evaluate simple mathematical and boolean expressions.
https://ezylang.github.io/EvalEx/
Apache License 2.0
987 stars 268 forks source link

Is it possible to achieve these with this library? #198

Closed tosehee closed 3 years ago

tosehee commented 5 years ago

Can I use this library to evaluate the expression such as below?

oh.currentStatus == 'New' && oh.pickWave.status == "Planned"

"oh" is the variable that I'd like to bind, and currentStatus is the property of the object.. You can go further with the approach where "pickWave" is a object property of "oh", and it has the 'status' as its property.

It seems that using a Reflection API can achieve the above, but wasn't sure if it's already supported or not.

RobertZenz commented 5 years ago

Well, as usual, I do not know the extend of the string support, but you might able to get away with binding a custom operator on . and work with that. However, that seems rather cumbersome.

tosehee commented 5 years ago

Well, "oh" is not a string. It's actually hibernate proxy object that contains other relations, and it does seem rather cumbersome solution..

Any other thoughts?

squeek502 commented 5 years ago

Seems like you probably want a proper scripting language?

tosehee commented 5 years ago

That is whst i sm doing but it's heavy for simple expression. So i am looking for alternatives

On Mon, Mar 25, 2019, 7:11 PM Ryan Liptak notifications@github.com wrote:

Seems like you probably want a proper scripting language?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/uklimaschewski/EvalEx/issues/198#issuecomment-476412298, or mute the thread https://github.com/notifications/unsubscribe-auth/AHGJNOffM236FB1gw4DbCHtkSA4tIEr8ks5vaVe2gaJpZM4cH1uY .

RobertZenz commented 5 years ago

LuaJ is rather lightweight and might be an alternative here. You could also go all the way and build your own DSL with ANTLR.

tosehee commented 5 years ago

We are already using the nashorn, and it's too heavy for what we are doing. That's how I ended up here.

I am afraid LuaJ might be in similar boat.

On Tue, Mar 26, 2019 at 5:21 PM RobertZenz notifications@github.com wrote:

LuaJ https://github.com/luaj/luaj/releases is rather lightweight and might be an alternative here. You could also go all the way and build your own DSL with ANTLR https://www.antlr.org/.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/uklimaschewski/EvalEx/issues/198#issuecomment-476857451, or mute the thread https://github.com/notifications/unsubscribe-auth/AHGJNMhumbrHzpYimInBa18GrBkOKKsiks5vao88gaJpZM4cH1uY .

--

Se Hee Lee | VP Product Development Email: slee@deposco.com | Phone: 678.597.8515 | Cell: 678.896.5097 555 North Point Center East Suite 400 Alpharetta, GA 30022 www.deposco.com

squeek502 commented 5 years ago

What do you mean by 'heavy'?

tosehee commented 5 years ago

Heave in terms of resource usage and performance

On Wed, Mar 27, 2019, 3:52 PM Ryan Liptak notifications@github.com wrote:

What do you mean by 'heavy'?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/uklimaschewski/EvalEx/issues/198#issuecomment-477322500, or mute the thread https://github.com/notifications/unsubscribe-auth/AHGJNCpAOIN8-NbZZjHbj2UPld5rwTMsks5va8wAgaJpZM4cH1uY .

RobertZenz commented 5 years ago

I am afraid LuaJ might be in similar boat.

You need to try that, I never paid much attention to it. But given that it compiles to Java bytecode and that you can strip the STL it should not be that much.

squeek502 commented 5 years ago

Yeah, Lua is known for being lightweight in both performance and resource usage.

RobertZenz commented 5 years ago

You can't say it like that, though, as you require an interpreter, and it depends on that interpreter. But LuaJ is quite well in that regard.

uklimaschewski commented 5 years ago

Evaluating oh.pickWave.statuscould be possible with some effort, but the biger problem is the missing string support with operators. Strings are allowed as function parameters, e.g. STREQ("New","oh.pickWave.status"). In the custom STREQ function, you could start evaluating the oh.pickWave.status expression. The object oh could be a JSON string as a variable e.g. expression.with("oh" : {pickWave : { status : "New"}}).

uklimaschewski commented 5 years ago

Maybe #188 can help here?