@@ -13,7 +13,7 @@ def __init__(self, tag, attribute, nodes, bind=None, optional=False):
1313
1414 def to_string (self , indent = 0 ):
1515 # return "%s%s%s[%s](%s%s)%s" % ("\n" if indent else "", " "*indent, self.tag, self.attribute, "".join(n.to_string(indent+2) for n in self.nodes), ("\n" + " "*indent) if len(self.nodes) else "", (" -> %s" % self.bind) if self.bind else "")
16- return "<Rule %s %s>" % (self .tag , self .attribute )
16+ return "<%s %s%s >" % (self .tag , f" { self . bind } =" if self . bind else "" , self .attribute )
1717
1818 def __repr__ (self ):
1919 return self .to_string ()
@@ -23,8 +23,8 @@ class template(object):
2323 Representation of an mvdXML template
2424 """
2525
26- def __init__ (self , concept , root , constraints = None , rules = None ):
27- self .concept , self .root , self .constraints = concept , root , (constraints or [])
26+ def __init__ (self , concept , root , constraints = None , rules = None , parent = None ):
27+ self .concept , self .root , self .constraints , self . parent = concept , root , (constraints or []), parent
2828 self .rules = rules or []
2929 self .entity = str (root .attributes ['applicableEntity' ].value )
3030 try :
@@ -58,7 +58,7 @@ def visit(n, p=root, ps=[root]):
5858 visit (r )
5959
6060 def parse_rule (self , root , visited = None ):
61- def visit (node , prefix = "" , visited = None ):
61+ def visit (node , prefix = "" , visited = None , parent = None ):
6262 r = None
6363 n = node
6464 nm = None
@@ -112,7 +112,10 @@ def _(n):
112112 for x in visit (subnode , p , visited = visited ): yield x
113113
114114 if r :
115- yield rule (node .localName , r , list (_ (n )), (p + nm ) if nm else nm , optional = optional )
115+ R = rule (node .localName , r , list (_ (n )), (p + nm ) if nm else nm , optional = optional )
116+ for rr in R .nodes :
117+ rr .parent = R
118+ yield R
116119 else :
117120 for subnode in n .childNodes :
118121 if not isinstance (subnode , Element ): continue
0 commit comments