Search code examples
javajavascriptrhino

Defining rules and condition in javascript = Rhino


My requirement is, The user is given the option to define rules for eg:

IF f1 is grt than f2 do this

or

IF f1 > f2 and f2 < f3 ...

so he may use operators or text (say and or &&)

Now we need to convert this text in a textbox to specific rules or condition. There are lots of condition (all operators &&, ||, !, = etc etc...) provided it should be done in client side browser. So javascript is a way to do. I dont have enough time to write a library or a parser. However I read somewhere rhino has this ability but i have no idea how to use it.

Thanks in Advance for any hints.


Solution

  • If I understand you correctly, you want to translate rules written in a custom language to javascript?

    In this case, Rhino will not solve your problem: Rhino is a javascript interpreter written in Java. It would allow you to evaluate the rules if they were written in javascript.