expr
expr copied to clipboard
Option to list allowed operators?
For my use case I need to allow only small subset of operators, is there currently any way to do that?
No, currently there is no way. But I’m thinking about adding this functionality. What is your use case? Why only subset of operations?
My use case is that the expressions would be coming from the users in an online service. And the requirement is that users should be limited to only simple comparison operations (such as ==
, <=
, >=
, <>
etc).
Okay, I understand. Well, there is a built-ins as well. Do you need them? I think we need to find some api for configuring operators and builtins.
Is there are other examples of configurable languages?
For my use case I would not need those built-ins. Only comparison operations. I imagine if allowed operators will be configurable, it would make sense to make all language elements configurable. Though not sure how difficult would that be (did not look at the code base yet).
@antonmedv , I have been using this package with great succes for my Melrōse music language.
I defined lots of functions for my DSL and even added the concept of a variable and assignment. However, as @akamensky mentioned, my DSL is accepting too much language constructs. On the one hand, I am maybe using this package beyond its intent to build a DSL. On the other hand, if the built-ins were configurable, the expr
package is an almost perfect fit (well, variable support would be even better!).
ps. if you like, my open-source music programming tool may enter the hall of fame (who is using expr).
I’m also thinking about adding variable support as well as configurable built-in.
Please, send a pr to add you to the list)
I've added the next function to configure which builtins are available to the users:
- DisableAllBuiltins
- DisableBuiltin
- EnableBuiltin