gherkin icon indicating copy to clipboard operation
gherkin copied to clipboard

[cucumber/gherkin] - comments in feature description cause a parse error

Open ciaranmcnulty opened this issue 4 years ago • 4 comments

Summary

It looks like comments in any part of the feature description are currently disallowed:

Feature: Using a comment in feature description

  # comment 1
  This is the feature description
  # comment 2

  Example: A normal example

Current Behavior

The text line that comprises the feature description is not allowed to follow the comment 1 so a parse error is thrown. The comment 2 is allowed because it's followed by an Example, so if only comment 1 is removed the file parses correctly.

(4:3): expected: #EOF, #Comment, #BackgroundLine, #TagLine, #ScenarioLine, #RuleLine, #Empty, got '  This is the feature description'

Context & Motivation

I'm generally looking at where comments are allowed by the parser for behat compatibility and this came up

Your Environment

  • Version used: Go gherkin binary, 17.0.2 darwin amd64
  • Operating System and version: macOS Big Sur (M1)

ciaranmcnulty avatar Mar 09 '21 11:03 ciaranmcnulty

Yes, this seem to be disallowed by the grammar. I don't know whether this was intentional though. https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin.berp#L37

FeatureHeader! := #Language? Tags? #FeatureLine DescriptionHelper
...
DescriptionHelper := #Empty* Description? #Comment*

gasparnagy avatar May 06 '21 07:05 gasparnagy

Whether it was intentional I think it's clearly wrong - I don't know how to fix it though? ;)

ciaranmcnulty avatar Jul 09 '22 09:07 ciaranmcnulty

@ciaranmcnulty Are commented lines allowed before the Feature? It is sometimes important to add comments to tags; if those tags precede 'Feature' then comments should be allowed there as well. (And lines that are neither comments nor tags should probably raise a parser error.)

If comments are not allowed before 'Feature', I think that should be addressed at the same time as this issue.

The-BDD-Coach avatar Dec 01 '22 16:12 The-BDD-Coach

Duplicate of #16?

enkessler avatar Aug 16 '23 05:08 enkessler