From 2167e4b6fe0d02f1881fa5683a15a6cff038f136 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Sat, 8 Jun 2019 11:23:50 +0200 Subject: [PATCH] Restrictions now always a list, removes/simplifies a bit of code --- wani.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/wani.py b/wani.py index 822e3f2..9cfedd6 100644 --- a/wani.py +++ b/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