- 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):
|
class Rule(object):
|
||||||
def __init__(self,left=[],right=[]):
|
def __init__(self,left=[],right=[]):
|
||||||
self.left = left
|
def sanitize(x):
|
||||||
self.right = right
|
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.label = None
|
||||||
self.actor = None
|
self.actors = []
|
||||||
|
|
||||||
def setLabel(self,label):
|
def setLabel(self,label):
|
||||||
self.label = label
|
self.label = label
|
||||||
@ -171,8 +179,11 @@ class Rule(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
def getActor(self):
|
def getActors(self):
|
||||||
return None
|
return self.actors
|
||||||
|
|
||||||
|
def getFacts(self):
|
||||||
|
return self.left + self.right
|
||||||
|
|
||||||
|
|
||||||
class InitialRule(Rule):
|
class InitialRule(Rule):
|
||||||
@ -185,18 +196,15 @@ class MessageRule(Rule):
|
|||||||
|
|
||||||
def __init__(self,left=[],right=[]):
|
def __init__(self,left=[],right=[]):
|
||||||
Rule.__init__(self,left,right)
|
Rule.__init__(self,left,right)
|
||||||
self.actor = None
|
self.actors = []
|
||||||
for fact in left + right:
|
for fact in self.getFacts():
|
||||||
actor = fact.getActor()
|
actor = fact.getActor()
|
||||||
if actor != None:
|
if actor != None:
|
||||||
self.actor = actor
|
self.actors.append(actor)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Message " + Rule.__str__(self)
|
return "Message " + Rule.__str__(self)
|
||||||
|
|
||||||
def getActor(self):
|
|
||||||
return self.actor
|
|
||||||
|
|
||||||
class GoalRule(Rule):
|
class GoalRule(Rule):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Goal " + Rule.__str__(self)
|
return "Goal " + Rule.__str__(self)
|
||||||
|
@ -293,11 +293,8 @@ def typeSwitch(line):
|
|||||||
def linesParse(lines):
|
def linesParse(lines):
|
||||||
|
|
||||||
typeSwitch(lines[0])
|
typeSwitch(lines[0])
|
||||||
|
|
||||||
parser = ifParser()
|
parser = ifParser()
|
||||||
result = parser.parseString("".join( lines[1:]))
|
return parser.parseString("".join( lines[1:]))
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
# Main code
|
# Main code
|
||||||
def main():
|
def main():
|
||||||
@ -306,7 +303,7 @@ def main():
|
|||||||
file = open("NSPK_LOWE.if", "r")
|
file = open("NSPK_LOWE.if", "r")
|
||||||
rulelist = linesParse(file.readlines())
|
rulelist = linesParse(file.readlines())
|
||||||
file.close()
|
file.close()
|
||||||
print Spdl.generator(rulelist)
|
print rulelist
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -3,13 +3,16 @@
|
|||||||
# Spdl generator
|
# Spdl generator
|
||||||
#
|
#
|
||||||
import If
|
import If
|
||||||
|
from misc import *
|
||||||
|
|
||||||
def processRole(rulelist, role):
|
def processRole(rulelist, role):
|
||||||
|
|
||||||
print "Role", role
|
print "Role", role
|
||||||
for rule in rulelist:
|
for rule in rulelist:
|
||||||
if rule.getActor() == role:
|
if role in rule.getActors():
|
||||||
print rule
|
for fact in rule.getFacts():
|
||||||
|
if type(fact) == If.MessageFact:
|
||||||
|
print fact.spdl()
|
||||||
|
|
||||||
print
|
print
|
||||||
return ""
|
return ""
|
||||||
@ -18,11 +21,8 @@ def processRole(rulelist, role):
|
|||||||
def getRoles(rulelist):
|
def getRoles(rulelist):
|
||||||
roles = []
|
roles = []
|
||||||
for rule in rulelist:
|
for rule in rulelist:
|
||||||
actor = rule.getActor()
|
roles += rule.getActors()
|
||||||
if actor != None:
|
return uniq(roles)
|
||||||
if actor not in roles:
|
|
||||||
roles.append(actor)
|
|
||||||
return roles
|
|
||||||
|
|
||||||
def generator(rulelist):
|
def generator(rulelist):
|
||||||
roles = getRoles(rulelist)
|
roles = getRoles(rulelist)
|
||||||
|
Loading…
Reference in New Issue
Block a user