Skip to content

Commit a9a8a4b

Browse files
committed
[Py] Handle case where line_tokens in Description AST node can be an empty list
1 parent 46bb437 commit a9a8a4b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

python/gherkin/ast_builder.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,13 @@ def transform_node(
268268
return self.get_table_rows(node)
269269
elif node.rule_type == "Description":
270270
line_tokens = node.get_tokens("Other")
271+
tokens = list(line_tokens)
272+
271273
# Trim trailing empty lines
272-
last_non_empty = next(
273-
i for i, j in reversed(list(enumerate(line_tokens))) if j.matched_text
274-
)
275-
description = "\n".join(
276-
[token.matched_text for token in line_tokens[: last_non_empty + 1]]
277-
)
274+
while tokens and not tokens[-1].matched_text:
275+
tokens.pop()
278276

279-
return description
277+
return "\n".join(token.matched_text for token in tokens)
280278
elif node.rule_type == "Rule":
281279
header = cast(Union[AstNode, None], node.get_single("RuleHeader"))
282280
if not header:

0 commit comments

Comments
 (0)