EricSmekens / jsep

JavaScript Expression Parser
http://ericsmekens.github.io/jsep/
MIT License
835 stars 136 forks source link

Support for "IN" clause/operator type expression #228

Closed munderk closed 2 years ago

munderk commented 2 years ago

We have requirement wherein we need to parse and validate "IN" clause expressions. e.g, "Country IN ('Germany', 'France', 'UK')"

I add the "IN" operator using jsep.addBinaryOp("IN") and then I try to parse the expression and build tree.

But whenever I try such expression for parsing, e.g, jsep("Country IN ('Germany', 'France', 'UK')"), it throws error.

Can anyone please help me with parsing such expression and build tree properly?

6utt3rfly commented 2 years ago

@munderk - you can add IN support, but dealing with a list within parentheses (versus square brackets), makes it look like a function call to JSEP. Can you use [] syntax instead of ()?

Otherwise, you could maybe create a custom plugin (probably on the gobble-token event) to look for IN and then utilize jsep's gobbleArguments method?

munderk commented 2 years ago

@6utt3rfly Thanks for the reply. The use case is working fine in the newer version. No need to use the custom plugins.