Skip to content

Commit 33318c5

Browse files
committed
add parent property to AST
1 parent 64aa4d7 commit 33318c5

File tree

1 file changed

+14
-6
lines changed
  • tagstudio/src/core/query_lang

1 file changed

+14
-6
lines changed

tagstudio/src/core/query_lang/ast.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def from_string(text: str) -> "ConstraintType":
2121

2222

2323
class AST:
24+
parent: "AST" = None
25+
2426
def __str__(self):
2527
class_name = self.__class__.__name__
2628
fields = vars(self) # Get all instance variables as a dictionary
@@ -32,19 +34,23 @@ def __repr__(self) -> str:
3234

3335

3436
class ANDList(AST):
35-
elements: list[Union["ORList", "Constraint"]]
37+
terms: list[Union["ORList", "Constraint"]]
3638

37-
def __init__(self, elements: list[Union["ORList", "Constraint"]]) -> None:
39+
def __init__(self, terms: list[Union["ORList", "Constraint"]]) -> None:
3840
super().__init__()
39-
self.elements = elements
41+
for term in terms:
42+
term.parent = self
43+
self.terms = terms
4044

4145

4246
class ORList(AST):
43-
terms: list[ANDList]
47+
elements: list[ANDList]
4448

45-
def __init__(self, terms: list[ANDList]) -> None:
49+
def __init__(self, elements: list[ANDList]) -> None:
4650
super().__init__()
47-
self.terms = terms
51+
for element in elements:
52+
element.parent = self
53+
self.elements = elements
4854

4955

5056
class Constraint(AST):
@@ -54,6 +60,8 @@ class Constraint(AST):
5460

5561
def __init__(self, type: ConstraintType, value: str, properties: list["Property"]) -> None:
5662
super().__init__()
63+
for prop in properties:
64+
prop.parent = self
5765
self.type = type
5866
self.value = value
5967
self.properties = properties

0 commit comments

Comments
 (0)