-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
gherkin.berp
38 lines (29 loc) · 1.66 KB
/
gherkin.berp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[
Tokens -> #Empty,#Comment,#TagLine,#FeatureLine,#RuleLine,#BackgroundLine,#ScenarioLine,#ExamplesLine,#StepLine,#DocStringSeparator,#TableRow,#Language
IgnoredTokens -> #Comment,#Empty
ClassName -> Parser
Namespace -> Gherkin
]
GherkinDocument! := Feature?
Feature! := FeatureHeader Background? ScenarioDefinition* Rule*
FeatureHeader! := #Language? Tags? #FeatureLine DescriptionHelper
Rule! := RuleHeader Background? ScenarioDefinition*
RuleHeader! := Tags? #RuleLine DescriptionHelper
Background! := #BackgroundLine DescriptionHelper Step*
// Interpreting a tag line is ambiguous (tag line of rule or of scenario)
ScenarioDefinition! [#Empty|#Comment|#TagLine->#ScenarioLine]:= Tags? Scenario
Scenario! := #ScenarioLine DescriptionHelper Step* ExamplesDefinition*
// after the first "Data" block, interpreting a tag line is ambiguous (tagline of next examples or of next scenario)
// because of this, we need a lookahead hint, that connects the tag line to the next examples, if there is an examples block ahead
ExamplesDefinition! [#Empty|#Comment|#TagLine->#ExamplesLine]:= Tags? Examples
Examples! := #ExamplesLine DescriptionHelper ExamplesTable?
ExamplesTable! := #TableRow #TableRow*
Step! := #StepLine StepArg?
StepArg := (DataTable | DocString)
DataTable! := #TableRow+
DocString! := #DocStringSeparator #Other* #DocStringSeparator
Tags! := #TagLine+
// we need to explicitly mention comment, to avoid merging it into the description line's #Other token
// we also eat the leading empty lines, the tailing lines are not removed by the parser to avoid lookahead, this has to be done by the AST builder
DescriptionHelper := #Empty* Description? #Comment*
Description! := #Other+