Skip to content
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

Getting sub expressions during evaluation #45

Open
VolceOntra opened this issue Apr 3, 2023 · 2 comments
Open

Getting sub expressions during evaluation #45

VolceOntra opened this issue Apr 3, 2023 · 2 comments

Comments

@VolceOntra
Copy link

VolceOntra commented Apr 3, 2023

Problem:
I want to add a postfix % operator that takes in the last valid expression and transform it, however (and I'm still learning this library) it seems without a lot of parsing it's kind of challenging -- is there a way to transform something like this

10 + 2% to equal 10 + (10*2/100)

or

20 * 2 + 10% would give access to the last evaluated expression of (20 * 2) and the main argument 10 when getting the post fix callback for %

@nicklockwood
Copy link
Owner

@VolceOntra sorry, I don't think this is possible right now. The precedence for postfix operators is always higher than for infix, so without adding parentheses, it's not possible for the % to operate on the entire previous expression.

The syntax tree isn't currently public, but you could maybe do something hacky, like preprocess the string to add parentheses in before passing it to Expression.

@DanDolog
Copy link

I just want to say that I need this feature too 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants