-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Improve auto crafting request input field #834
Comments
Sounds like a good idea! |
I think i should be able to write my own formatter which will first evaluate the expression, and then send the value to a decimal formatter |
Keep in mind that we already have a query parser with a lexer and parser. It should be straightforward to add math expression evaluation to that. |
I was thinking that I can just use an existing expression evaluation library. It would be simpler than writing my own, and the result would be a lot more powerful. |
I finished writing this, so whenever you are ready, tell me to submit the PR. |
…e-number-input-fields
Describe your enhancement
Allow for math expressions (x+y), craft up to an amount in storage (=x), and use units (xK).
To do this, I added a folder to the query-parser called evaluator. It takes an input string, runs it through the lexer, interprets all unit multipliers (such as 1k->1000) and parser with ArithmeticMappings. Then the result is run through a loop which evaluates the equation.
If at any point there is a problem, it is returned as a thrown exception. The value of the exception corresponds to a translation entry, which will be the error shown to the user as a tooltip.
All this logic is controlled by the ExpressionAmountOperator which can be passed as the valueOperator to the abstract screen class. That operator also catches the exceptiona and returns the translation.
The text was updated successfully, but these errors were encountered: