Skip to content

Commit

Permalink
[Py] Handle case where line_tokens in Description AST node can be an …
Browse files Browse the repository at this point in the history
…empty list
  • Loading branch information
jsa34 committed Mar 8, 2025
1 parent 46bb437 commit a9a8a4b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions python/gherkin/ast_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,13 @@ def transform_node(
return self.get_table_rows(node)
elif node.rule_type == "Description":
line_tokens = node.get_tokens("Other")
tokens = list(line_tokens)

# Trim trailing empty lines
last_non_empty = next(
i for i, j in reversed(list(enumerate(line_tokens))) if j.matched_text
)
description = "\n".join(
[token.matched_text for token in line_tokens[: last_non_empty + 1]]
)
while tokens and not tokens[-1].matched_text:
tokens.pop()

return description
return "\n".join(token.matched_text for token in tokens)
elif node.rule_type == "Rule":
header = cast(Union[AstNode, None], node.get_single("RuleHeader"))
if not header:
Expand Down

0 comments on commit a9a8a4b

Please sign in to comment.