Comments (5)
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?
from dentaku.
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.
from dentaku.
+1 for this suggestion, or would it be reasonable to expose a parse!() method that could be called to validate a formula?
from dentaku.
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
from dentaku.
This is fixed in v2.0 -- calculator.ast(expression)
will return an AST node or raise a parse error.
from dentaku.
Related Issues (20)
- Class Conversion HOT 3
- What is the state of SQRT function? HOT 4
- Bitwise operators & and | returning errors on non-integer arguments
- Misinterpreting formula with minus signs as a date HOT 1
- some edge case statements don't return Dentaku error HOT 1
- set var_name causing solve to fail HOT 5
- 0.089*105.0 should equal 9.344999999999999, not 9.345 HOT 1
- `-` is interpretated as a number rather than a string HOT 1
- Not able to evaluated string with apostrophe
- Lazy loading variables HOT 2
- AVG function returns always integer class value HOT 2
- `dentaku + ruby-units`: Let `dentaku` defer some or all operations to custom class HOT 3
- Isn't `add_functions` supposed to be class method? HOT 1
- Division by Zero error in `solve` on `IF()` function not being rescued
- Unclear effect of `add_function` type parameter
- Division by % is not working
- Division by % is not working
- Case sensitive BulkExpressionSolver#solve fails for capitalized keys declared in imperfect order HOT 1
- Feature request: Support empty array literal
- v3.5.2: Calculating difference between two stored dates returns :undefined HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dentaku.