GithubHelp home page GithubHelp logo

Comments (5)

rubysolo avatar rubysolo commented on July 22, 2024

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.

AlexeyMK avatar AlexeyMK commented on July 22, 2024

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.

lawso017 avatar lawso017 commented on July 22, 2024

+1 for this suggestion, or would it be reasonable to expose a parse!() method that could be called to validate a formula?

from dentaku.

rikkipitt avatar rikkipitt commented on July 22, 2024

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.

rubysolo avatar rubysolo commented on July 22, 2024

This is fixed in v2.0 -- calculator.ast(expression) will return an AST node or raise a parse error.

from dentaku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.