Commit cb2dc33a authored by jeancoquet's avatar jeancoquet
Browse files

Fixing bug of event parsing

parent 5e4d960e
......@@ -37,7 +37,7 @@ from logging import DEBUG
# Library imports
from cadbiom.models.guard_transitions.translators.chart_xml \
import MakeModelFromXmlFile
from cadbiom.models.biosignal.translators.gt_visitors import compile_cond
from cadbiom.models.biosignal.translators.gt_visitors import compile_cond, compile_event
from cadbiom.models.guard_transitions.analyser.ana_visitors import TableVisitor
from cadbiom.models.biosignal.sig_expr import *
from cadbiom.models.guard_transitions.analyser.ana_visitors import SigExpIdCollectVisitor
......@@ -176,8 +176,12 @@ def get_transitions(file, all_places=False):
# Get the names of clocks
# Some event have many clocks (like _h_2755) for the same
# ori/ext entities, so we have to extract them
events = re.findall('(_h_[0-9_\.]+)', trans.event)
for event in events:
if re.match('_h_[0-9_\.]+', trans.event):
eventToCondStr = {trans.event: trans.condition}
else:
eventToCondStr = parse_event(trans.event)
for event in eventToCondStr:
# LOGGER.debug("NEW trans", event)
# Handle multiple transitions for 1 event
......@@ -186,7 +190,7 @@ def get_transitions(file, all_places=False):
trans.ori.name, trans.ext.name,
{
'label': event, #+ '[' + trans.condition + ']',
'condition': trans.condition,
'condition': eventToCondStr[event],
}
)
)
......@@ -394,6 +398,28 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
# print(dir(ret))
def treeToExprDefaultsList(tree):
if isinstance(tree, SigDefaultExpr) :
return treeToExprDefaultsList(tree.left_h)+treeToExprDefaultsList(tree.right_h)
else: return [tree]
def parse_event(event):
err = Reporter()
tvi = TableVisitor(err)
symb_tab = tvi.tab_symb
# Get tree object from event string
event_sexpr = compile_event(event, symb_tab, True, err)[0]
eventToCondStr = {}
for expr in treeToExprDefaultsList(event_sexpr):
if isinstance(expr, SigWhenExpr):
eventToCondStr[str(expr.left_h)] = str(expr.right_h)
return eventToCondStr
def build_graph(solution, steps, transitions):
"""Build a graph for the given solution.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment