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

6 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-15 10:34 +0000

1# Copyright (C) 2024-2026 TNO 

2# 

3# Licensed under the terms specified in the LICENSE file in the root directory 

4# of this repository, also available at: 

5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE 

6 

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

8 

9from arpeggio import flatten 

10 

11from renaissance.syntax_tree import PatternMatch 

12from renaissance.syntax_tree.ast_node import ASTNode 

13from renaissance.syntax_tree.match_finder import match_pattern 

14 

15 

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

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

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