diff --git a/scripts/if2spdl/If.py b/scripts/if2spdl/If.py index 2e7cd22..edffbaf 100644 --- a/scripts/if2spdl/If.py +++ b/scripts/if2spdl/If.py @@ -146,10 +146,18 @@ class Label(object): class Rule(object): def __init__(self,left=[],right=[]): - self.left = left - self.right = right + def sanitize(x): + if x == None: + return [] + elif type(x) != list: + return [x] + else: + return x + + self.left = sanitize(left) + self.right = sanitize(right) self.label = None - self.actor = None + self.actors = [] def setLabel(self,label): self.label = label @@ -171,8 +179,11 @@ class Rule(object): def __repr__(self): return str(self) - def getActor(self): - return None + def getActors(self): + return self.actors + + def getFacts(self): + return self.left + self.right class InitialRule(Rule): @@ -185,18 +196,15 @@ class MessageRule(Rule): def __init__(self,left=[],right=[]): Rule.__init__(self,left,right) - self.actor = None - for fact in left + right: + self.actors = [] + for fact in self.getFacts(): actor = fact.getActor() if actor != None: - self.actor = actor + self.actors.append(actor) def __str__(self): return "Message " + Rule.__str__(self) - def getActor(self): - return self.actor - class GoalRule(Rule): def __str__(self): return "Goal " + Rule.__str__(self) diff --git a/scripts/if2spdl/Ifparser.py b/scripts/if2spdl/Ifparser.py index 7134c98..3049a4a 100755 --- a/scripts/if2spdl/Ifparser.py +++ b/scripts/if2spdl/Ifparser.py @@ -293,11 +293,8 @@ def typeSwitch(line): def linesParse(lines): typeSwitch(lines[0]) - parser = ifParser() - result = parser.parseString("".join( lines[1:])) - - return result + return parser.parseString("".join( lines[1:])) # Main code def main(): @@ -306,7 +303,7 @@ def main(): file = open("NSPK_LOWE.if", "r") rulelist = linesParse(file.readlines()) file.close() - print Spdl.generator(rulelist) + print rulelist if __name__ == '__main__': main() diff --git a/scripts/if2spdl/Spdl.py b/scripts/if2spdl/Spdl.py index 025faf9..2ef3708 100644 --- a/scripts/if2spdl/Spdl.py +++ b/scripts/if2spdl/Spdl.py @@ -3,13 +3,16 @@ # Spdl generator # import If +from misc import * def processRole(rulelist, role): print "Role", role for rule in rulelist: - if rule.getActor() == role: - print rule + if role in rule.getActors(): + for fact in rule.getFacts(): + if type(fact) == If.MessageFact: + print fact.spdl() print return "" @@ -18,11 +21,8 @@ def processRole(rulelist, role): def getRoles(rulelist): roles = [] for rule in rulelist: - actor = rule.getActor() - if actor != None: - if actor not in roles: - roles.append(actor) - return roles + roles += rule.getActors() + return uniq(roles) def generator(rulelist): roles = getRoles(rulelist)