-
Notifications
You must be signed in to change notification settings - Fork 161
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
Tokenizer (or Expression) should fail on nonsensical input #26
Comments
This would fail at evaluation: calculator.evaluate!('10 7')
RuntimeError: no rule matched {{10 7}} Do you feel that it should fail when attempting to construct the expression? |
Yeah - ideally this should be a compile-time error and not a run-time error. This is particularly important in my case, where non-technical users write formulas that only get run days later when the formulas are run. It is substantially less painful for debugging if I can tell them there's an error when they write it than when the formula gets run. My current work-around is to calculate dependencies, mark all the identifiers with the value 0, and run the formula to see if it passes. |
+1 for this suggestion, or would it be reasonable to expose a parse!() method that could be called to validate a formula? |
I was looking for this functionality too, specifically to help validate expressions saved in a model. I came up with this custom validator: https://gist.github.com/rikkipitt/4551c9b72b35cd7a4756 Please try it out and extend if your case requires! Rikki |
This is fixed in v2.0 -- |
One example of an expression that should fail is
5 4
- two values (or identifiers) not connected with an operator of any sort. This seems like a good cause for a stricter grammar / lexer.The text was updated successfully, but these errors were encountered: