Comments (6)
ParsingError comes from the Ragel part of Gherkin, so think it makes more sense to add that information to the Cucumber code which instantiates the Gherkin parser and then calls the parser's #scan method. Something like:
gherkin_parser = Gherkin::Feature.new(lang, listener)
begin
gherkin_parser.scan(input_string)
rescue ParsingError => e
raise CucumberParsingError.new("/path/to/example.feature", e.line, e.content)
end
This way the Gherkin parser doesn't need any knowledge of the source of the input. Gherkin can also throw a FeatureSyntaxError on syntax errors. The difference between the two is that ParsingError means Ragel cannot recognize the input tokens, so it can't continue at all, whereas FeatureSyntaxError means the listener has received an event when it should not have, e.g. a py_string was encountered within an examples table. You can tell Gherkin not to raise a FeatureSyntaxError and send a syntax error message to the listener instead, but it's really impractical to even try to recover from a ParsingError, so that one is a full stop.
Thoughts?
from gherkin2.
Makes total sense.
I threw this together earlier on actually: http://github.com/mattwynne/cucumber/commit/e4ab3aa3c2adce3f1bf97cd4f406a533852e91b9
I guess we just need a feature or two for the gherkin parser integration in cucumber to drive this out?
from gherkin2.
Definitely. Also worth considering: adding an attribute writer on ParsingError (say "source") which would change the error message. That way clients of Gherkin can just add it if needed.
from gherkin2.
How about just adding a scan_file method? That should do it for LexingError. The parser doesn't know about the file, but the lexer could intercept any ParseErrors and just add the file info before throwing it up.
Needs to be done in Ruby, C and Java
from gherkin2.
I'm not sure about the scan_file method. That seems to add the responsibility of knowing the execution environment into Gherkin, when it could be handled within Cucumber. Currently all the Gherkin lexer needs is a string--where that came from it does not care. If there is a lexing or parsing error, the gherkin parser plugin in Cucumber could catch it, add the info and then raise.
from gherkin2.
Good point Mike. I'll close this then. No knowledge of source location in Gherkin.
from gherkin2.
Related Issues (20)
- JS JSONFormatter - No way to attach an embedding without base64 encoding HOT 2
- Unable to compile
- Support i18n in snippet generation HOT 4
- cannot load such file -- 2.1/gherkin_lexer_en HOT 10
- [Java] Ugly formatting for CJK data containing full-width characters
- [Suggestion] Delete merged branches from the repo
- [Ruby] Backslashes in tables HOT 1
- SyntaxError in output HOT 1
- Background.feature is nil (in Cucumber 2.0) HOT 1
- Couldn't load 2.1/gherkin_lexer_en HOT 3
- Scenerios should be randomized across feature files, not just within a feature file HOT 2
- NPE in JSONFormatter in scenario print in a @Before HOT 1
- Getting Lexing Error HOT 5
- Cucumber generating empty JSON file upon multiple feature failures. HOT 1
- cucumber for java: number format exception when using tag with semicolon in name HOT 5
- allow tagging individual outline examples HOT 1
- Request for new release HOT 3
- Pretty formatter cannot handle comments in feature correctly
- Source files without license headers HOT 4
- NullPointerException when 'type' property is missing 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 gherkin2.