- Skeleton output of messages is done.
This commit is contained in:
parent
951794a7ac
commit
9e2a144e5f
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user