Skip to content

Commit e8d4785

Browse files
committed
reintroduce naming equations feature (lost in merge)
1 parent 90fd0c7 commit e8d4785

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/pyirk/_builtin/scopes.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def new_equation(self, lhs: Item, rhs: Item, force_key: str = None) -> Item:
458458

459459
# TODO: this makes self.new_equation obsolete, doesn't it?
460460
def new_math_relation(
461-
self, lhs: Item, rsgn: str, rhs: Item, add_relations: dict = {}, force_key: str = None
461+
self, lhs: Item, rsgn: str, rhs: Item, add_relations: dict = {}, force_key: str = None, name: str = None
462462
) -> Item:
463463
"""
464464
convenience method to create a math_relation-related StatementObject (aka "Statement")
@@ -476,6 +476,16 @@ def new_math_relation(
476476
rel = _be.new_mathematical_relation(
477477
lhs, rsgn, rhs, scope=self.scope, add_relations=add_relations, force_key=force_key
478478
)
479+
if name:
480+
# add name of equation to available names in context for explicit referencing
481+
# TODO unsure if this is the cleanest way
482+
msg = f"The name '{name}' is already occupied in the scope `{self.scope}` of item `{self.item}`."
483+
assert name not in self.item.__dict__ and name not in self.__dict__, msg
484+
self.item.__dict__[name] = rel
485+
486+
# keep track of added context vars
487+
self.namespace[name] = rel
488+
479489
return rel
480490

481491
def AND(self) -> "ConditionSubScopeCM":

0 commit comments

Comments
 (0)