GithubHelp home page GithubHelp logo

Error message method about ohm HOT 7 CLOSED

harc avatar harc commented on August 24, 2024
Error message method

from ohm.

Comments (7)

alexwarth avatar alexwarth commented on August 24, 2024

You're right, this kind of thing should be easy to do. And I think it is in this case: have you tried the message and shortMessage properties of the MatchFailure object that you get from a failed call to yourGrammar.match(...)? Let me know if those properties don't do what you want and I'll figure something out :)

Alternatively, you could compose your own error message using a combination of other methods from MatchFailure. It's more work, but gives you more control:

  • getPos() method will tell you where the match failed. (We should probably also support a getLineAndCol method, so that clients don't have to compute that information themselves.)
  • getExpectedText() gives you a string, e.g., "+, -, *, or /"

from ohm.

JonathanMEdwards avatar JonathanMEdwards commented on August 24, 2024

Sorry - this is for when the parse is succeeding but I want to report errors detected later in the semantics.

from ohm.

alexwarth avatar alexwarth commented on August 24, 2024

Oh, I see! Thanks for clarifying.

I think your suggestion makes perfect sense. I can imagine exposing this kind of functionality in a couple of different ways. One option (as you suggested) would be to add it as a method on Intervals. Another would be to make it a method of CST nodes (e.g., someNode.createErrorMessage('a string that explains what is wrong with this node')) -- then you wouldn't even have to extract the node's interval. IMO the latter would be nicer to use, assuming it's expressive enough. Can you think of any cases where you'd want to create a custom interval?

Anyway, I'll leave this one for Pat to look at on Monday. He's been working on improving the way error messages are displayed, so it's probably best if he adds this feature.

Thanks again, Jonathan!

from ohm.

JonathanMEdwards avatar JonathanMEdwards commented on August 24, 2024

Great, thanks. I'd vote for a method on Interval, because it only depends on info from the Interval. I've been stashing Intervals in the DOM because that's all i need so far.

Another reason I haven't been using Nodes is because semantic actions get the current node as a dynamic this, which is subtle and not expressible in the Typescript type system and not available to ES6 lambda expressions.

from ohm.

pdubroy avatar pdubroy commented on August 24, 2024

As of d376cf3, it's exposed via ohm.util.getLineAndColumnMessage. I will probably also make a convenience method on Interval, but I thought it would be better to have a more flexible version for cases for when you might not have an interval in hand.

from ohm.

pdubroy avatar pdubroy commented on August 24, 2024

@JonathanMEdwards, would you mind opening a new issue with some more details about the problem with dynamic this in Typescript? We'll eventually want to figure out a solution that works well in other languages.

from ohm.

JonathanMEdwards avatar JonathanMEdwards commented on August 24, 2024

Upon reflection I think the current design is the best. It is certainly
idiomatic javascript. Dynamic this and first-class methods are outliers in
the landscape of OO languages but it actually works nicely in this case.
Typescript doesn't allow dynamic this to be typed but still allows it to be
used.

On Mon, Jun 1, 2015 at 6:36 AM, Patrick Dubroy [email protected]
wrote:

@JonathanMEdwards https://github.com/JonathanMEdwards, would you mind
opening a new issue with some more details about the problem with dynamic
this in Typescript? We'll eventually want to figure out a solution that
works well in other languages.


Reply to this email directly or view it on GitHub
#15 (comment).

from ohm.

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.