-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgherkin.peg
131 lines (98 loc) · 3 KB
/
gherkin.peg
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package gherkin
type gherkinPeg Peg {
gherkinPegBase
buf1 string
buf2 string
buftags []string
bufcmt string
}
Begin <-
Feature?
OS !.
ScenarioKeyWord <-
('Background:' / 'Scenario:' / 'Scenario Outline:')
StepKeyWord <-
('Given' / 'When' / 'Then' / 'And' / 'Or' / 'But' / '*')
Feature <-
Tags 'Feature:' WS* <UntilLineEnd?>{{buf1}} <>{{buf2}} LineEnd
(WS* !('@' Word / ScenarioKeyWord) <UntilLineEnd?>{{++buf2}} LineEnd { p.buf2 = p.buf2 + "\n" })*
{ p.beginFeature(trimWS(p.buf1), trimWSML(p.buf2), p.buftags); p.buftags = nil }
( Background / Scenario / Outline / BlankLine )*
{ p.endFeature() }
Background <-
Tags 'Background:' WS* <UntilLineEnd?>{{buf1}} <>{{buf2}} LineEnd
(WS* !('@' Word / ScenarioKeyWord / StepKeyWord) <UntilLineEnd?>{{++buf2}} LineEnd { p.buf2 = p.buf2 + "\n" })*
{ p.beginBackground(trimWS(p.buf1), trimWSML(p.buf2), p.buftags); p.buftags = nil }
(Step / BlankLine)*
{ p.endBackground() }
Scenario <-
Tags 'Scenario:' WS* <UntilLineEnd?>{{buf1}} <>{{buf2}} LineEnd
(WS* !('@' Word / ScenarioKeyWord / StepKeyWord) <UntilLineEnd?>{{++buf2}} LineEnd { p.buf2 = p.buf2 + "\n" })*
{ p.beginScenario(trimWS(p.buf1), trimWSML(p.buf2), p.buftags); p.buftags = nil }
(Step / BlankLine)*
{ p.endScenario() }
Outline <-
Tags 'Scenario Outline:' WS* <UntilLineEnd?>{{buf1}} <>{{buf2}} LineEnd
(WS* !('@' Word / ScenarioKeyWord / StepKeyWord) <UntilLineEnd?>{{++buf2}} LineEnd { p.buf2 = p.buf2 + "\n" })*
{ p.beginOutline(trimWS(p.buf1), trimWSML(p.buf2), p.buftags); p.buftags = nil }
(Step / BlankLine)*
(OutlineExamples / BlankLine)*
{ p.endOutline() }
OutlineExamples <-
OS 'Examples:' WS* <UntilLineEnd?>{{buf1}} LineEnd
{ p.beginOutlineExamples(trimWS(p.buf1)) }
Table?
{ p.endOutlineExamples() }
Step <-
WS* <(StepKeyWord)>{{buf1}}
WS* <UntilLineEnd>{{buf2}} LineEnd
{ p.beginStep(trimWS(p.buf1), trimWS(p.buf2)) }
StepArgument?
{ p.endStep() }
StepArgument
<- Table
/ PyString
PyString <-
(WS* NL)* <WS*> PyStringQuote NL
{ p.beginPyString(buffer[begin:end]) }
(!(WS* PyStringQuote) PyStringLine)*
WS* PyStringQuote LineEnd
{ p.endPyString() }
PyStringQuote <- '\"' '\"' '\"'
PyStringLine <-
< UntilNL > NL
{ p.bufferPyString(buffer[begin:end]) }
Table <-
{ p.beginTable() }
TableRow+
{ p.endTable() }
TableRow <-
{ p.beginTableRow() }
OS '|' TableCell+ LineEnd
{ p.endTableRow() }
TableCell <-
<( [^\r\n|]+ )> '|'
{ p.beginTableCell(); p.endTableCell(trimWS(buffer[begin:end])) }
Tags <-
(Tag+ WS* LineEnd?)* OS
Tag <-
OS '@' <( Word )>{{[]buftags}}
Word <-
[^\r\n\t "#]+
EscapedChar <- '\\' .
QuotedString <-
'"' ( EscapedChar / [^\n\\"]+ )* '"'
UntilLineEnd <-
( EscapedChar / [^\n\\"#]+ / QuotedString )+
LineEnd <-
WS* LineComment? NL
LineComment <-
'#' < [^\n]* >
{ p.bufcmt = buffer[begin:end]; p.triggerComment(p.bufcmt) }
BlankLine <-
( WS LineEnd / ( LineComment? NL ) )
{ p.triggerBlankLine() }
OS <- (NL/WS)*
WS <- (' ' / '\t')
UntilNL <- [^\n]*
NL <- ('\n' / '\r' / '\r\n')