diff --git a/src/scxml_interpreter/scxml_parser.py b/src/scxml_interpreter/scxml_parser.py index 21a965e..4f001d5 100644 --- a/src/scxml_interpreter/scxml_parser.py +++ b/src/scxml_interpreter/scxml_parser.py @@ -8,26 +8,41 @@ from scxml_interpreter.interfaces import SimpleStateInterface, CompoundStateInterface, \ SCXMLInterface, ParallelStateInterface - def convert_to_concurence_map(cond): # split mapping cond_ = cond.strip() map_list = [] - if(cond_.find(' AND ') == -1): # There is no "and" condition - if(cond_.find(' OR ') == -1): # There is no "or" condition + if(cond_.find(' AND ') == -1): # there are no "and" conditions + if(cond_.find(' OR ') == -1): # there are no "or" conditions list_ = cond_.split('.') map_list.append({list_[0]: list_[1]}) - else: + else: # there are only "or" conditions + + # State1.succeeded OR State2.succeeded + # succeeded: [{State1: succeeded} , {State2: succeeded }] for cond_or in cond_.split(' OR '): list_ = cond_or.split('.') map_list.append({list_[0]: list_[1]}) else: - for cond_and in cond_.split(' AND '): - list_and = cond_and.split('.') - map_list.append({list_and[0]: list_and[1]}) + if(cond_.find(' OR ') == -1): # there are only "and" conditions + + # State1.succeeded AND State2.succeeded + # succeeded: [{State1: succeeded, State2: succeeded }] + cond_and_dict = {} + for cond_and_parcel in cond_.split(' AND '): + list_and = cond_and_parcel.split('.') + cond_and_dict[list_and[0]] = list_and[1] + map_list.append(cond_and_dict) + + else: # there are both "or" and "and" conditions + for cond_or in cond_.split(' OR '): + cond_and_dict = {} + for cond_and_parcel in cond_or.split(' AND '): + list_and = cond_and_parcel.split('.') + cond_and_dict[list_and[0]] = list_and[1] + map_list.append(cond_and_dict) return map_list - class Converter(object): def convert_to_interface(self, root):