diff --git a/CHANGELOG.md b/CHANGELOG.md index b5056f2..463fe18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + diff --git a/src/parser.rs b/src/parser.rs index f366d21..bf617fe 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 @@ -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) } diff --git a/tests/fixtures/data/good/feature_with_comment.feature b/tests/fixtures/data/good/feature_with_comment.feature new file mode 100644 index 0000000..143bb23 --- /dev/null +++ b/tests/fixtures/data/good/feature_with_comment.feature @@ -0,0 +1,2 @@ +#comment +Feature: feature diff --git a/tests/fixtures/data/good/feature_with_comment.feature.ast.ndjson b/tests/fixtures/data/good/feature_with_comment.feature.ast.ndjson new file mode 100644 index 0000000..772ae46 --- /dev/null +++ b/tests/fixtures/data/good/feature_with_comment.feature.ast.ndjson @@ -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"}} diff --git a/tests/fixtures/data/good/feature_with_comment_and_tag.feature b/tests/fixtures/data/good/feature_with_comment_and_tag.feature new file mode 100644 index 0000000..ea11e70 --- /dev/null +++ b/tests/fixtures/data/good/feature_with_comment_and_tag.feature @@ -0,0 +1,3 @@ +#comment +@tag +Feature: feature diff --git a/tests/fixtures/data/good/feature_with_comment_and_tag.feature.ast.ndjson b/tests/fixtures/data/good/feature_with_comment_and_tag.feature.ast.ndjson new file mode 100644 index 0000000..df60eaf --- /dev/null +++ b/tests/fixtures/data/good/feature_with_comment_and_tag.feature.ast.ndjson @@ -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"}} diff --git a/tests/fixtures/data/good/feature_with_tag.feature b/tests/fixtures/data/good/feature_with_tag.feature new file mode 100644 index 0000000..857a899 --- /dev/null +++ b/tests/fixtures/data/good/feature_with_tag.feature @@ -0,0 +1,2 @@ +@tag +Feature: feature diff --git a/tests/fixtures/data/good/feature_with_tag.feature.ast.ndjson b/tests/fixtures/data/good/feature_with_tag.feature.ast.ndjson new file mode 100644 index 0000000..3234d11 --- /dev/null +++ b/tests/fixtures/data/good/feature_with_tag.feature.ast.ndjson @@ -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"}}