EricSmekens / jsep

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

Multiple instances of jsep with different operators #211

Open cmarcao opened 2 years ago

cmarcao commented 2 years ago

Hi guys.

There is any reason to have a singleton parser? There is no chance to have more than one jsep with different configuration running in the same app at client side?

Thank you,

Carlos Marcão

6utt3rfly commented 2 years ago

@EricSmekens and @LeaVerou - any thoughts on this? I know when we first started moving into a plugin system, this was discussed, but then dropped to reduce complexity/scope. I feel like this could be useful in some cases and could be re-done similar to what this commit removed?

LeaVerou commented 2 years ago

Any proposal for additional complexity should be justified through use cases. What are the use cases for having multiple parsers with different configurations and how common are they?

joeflateau commented 2 years ago

@LeaVerou I would like to use jsep in a library with a custom binary operator but I cannot because of the singleton nature of it might lead to transient, hard to locate bugs

Julusian commented 1 year ago

I think what @joeflateau said sums it up for me. If writing an application, then the singleton nature most likely isnt an issue.
But if writing a library, it could be an issue if some other component of the application also uses jsep.

I was considering using this for an application, where I would want to be able to parse boolean expressions and number expressions separately under different rules. While I could manage with this singleton, it would require swapping out the acceptable operators and things each time I want to parse an expression, which is rather wasteful.

jdanyow commented 1 year ago

related to #28