Restrictions now always a list, removes/simplifies a bit of code
This commit is contained in:
parent
d83d619dc0
commit
2167e4b6fe
26
wani.py
26
wani.py
|
@ -539,7 +539,7 @@ class Component:
|
|||
self.status = status
|
||||
self.name = name
|
||||
self.idx = idx
|
||||
self.restriction = None
|
||||
self.restrictions = []
|
||||
self.next_element = []
|
||||
self.representation = []
|
||||
self.selection = {}
|
||||
|
@ -551,13 +551,13 @@ class Component:
|
|||
|
||||
def set_restriction(self, restrictions_tag):
|
||||
if restrictions_tag is None:
|
||||
self.restriction = Restriction(None)
|
||||
self.restrictions = [Restriction(None)]
|
||||
|
||||
elif restrictions_tag.tag == "restriction":
|
||||
self.restriction = Restriction(restrictions_tag)
|
||||
self.restrictions = [Restriction(restrictions_tag)]
|
||||
|
||||
elif restrictions_tag.tag == "restriction_or":
|
||||
self.restriction = [Restriction(el) for el in restrictions_tag]
|
||||
self.restrictions = [Restriction(el) for el in restrictions_tag]
|
||||
|
||||
else:
|
||||
raise RuntimeError("Unreachable")
|
||||
|
@ -626,22 +626,10 @@ class Component:
|
|||
return to_ret
|
||||
|
||||
def _match_self(self, word):
|
||||
matched = None
|
||||
|
||||
# matching
|
||||
if type(self.restriction) is list:
|
||||
for restr in self.restriction:
|
||||
matched = restr.match(word)
|
||||
if matched: # match either
|
||||
break
|
||||
else:
|
||||
matched = self.restriction.match(word)
|
||||
|
||||
# recurse to next
|
||||
if not matched:
|
||||
return None
|
||||
else:
|
||||
return {self.idx: word}
|
||||
for restr in self.restrictions:
|
||||
if restr.match(word): # match either
|
||||
return {self.idx: word}
|
||||
|
||||
def _match_next(self, word):
|
||||
# matches for every component in links from this component
|
||||
|
|
Loading…
Reference in New Issue
Block a user