forked from cucumber/gherkin-c
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgherkin.berp
37 lines (28 loc) · 1.67 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
[
Tokens -> #Empty,#Comment,#TagLine,#FeatureLine,#BackgroundLine,#ScenarioLine,#ScenarioOutlineLine,#ExamplesLine,#StepLine,#DocStringSeparator,#TableRow,#Language
IgnoredTokens -> #Comment,#Empty
ClassName -> Parser
Namespace -> Gherkin
]
GherkinDocument! := Feature?
Feature! := Feature_Header Background? Scenario_Definition*
Feature_Header! := #Language? Tags? #FeatureLine Description_Helper
Background! := #BackgroundLine Description_Helper Step*
// we could avoid defining Scenario_Definition, but that would require regular look-aheads, so worse performance
Scenario_Definition! := Tags? (Scenario | ScenarioOutline)
Scenario! := #ScenarioLine Description_Helper Step*
ScenarioOutline! := #ScenarioOutlineLine Description_Helper Step* Examples_Definition*
// after the first "Examples" 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
Examples_Definition! [#Empty|#Comment|#TagLine->#ExamplesLine]:= Tags? Examples
Examples! := #ExamplesLine Description_Helper Examples_Table?
Examples_Table! := #TableRow #TableRow*
Step! := #StepLine Step_Arg?
Step_Arg := (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
Description_Helper := #Empty* Description? #Comment*
Description! := #Other+