Restrictions now always a list, removes/simplifies a bit of code

This commit is contained in:
Ozbolt Menegatti 2019-06-08 11:23:50 +02:00
parent d83d619dc0
commit 2167e4b6fe

26
wani.py
View File

@ -539,7 +539,7 @@ class Component:
self.status = status self.status = status
self.name = name self.name = name
self.idx = idx self.idx = idx
self.restriction = None self.restrictions = []
self.next_element = [] self.next_element = []
self.representation = [] self.representation = []
self.selection = {} self.selection = {}
@ -551,13 +551,13 @@ class Component:
def set_restriction(self, restrictions_tag): def set_restriction(self, restrictions_tag):
if restrictions_tag is None: if restrictions_tag is None:
self.restriction = Restriction(None) self.restrictions = [Restriction(None)]
elif restrictions_tag.tag == "restriction": elif restrictions_tag.tag == "restriction":
self.restriction = Restriction(restrictions_tag) self.restrictions = [Restriction(restrictions_tag)]
elif restrictions_tag.tag == "restriction_or": 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: else:
raise RuntimeError("Unreachable") raise RuntimeError("Unreachable")
@ -626,22 +626,10 @@ class Component:
return to_ret return to_ret
def _match_self(self, word): def _match_self(self, word):
matched = None
# matching # matching
if type(self.restriction) is list: for restr in self.restrictions:
for restr in self.restriction: if restr.match(word): # match either
matched = restr.match(word) return {self.idx: 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}
def _match_next(self, word): def _match_next(self, word):
# matches for every component in links from this component # matches for every component in links from this component