expr icon indicating copy to clipboard operation
expr copied to clipboard

Option to list allowed operators?

Open akamensky opened this issue 5 years ago • 6 comments

For my use case I need to allow only small subset of operators, is there currently any way to do that?

akamensky avatar Oct 02 '19 01:10 akamensky

No, currently there is no way. But I’m thinking about adding this functionality. What is your use case? Why only subset of operations?

antonmedv avatar Oct 02 '19 05:10 antonmedv

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).

akamensky avatar Oct 02 '19 06:10 akamensky

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?

antonmedv avatar Oct 02 '19 06:10 antonmedv

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).

akamensky avatar Oct 02 '19 07:10 akamensky

@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).

emicklei avatar Apr 04 '21 12:04 emicklei

I’m also thinking about adding variable support as well as configurable built-in.

Please, send a pr to add you to the list)

antonmedv avatar Apr 04 '21 14:04 antonmedv

I've added the next function to configure which builtins are available to the users:

  • DisableAllBuiltins
  • DisableBuiltin
  • EnableBuiltin

antonmedv avatar Aug 19 '23 20:08 antonmedv