line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gherkin::TokenMatcher; |
2
|
|
|
|
|
|
|
$Gherkin::TokenMatcher::VERSION = '25.0.2'; |
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use List::Util qw(any first reduce); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
131
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $LANGUAGE_RE = qr/^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/o; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
|
|
7
|
use Class::XSAccessor accessors => [ |
11
|
|
|
|
|
|
|
qw/dialect _default_dialect_name _indent_to_remove _active_doc_string_separator _keyword_types /, |
12
|
1
|
|
|
1
|
|
8
|
]; |
|
1
|
|
|
|
|
2
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
375
|
use Cucumber::Messages; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
15
|
1
|
|
|
1
|
|
407
|
use Gherkin::Dialect; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1740
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
3
|
|
|
3
|
1
|
8
|
my ( $class, $options ) = @_; |
20
|
3
|
|
33
|
|
|
28
|
$options->{'dialect'} ||= Gherkin::Dialect->new( { dialect => 'en' } ); |
21
|
3
|
|
|
|
|
9
|
my $self = bless $options, $class; |
22
|
3
|
|
|
|
|
9
|
$self->_default_dialect_name( $self->dialect_name ); |
23
|
3
|
|
|
|
|
12
|
$self->reset(); |
24
|
3
|
|
|
|
|
32
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _add_keyword_type_mappings { |
28
|
24
|
|
|
24
|
|
43
|
my ($keyword_types, $keywords, $type) = @_; |
29
|
|
|
|
|
|
|
|
30
|
24
|
|
|
|
|
71
|
for my $keyword (@$keywords) { |
31
|
60
|
100
|
|
|
|
114
|
if (not exists $keyword_types->{$keyword}) { |
32
|
36
|
|
|
|
|
66
|
$keyword_types->{$keyword} = []; |
33
|
|
|
|
|
|
|
} |
34
|
60
|
|
|
|
|
76
|
push @{$keyword_types->{$keyword}}, $type; |
|
60
|
|
|
|
|
119
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
39
|
|
|
39
|
1
|
174
|
sub dialect_name { $_[0]->dialect->dialect } |
39
|
|
|
|
|
|
|
sub change_dialect { |
40
|
6
|
|
|
6
|
1
|
9
|
my $self = shift; |
41
|
6
|
|
|
|
|
22
|
$self->dialect->change_dialect(@_); |
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
|
|
11
|
my $keyword_types = {}; |
44
|
6
|
|
|
|
|
20
|
_add_keyword_type_mappings($keyword_types, $self->dialect->Given, |
45
|
|
|
|
|
|
|
Cucumber::Messages::Step::KEYWORDTYPE_CONTEXT); |
46
|
6
|
|
|
|
|
22
|
_add_keyword_type_mappings($keyword_types, $self->dialect->When, |
47
|
|
|
|
|
|
|
Cucumber::Messages::Step::KEYWORDTYPE_ACTION); |
48
|
6
|
|
|
|
|
18
|
_add_keyword_type_mappings($keyword_types, $self->dialect->Then, |
49
|
|
|
|
|
|
|
Cucumber::Messages::Step::KEYWORDTYPE_OUTCOME); |
50
|
|
|
|
|
|
|
_add_keyword_type_mappings($keyword_types, |
51
|
6
|
|
|
|
|
10
|
[ @{ $self->dialect->And }, @{ $self->dialect->But } ], |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
16
|
|
52
|
|
|
|
|
|
|
Cucumber::Messages::Step::KEYWORDTYPE_CONJUNCTION); |
53
|
6
|
|
|
|
|
24
|
$self->_keyword_types( $keyword_types ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub reset { |
57
|
6
|
|
|
6
|
1
|
10
|
my $self = shift; |
58
|
6
|
|
|
|
|
18
|
$self->change_dialect( $self->_default_dialect_name ); |
59
|
6
|
|
|
|
|
16
|
$self->_indent_to_remove(0); |
60
|
6
|
|
|
|
|
15
|
$self->_active_doc_string_separator(undef); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub match_FeatureLine { |
65
|
3
|
|
|
3
|
0
|
8
|
my ( $self, $token ) = @_; |
66
|
3
|
|
|
|
|
12
|
$self->_match_title_line( $token, FeatureLine => $self->dialect->Feature ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub match_RuleLine { |
70
|
9
|
|
|
9
|
0
|
15
|
my ( $self, $token ) = @_; |
71
|
9
|
|
|
|
|
28
|
$self->_match_title_line( $token, |
72
|
|
|
|
|
|
|
RuleLine => $self->dialect->Rule ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub match_ScenarioLine { |
76
|
15
|
|
|
15
|
0
|
24
|
my ( $self, $token ) = @_; |
77
|
15
|
100
|
|
|
|
48
|
$self->_match_title_line( |
78
|
|
|
|
|
|
|
$token, |
79
|
|
|
|
|
|
|
ScenarioLine => $self->dialect->Scenario ) |
80
|
|
|
|
|
|
|
or $self->_match_title_line( |
81
|
|
|
|
|
|
|
$token, |
82
|
|
|
|
|
|
|
ScenarioLine => $self->dialect->ScenarioOutline );; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub match_BackgroundLine { |
86
|
3
|
|
|
3
|
0
|
6
|
my ( $self, $token ) = @_; |
87
|
3
|
|
|
|
|
14
|
$self->_match_title_line( $token, |
88
|
|
|
|
|
|
|
BackgroundLine => $self->dialect->Background ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub match_ExamplesLine { |
92
|
6
|
|
|
6
|
0
|
13
|
my ( $self, $token ) = @_; |
93
|
6
|
|
|
|
|
18
|
$self->_match_title_line( $token, |
94
|
|
|
|
|
|
|
ExamplesLine => $self->dialect->Examples ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub match_Language { |
98
|
3
|
|
|
3
|
0
|
18
|
my ( $self, $token ) = @_; |
99
|
3
|
50
|
|
|
|
14
|
if ( $token->line->get_line_text =~ $LANGUAGE_RE ) { |
100
|
0
|
|
|
|
|
0
|
my $dialect_name = $1; |
101
|
0
|
|
|
|
|
0
|
$self->_set_token_matched( $token, |
102
|
|
|
|
|
|
|
Language => { text => $dialect_name } ); |
103
|
0
|
|
|
|
|
0
|
$self->change_dialect( $dialect_name, $token->location ); |
104
|
0
|
|
|
|
|
0
|
return 1; |
105
|
|
|
|
|
|
|
} else { |
106
|
3
|
|
|
|
|
10
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub match_TagLine { |
111
|
39
|
|
|
39
|
0
|
62
|
my ( $self, $token ) = @_; |
112
|
39
|
50
|
|
|
|
92
|
return unless $token->line->startswith('@'); |
113
|
0
|
|
|
|
|
0
|
$self->_set_token_matched( $token, |
114
|
|
|
|
|
|
|
TagLine => { items => $token->line->tags } ); |
115
|
0
|
|
|
|
|
0
|
return 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _match_title_line { |
119
|
45
|
|
|
45
|
|
88
|
my ( $self, $token, $token_type, $keywords ) = @_; |
120
|
|
|
|
|
|
|
|
121
|
45
|
|
|
|
|
76
|
for my $keyword (@$keywords) { |
122
|
75
|
100
|
|
|
|
204
|
if ( $token->line->startswith_title_keyword($keyword) ) { |
123
|
12
|
|
|
|
|
38
|
my $title = |
124
|
|
|
|
|
|
|
$token->line->get_rest_trimmed( length( $keyword . ': ' ) ); |
125
|
12
|
|
|
|
|
105
|
$self->_set_token_matched( $token, $token_type, |
126
|
|
|
|
|
|
|
{ text => $title, keyword => $keyword } ); |
127
|
12
|
|
|
|
|
62
|
return 1; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
33
|
|
|
|
|
102
|
return; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _set_token_matched { |
135
|
36
|
|
|
36
|
|
70
|
my ( $self, $token, $matched_type, $options ) = @_; |
136
|
36
|
|
50
|
|
|
184
|
$options->{'items'} ||= []; |
137
|
36
|
|
|
|
|
118
|
$token->matched_type($matched_type); |
138
|
|
|
|
|
|
|
|
139
|
36
|
100
|
|
|
|
82
|
if ( defined $options->{'text'} ) { |
140
|
21
|
|
|
|
|
45
|
chomp( $options->{'text'} ); |
141
|
21
|
|
|
|
|
52
|
$token->matched_text( $options->{'text'} ); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$token->matched_keyword( $options->{'keyword'} ) |
145
|
36
|
100
|
|
|
|
97
|
if defined $options->{'keyword'}; |
146
|
|
|
|
|
|
|
$token->matched_keyword_type( $options->{'keyword_type'} ) |
147
|
36
|
100
|
|
|
|
94
|
if defined $options->{'keyword_type'}; |
148
|
|
|
|
|
|
|
|
149
|
36
|
100
|
|
|
|
70
|
if ( defined $options->{'indent'} ) { |
150
|
12
|
|
|
|
|
22
|
$token->matched_indent( $options->{'indent'} ); |
151
|
|
|
|
|
|
|
} else { |
152
|
24
|
100
|
|
|
|
81
|
$token->matched_indent( $token->line ? $token->line->indent : 0 ); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$token->matched_items( $options->{'items'} ) |
156
|
36
|
50
|
|
|
|
93
|
if defined $options->{'items'}; |
157
|
|
|
|
|
|
|
|
158
|
36
|
|
|
|
|
96
|
$token->location->{'column'} = $token->matched_indent + 1; |
159
|
36
|
|
|
|
|
76
|
$token->matched_gherkin_dialect( $self->dialect_name ); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub match_EOF { |
163
|
36
|
|
|
36
|
0
|
59
|
my ( $self, $token ) = @_; |
164
|
36
|
100
|
|
|
|
82
|
return unless $token->is_eof; |
165
|
3
|
|
|
|
|
15
|
$self->_set_token_matched( $token, 'EOF' ); |
166
|
3
|
|
|
|
|
8
|
return 1; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub match_Empty { |
170
|
24
|
|
|
24
|
0
|
38
|
my ( $self, $token ) = @_; |
171
|
24
|
100
|
|
|
|
65
|
return unless $token->line->is_empty; |
172
|
12
|
|
|
|
|
56
|
$self->_set_token_matched( $token, Empty => { indent => 0 } ); |
173
|
12
|
|
|
|
|
38
|
return 1; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub match_Comment { |
177
|
21
|
|
|
21
|
0
|
37
|
my ( $self, $token ) = @_; |
178
|
21
|
50
|
|
|
|
48
|
return unless $token->line->startswith('#'); |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
my $comment_text = $token->line->line_text; |
181
|
0
|
|
|
|
|
0
|
$comment_text =~ s/\r\n$//; # Why? |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
0
|
$self->_set_token_matched( $token, |
184
|
|
|
|
|
|
|
Comment => { text => $comment_text, indent => 0 } ); |
185
|
0
|
|
|
|
|
0
|
return 1; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub match_Other { |
189
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $token ) = @_; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# take the entire line, except removing DocString indents |
192
|
0
|
|
|
|
|
0
|
my $text = $token->line->get_line_text( $self->_indent_to_remove ); |
193
|
0
|
|
|
|
|
0
|
$self->_set_token_matched( $token, |
194
|
|
|
|
|
|
|
Other => { indent => 0, text => $self->_unescaped_docstring($text) } ); |
195
|
0
|
|
|
|
|
0
|
return 1; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _unescaped_docstring { |
199
|
0
|
|
|
0
|
|
0
|
my ( $self, $text ) = @_; |
200
|
0
|
0
|
|
|
|
0
|
if ( $self->_active_doc_string_separator ) { |
201
|
0
|
|
|
|
|
0
|
$text =~ s!\\"\\"\\"!"""!; |
202
|
0
|
|
|
|
|
0
|
$text =~ s!\\`\\`\\`!```!; |
203
|
0
|
|
|
|
|
0
|
return $text; |
204
|
|
|
|
|
|
|
} else { |
205
|
0
|
|
|
|
|
0
|
return $text; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub match_StepLine { |
210
|
24
|
|
|
24
|
0
|
43
|
my ( $self, $token ) = @_; |
211
|
24
|
|
|
|
|
44
|
my @keywords = map { @{ $self->dialect->$_ } } qw/Given When Then And But/; |
|
120
|
|
|
|
|
173
|
|
|
120
|
|
|
|
|
290
|
|
212
|
24
|
|
|
|
|
49
|
my $line = $token->line; |
213
|
|
|
|
|
|
|
|
214
|
24
|
|
|
|
|
58
|
for my $keyword (@keywords) { |
215
|
168
|
100
|
|
|
|
301
|
if ( $line->startswith($keyword) ) { |
216
|
9
|
|
|
|
|
22
|
my $title = $line->get_rest_trimmed( length($keyword) ); |
217
|
|
|
|
|
|
|
my $keyword_type = |
218
|
9
|
|
|
|
|
42
|
(scalar @{$self->_keyword_types->{$keyword}} > 1) |
219
|
|
|
|
|
|
|
? Cucumber::Messages::Step::KEYWORDTYPE_UNKNOWN |
220
|
9
|
50
|
|
|
|
17
|
: $self->_keyword_types->{$keyword}->[0]; |
221
|
9
|
|
|
|
|
51
|
$self->_set_token_matched( |
222
|
|
|
|
|
|
|
$token, |
223
|
|
|
|
|
|
|
StepLine => { |
224
|
|
|
|
|
|
|
text => $title, |
225
|
|
|
|
|
|
|
keyword => $keyword, |
226
|
|
|
|
|
|
|
keyword_type => $keyword_type, |
227
|
|
|
|
|
|
|
} ); |
228
|
9
|
|
|
|
|
42
|
return 1; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
15
|
|
|
|
|
43
|
return; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub match_DocStringSeparator { |
235
|
15
|
|
|
15
|
0
|
26
|
my ( $self, $token ) = @_; |
236
|
15
|
50
|
|
|
|
36
|
if ( !$self->_active_doc_string_separator ) { |
237
|
15
|
|
33
|
|
|
32
|
return $self->_match_DocStringSeparator( $token, '"""', 1 ) |
238
|
|
|
|
|
|
|
|| $self->_match_DocStringSeparator( $token, '```', 1 ); |
239
|
|
|
|
|
|
|
} else { |
240
|
0
|
|
|
|
|
0
|
return $self->_match_DocStringSeparator( $token, |
241
|
|
|
|
|
|
|
$self->_active_doc_string_separator, 0 ); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub _match_DocStringSeparator { |
246
|
30
|
|
|
30
|
|
59
|
my ( $self, $token, $separator, $is_open ) = @_; |
247
|
30
|
50
|
|
|
|
63
|
return unless $token->line->startswith($separator); |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
0
|
my $content_type; |
250
|
0
|
0
|
|
|
|
0
|
if ($is_open) { |
251
|
0
|
|
|
|
|
0
|
$content_type = $token->line->get_rest_trimmed( length($separator) ); |
252
|
0
|
|
|
|
|
0
|
$self->_active_doc_string_separator($separator); |
253
|
0
|
|
|
|
|
0
|
$self->_indent_to_remove( $token->line->indent ); |
254
|
|
|
|
|
|
|
} else { |
255
|
0
|
|
|
|
|
0
|
$self->_active_doc_string_separator(undef); |
256
|
0
|
|
|
|
|
0
|
$self->_indent_to_remove(0); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
0
|
$self->_set_token_matched( $token, |
260
|
|
|
|
|
|
|
DocStringSeparator => { text => $content_type, keyword => $separator } ); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub match_TableRow { |
264
|
15
|
|
|
15
|
0
|
29
|
my ( $self, $token ) = @_; |
265
|
15
|
50
|
|
|
|
37
|
return unless $token->line->startswith('|'); |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
$self->_set_token_matched( $token, |
268
|
|
|
|
|
|
|
TableRow => { items => $token->line->table_cells } ); |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
1; |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
__END__ |