Refs #34362 -- Added get_child_with_renamed_prefix() hook.

This commit is contained in:
Francesco Panico 2023-07-21 09:29:27 +02:00 committed by Mariusz Felisiak
parent addbc90049
commit afc880571d
1 changed files with 9 additions and 6 deletions

View File

@ -73,14 +73,17 @@ def get_children_from_q(q):
yield child yield child
def get_child_with_renamed_prefix(prefix, replacement, child):
if isinstance(child, Node):
return rename_prefix_from_q(prefix, replacement, child)
lhs, rhs = child
lhs = lhs.replace(prefix, replacement, 1)
return lhs, rhs
def rename_prefix_from_q(prefix, replacement, q): def rename_prefix_from_q(prefix, replacement, q):
return Q.create( return Q.create(
[ [get_child_with_renamed_prefix(prefix, replacement, c) for c in q.children],
rename_prefix_from_q(prefix, replacement, c)
if isinstance(c, Node)
else (c[0].replace(prefix, replacement, 1), c[1])
for c in q.children
],
q.connector, q.connector,
q.negated, q.negated,
) )