@@ -23,7 +23,6 @@ class Parser(NamedTuple):
2323
2424
2525class CucumberExpressionParser :
26-
2726 # text == whitespace | ')' | '}' | .
2827 @staticmethod
2928 def parse_text (parser : Parser ):
@@ -34,9 +33,7 @@ def parse_text(parser: Parser):
3433 TokenType .END_PARAMETER ,
3534 TokenType .END_OPTIONAL ,
3635 ]:
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 ))
4037 if token .ast_type == TokenType .ALTERNATION :
4138 raise AlternationNotAllowedInOptional (parser .expression , token )
4239 # If configured correctly this will never happen
@@ -47,9 +44,7 @@ def parse_text(parser: Parser):
4744 def parse_name (parser : Parser ):
4845 token = parser .tokens [parser .current ]
4946 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 ))
5348 if token .ast_type in [
5449 TokenType .BEGIN_PARAMETER ,
5550 TokenType .END_PARAMETER ,
@@ -90,9 +85,7 @@ def parse_alternative_separator(parser: Parser) -> Result:
9085 if not self .looking_at (tokens , parser .current , TokenType .ALTERNATION ):
9186 return Result (0 , None )
9287 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 ))
9689
9790 alternative_parsers = [
9891 parse_alternative_separator ,
@@ -130,11 +123,7 @@ def parse_alternation(parser: Parser) -> Result:
130123 ],
131124 )
132125 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 ]:
138127 return Result (0 , None )
139128
140129 start = tokens [parser .current ].start
@@ -204,9 +193,7 @@ def _parse_between(parser: Parser):
204193 return _parse_between
205194
206195 @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 :
210197 for parser in parsers :
211198 consumed , ast = parser (Parser (expression , tokens , start_at ))
212199 if consumed :
@@ -237,12 +224,8 @@ def parse_tokens_until(
237224 ast .append (result .ast_node )
238225 return current - start_at , ast
239226
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 )
246229
247230 @staticmethod
248231 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
254237 return token_type == TokenType .END_OF_LINE
255238 return tokens [position ].ast_type == token_type
256239
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 ]:
260241 separators = []
261242 alternatives = []
262243 alternative = []
@@ -271,9 +252,7 @@ def split_alternatives(
271252 return list (self .create_alternative_nodes (start , end , separators , alternatives ))
272253
273254 @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 ]:
277256 for index , alternative in enumerate (alternatives ):
278257 if index == 0 :
279258 right_separator = separators [index ]
@@ -286,9 +265,7 @@ def create_alternative_nodes(
286265 )
287266 elif index == len (alternatives ) - 1 :
288267 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 )
292269 else :
293270 left_separator = separators [index - 1 ]
294271 right_separator = separators [index ]
0 commit comments