Skip to content

Commit

Permalink
Fix parsing error on feature with comment and tag (#37, #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilslv authored Oct 24, 2022
1 parent 4782559 commit c21fafd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 3 deletions.
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"}}

0 comments on commit c21fafd

Please sign in to comment.