Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing error on feature with comment and tag (#35) #37

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ All user visible changes to `gherkin` crate will be documented in this file. Thi

- Bump up [MSRV] to 1.62 to support newer versions of dependencies.

### Fixed

- Parsing error on a `Feature` having comment and `Tag` simultaneously. (#37, #35)

[#35]: /../../issues/35
[#37]: /../../pull/37




Expand Down
10 changes: 7 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ rule _() = quiet!{[' ' | '\t']*}
rule __() = quiet!{([' ' | '\t'] / nl())*}

rule nl0() = quiet!{"\r"? "\n"}
rule nl() = quiet!{nl0() p:position!() comment()* {
rule nl_no_comment() = quiet!{nl0() p:position!() {
env.increment_nl(p);
}}
rule nl() = quiet!{comment_no_nl()? nl0() p:position!() {
env.increment_nl(p);
}}
rule eof() = quiet!{![_]}
rule nl_eof() = quiet!{(nl() / [' ' | '\t'])+ / eof()}
rule comment() = quiet!{[' ' | '\t']* "#" $((!nl0()[_])*) nl_eof()}
rule comment_no_nl() = quiet!{[' ' | '\t']* "#" $((!nl0()[_])*)}
rule comment() = quiet!{comment_no_nl() nl_eof()}
rule not_nl() -> &'input str = n:$((!nl0()[_])+) { n }

rule keyword1(list: &[&str]) -> &'input str
Expand Down Expand Up @@ -197,7 +201,7 @@ pub(crate) rule keyword<'a>(list: &[&'a str]) -> &'a str
}

rule language_directive() -> ()
= __ "#" _ "language" _ ":" _ l:$(not_nl()+) _ nl() {?
= ([' ' | '\t'] / nl_no_comment())* "#" _ "language" _ ":" _ l:$(not_nl()+) _ nl() {?
env.set_language(l)
}

Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/data/good/feature_with_comment.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#comment
Feature: feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"gherkinDocument":{"comments":["comment"],"feature":{"children":[],"description":"","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"feature","tags":[]},"uri":"testdata/good/feature_with_comment.feature"}}
3 changes: 3 additions & 0 deletions tests/fixtures/data/good/feature_with_comment_and_tag.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#comment
@tag
Feature: feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"gherkinDocument":{"comments":["comment"],"feature":{"children":[],"description":"","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"feature","tags":["tag"]},"uri":"testdata/good/feature_with_comment.feature"}}
2 changes: 2 additions & 0 deletions tests/fixtures/data/good/feature_with_tag.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tag
Feature: feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"gherkinDocument":{"comments":[],"feature":{"children":[],"description":"","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"feature","tags":["tag"]},"uri":"testdata/good/feature_with_tag.feature"}}