-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom operator can't use external context #497
Comments
if you don't mind, I am ready to do PR |
What data do you need to inject in LikeExpression class ? |
cache instance for storing compiled regular expressions |
I'd imagine this would improve performance slightly, too, as it would eliminate the need for reflection when evaluating operators |
We can just change the BinaryOperatorImpl constructor. Instead of getting a
We should directly pass the instance of the class.
We should do the same modification in UnaryOperatorImpl too |
no, the parser every time creates a new instance of the class for each node in the tree |
and initializes a new class (leftExpression, rightExpression, lineNumber) |
My bad ... you're right |
and the class itself is used as a marker to distinguish the filter expression and test expression from the rest of the expressions. I think this is not good. it’s all easy to fix, you can pass the expression type to the constructor (for example, enum) |
@ebussieres |
I used Java 8 syntax. Maybe I'm wrong? I did not find in the documentation whether pebble supports Java 7. |
I register a new operation "LIKE":
I can only specify the class name LikeExpression. Its instance is created by the engine and there is no good way to inject some necessary data into the class instance. Filters have no such problem.
Now I see such context injection methods:
I suggest registering not a class, but a factory (or provider) of class instances:
These two methods can exist together without breaking backward compatibility. Registering a class can use a lambda factory:
The text was updated successfully, but these errors were encountered: