Coder Social home page Coder Social logo

Comments (11)

aslakhellesoy avatar aslakhellesoy commented on September 27, 2024

It would be great if the parser would detect if the next line didn't match what was expected. For example, if a Scenario line isn't followed by a step (ignoring comments). That sort of thing. It would be even better if it reported what line and what column it was on. And even better if it said what would have been valid input on that line (e.g. expected Given, When or Then, but found Crapola). Not sure what the best way to report errors is. Raise an exception? Invoke an error method on the listener? Not sure....

from gherkin2.

msassak avatar msassak commented on September 27, 2024

I like the idea of invoking an error method on the listener. That way the client code can decide whether to raise or continue, etc. I think that also jibes with the support Ragel has for handling error conditions.

from gherkin2.

msassak avatar msassak commented on September 27, 2024

I made a gist describing some possible error scenarios http://gist.github.com/188120, because it's hard for me to think of many.

from gherkin2.

ghnatiuk avatar ghnatiuk commented on September 27, 2024

I just pushed a feature to send the listener a table_error when it finds an unclosed table row. That message is sent first, folowed by a table message including all the parseable rows that are found. It's leading me to wonder, though, whether or not we should be tokenizing all the table rows rather than sending a single table message, e.g.

listener.table_start(10) #line number
listener.table_row(["hello","world", nil], 10)
listener.table_row_error("Unclosed table row", "| hello |world", 11)
listener.table_row(["goodbye", "cruel", "world"], 12)
listener.table_end(12)

or something like that. Maybe the table_start and table_end aren't even necessary.
wdyt?

from gherkin2.

msassak avatar msassak commented on September 27, 2024

Greg and I have been tossing around for a few days the idea of using Ragel strictly as a tokenizer, and inserting a "Syntax Policy Proxy" (or so we've been calling them) in between the Ragel parser and the listener, whose job it would be to ensure that events aren't called in the wrong order, handle error states, and pass on messages to the listener. Greg changed the parser to do that, and I merged his changes and pushed a very basic FeaturePolicy to my repo in the syntax-policies branch.

The intent, then, is to provide classes like Gherkin::Feature (or even Gherkin::CucumberFeature), which, given a language and a listener, would set everything up with the appropriate parser and policy. I like this idea a lot, not the least reason being that it would allow us to easily support use-cases like Liz Keogh brought up on the JBehave list where you have a bare scenario (or even bare steps) without any of the more complex stuff.

from gherkin2.

aslakhellesoy avatar aslakhellesoy commented on September 27, 2024

This is entirely up to you. If you think it's a good idea, just go ahead with it. I think it sounds smart, but I don't have enough insight now to know about pros and cons.

I assume these policies would have to be implemented in each target language too? I.e. C and Java.

from gherkin2.

msassak avatar msassak commented on September 27, 2024

Not unless you wanted to use the parser purely from C or Java--skipping Ruby and MRI/JRuby entirely.

from gherkin2.

aslakhellesoy avatar aslakhellesoy commented on September 27, 2024

I see, pure ruby. That's great.

from gherkin2.

ghnatiuk avatar ghnatiuk commented on September 27, 2024

We've got the parser sending a syntax_error message now if it finds something that doesn't make sense. Parsing effectively stops at that point. We'll probably leave the message ("Expecting Scenario, Feature, Background....") up to the listener for now, though it wouldn't be too hard to do with the policy proxy, either.

from gherkin2.

aslakhellesoy avatar aslakhellesoy commented on September 27, 2024

Delegating that to the parser is fine for now. We can push it into the policy later if we want.

from gherkin2.

msassak avatar msassak commented on September 27, 2024

My master uses two exceptions now: ParsingError and FeatureSyntaxError. ParsingError is thrown by the Ragel parser when it can't parse something (literally when parsing ends in an error state rather than the expected final state). FeatureSyntaxError is thrown by the policy when event messages are received out of order. If the policy is told not to raise, #syntax_error is sent to the listener instead.

from gherkin2.

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.