@@ -23,7 +23,6 @@ class Parser(NamedTuple):
23
23
24
24
25
25
class CucumberExpressionParser :
26
-
27
26
# text == whitespace | ')' | '}' | .
28
27
@staticmethod
29
28
def parse_text (parser : Parser ):
@@ -34,9 +33,7 @@ def parse_text(parser: Parser):
34
33
TokenType .END_PARAMETER ,
35
34
TokenType .END_OPTIONAL ,
36
35
]:
37
- return Result (
38
- 1 , Node (NodeType .TEXT , None , token .text , token .start , token .end )
39
- )
36
+ return Result (1 , Node (NodeType .TEXT , None , token .text , token .start , token .end ))
40
37
if token .ast_type == TokenType .ALTERNATION :
41
38
raise AlternationNotAllowedInOptional (parser .expression , token )
42
39
# If configured correctly this will never happen
@@ -47,9 +44,7 @@ def parse_text(parser: Parser):
47
44
def parse_name (parser : Parser ):
48
45
token = parser .tokens [parser .current ]
49
46
if token .ast_type in [TokenType .WHITE_SPACE , TokenType .TEXT ]:
50
- return Result (
51
- 1 , Node (NodeType .TEXT , None , token .text , token .start , token .end )
52
- )
47
+ return Result (1 , Node (NodeType .TEXT , None , token .text , token .start , token .end ))
53
48
if token .ast_type in [
54
49
TokenType .BEGIN_PARAMETER ,
55
50
TokenType .END_PARAMETER ,
@@ -90,9 +85,7 @@ def parse_alternative_separator(parser: Parser) -> Result:
90
85
if not self .looking_at (tokens , parser .current , TokenType .ALTERNATION ):
91
86
return Result (0 , None )
92
87
token = tokens [parser .current ]
93
- return Result (
94
- 1 , Node (NodeType .ALTERNATIVE , None , token .text , token .start , token .end )
95
- )
88
+ return Result (1 , Node (NodeType .ALTERNATIVE , None , token .text , token .start , token .end ))
96
89
97
90
alternative_parsers = [
98
91
parse_alternative_separator ,
@@ -130,11 +123,7 @@ def parse_alternation(parser: Parser) -> Result:
130
123
],
131
124
)
132
125
sub_current = parser .current + consumed
133
- if not [
134
- _ast_node .ast_type
135
- for _ast_node in ast_nodes
136
- if _ast_node .ast_type == NodeType .ALTERNATIVE
137
- ]:
126
+ if not [_ast_node .ast_type for _ast_node in ast_nodes if _ast_node .ast_type == NodeType .ALTERNATIVE ]:
138
127
return Result (0 , None )
139
128
140
129
start = tokens [parser .current ].start
@@ -204,9 +193,7 @@ def _parse_between(parser: Parser):
204
193
return _parse_between
205
194
206
195
@staticmethod
207
- def parse_token (
208
- expression , parsers : List , tokens : List [Token ], start_at : int
209
- ) -> Result :
196
+ def parse_token (expression , parsers : List , tokens : List [Token ], start_at : int ) -> Result :
210
197
for parser in parsers :
211
198
consumed , ast = parser (Parser (expression , tokens , start_at ))
212
199
if consumed :
@@ -237,12 +224,8 @@ def parse_tokens_until(
237
224
ast .append (result .ast_node )
238
225
return current - start_at , ast
239
226
240
- def looking_at_any (
241
- self , tokens : List [Token ], position : int , token_types : List [TokenType ]
242
- ) -> bool :
243
- return any (
244
- self .looking_at (tokens , position , token_type ) for token_type in token_types
245
- )
227
+ def looking_at_any (self , tokens : List [Token ], position : int , token_types : List [TokenType ]) -> bool :
228
+ return any (self .looking_at (tokens , position , token_type ) for token_type in token_types )
246
229
247
230
@staticmethod
248
231
def looking_at (tokens : List [Token ], position : int , token_type : TokenType ) -> bool :
@@ -254,9 +237,7 @@ def looking_at(tokens: List[Token], position: int, token_type: TokenType) -> boo
254
237
return token_type == TokenType .END_OF_LINE
255
238
return tokens [position ].ast_type == token_type
256
239
257
- def split_alternatives (
258
- self , start : int , end : int , alternation : List [Node ]
259
- ) -> List [Node ]:
240
+ def split_alternatives (self , start : int , end : int , alternation : List [Node ]) -> List [Node ]:
260
241
separators = []
261
242
alternatives = []
262
243
alternative = []
@@ -271,9 +252,7 @@ def split_alternatives(
271
252
return list (self .create_alternative_nodes (start , end , separators , alternatives ))
272
253
273
254
@staticmethod
274
- def create_alternative_nodes (
275
- start : int , end : int , separators : List , alternatives : List
276
- ) -> List [Node ]:
255
+ def create_alternative_nodes (start : int , end : int , separators : List , alternatives : List ) -> List [Node ]:
277
256
for index , alternative in enumerate (alternatives ):
278
257
if index == 0 :
279
258
right_separator = separators [index ]
@@ -286,9 +265,7 @@ def create_alternative_nodes(
286
265
)
287
266
elif index == len (alternatives ) - 1 :
288
267
left_separator = separators [index - 1 ]
289
- yield Node (
290
- NodeType .ALTERNATIVE , alternative , None , left_separator .end , end
291
- )
268
+ yield Node (NodeType .ALTERNATIVE , alternative , None , left_separator .end , end )
292
269
else :
293
270
left_separator = separators [index - 1 ]
294
271
right_separator = separators [index ]
0 commit comments