Coverage for src/rejuvenation/descendant_search.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-10-02 13:12 +0000

1"""AI: Example helper for matching nested (descendant) AST patterns.""" 

2 

3from arpeggio import flatten 

4 

5from renaissance.syntax_tree import PatternMatch 

6from renaissance.syntax_tree.ast_node import ASTNode 

7from renaissance.syntax_tree.match_finder import match_pattern 

8 

9 

10def find_descendant_match(root: ASTNode, outer_pattern: ASTNode, inner_pattern: ASTNode) -> list[PatternMatch]: 

11 """AI: Return matches of `inner_pattern` nested within nodes matching `outer_pattern`.""" 

12 return flatten(match_pattern(match.nodes, [inner_pattern]) for match in match_pattern(root.children, [outer_pattern]))