From 2b16673c1c7d4146261a670364c64e2cafb2b042 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Fri, 30 Aug 2024 12:12:29 -0400 Subject: [PATCH] rf: Walk all rules, collect all names --- .../bidsschematools/tests/test_expressions.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/schemacode/bidsschematools/tests/test_expressions.py b/tools/schemacode/bidsschematools/tests/test_expressions.py index a6f2800626..e2e0704b37 100644 --- a/tools/schemacode/bidsschematools/tests/test_expressions.py +++ b/tools/schemacode/bidsschematools/tests/test_expressions.py @@ -5,7 +5,16 @@ import pytest from pyparsing.exceptions import ParseException -from ..expressions import Array, ASTNode, BinOp, Function, Property, RightOp, expression +from ..expressions import ( + Array, + ASTNode, + BinOp, + Element, + Function, + Property, + RightOp, + expression, +) from ..types import Namespace @@ -148,6 +157,13 @@ def find_names(node: Union[ASTNode, str]): elif isinstance(node, Array): for element in node.elements: yield from find_names(element) + elif isinstance(node, Element): + yield from find_names(node.name) + yield from find_names(node.index) + elif isinstance(node, (int, float)): + return + else: + raise TypeError(f"Unexpected node type: {node!r}") @find_names.register