You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is probably a stupid and/or rookie question, but I've spent quite a bit of time trying to figure it out, and getting nowhere...
I'm trying to create a Gherkin / Cucumber / BDD parser. For those unfamiliar, that means I have input which looks like...
# Some feature comments
# which can go on multiple lines
Feature: This is a feature
These are some notes about the feature
which can also go on multiple lines
# The first scenario has two steps
# also multiple lines
Scenario: This is the first scenario
These are notes about the scenario
also multiple lines, although notes are
optional
Given some condition is already met
Then some ability is possible
# There can be multiple scenarios
Scenario: This is another scenario
Given some condition is already met
When something happens
Then we expect some change to happen
There can be multiple Steps in a scenario, and multiple Scenarios in a Feature. Oh, and the keywords (feature, scenario, given etc) can be localised.
I am trying to figure out how to parse the steps, and in particular, how to deal with cases where:
there is a single newline, because there is another step.
there are multiple newlines, because it's the end of the current scenario, but a new scenario starts.
there isn't a newline, because it's the end of the input.
I have this KeywordParser,
structKeywordParser:ParserPrinter{privateletkind:Keyword.Kindinit(for kind:Keyword.Kind){self.kind = kind
}varreservedWord:someParserPrinter<Substring,Substring>{OneOf{
for name in kind.localizedNames.styles {OneOf{PrefixThrough("\(name)")}}}}varbody:someParserPrinter<Substring,Keyword>{ParsePrint{Whitespace(.horizontal)
reservedWord.map(.string)
if kind.expectsSuffix {ParsePrint{":"}}Whitespace(1,.horizontal)Prefix{ false == $0.isNewline }.map(.string)Optionally{Prefix{ $0.isNewline }.map(.string)}}.map(.keyword(kind))// there is a conversion for this}}
This can be used to parse input such as:
FEATURE: Some feature title
feature: A different feature title
Scenario: A scenario title
GIVEN some phrase
when some phrase
etc.
What I can't seem to figure out, is how to parse the input after the keyword delimiter to the end of the line which is retained in the model, and then any number of new line characters, or possibly the end of the input.
I tried all sorts combinations of Optionally { } either inside this parser, or inside the separator of a Many { } parser (inside the Scenario Parser). But it seems that it just becomes greedy, and I end up with two steps where the 2nd one parses to the end of input.
Any ideas? Feels like parsing to the end of the line should be a fairly easy and common task, and composing that into a Many should be just as straightforward, no?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is probably a stupid and/or rookie question, but I've spent quite a bit of time trying to figure it out, and getting nowhere...
I'm trying to create a Gherkin / Cucumber / BDD parser. For those unfamiliar, that means I have input which looks like...
There can be multiple Steps in a scenario, and multiple Scenarios in a Feature. Oh, and the keywords (
feature
,scenario
,given
etc) can be localised.I am trying to figure out how to parse the steps, and in particular, how to deal with cases where:
I have this
KeywordParser
,This can be used to parse input such as:
etc.
What I can't seem to figure out, is how to parse the input after the keyword delimiter to the end of the line which is retained in the model, and then any number of new line characters, or possibly the end of the input.
I tried all sorts combinations of
Optionally { }
either inside this parser, or inside the separator of aMany { }
parser (inside the Scenario Parser). But it seems that it just becomes greedy, and I end up with two steps where the 2nd one parses to the end of input.Any ideas? Feels like parsing to the end of the line should be a fairly easy and common task, and composing that into a
Many
should be just as straightforward, no?Feel like I'm missing something...
Beta Was this translation helpful? Give feedback.
All reactions