Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -72,11 +72,11 @@ aRule.append(sToken) for aRule in lTokenLines: yield aRule -def createRule (iLine, sRuleName, sTokenLine, sActions, nPriority): +def createRule (iLine, sRuleName, sTokenLine, iActionBlock, sActions, nPriority): # print(iLine, "//", sRuleName, "//", sTokenLine, "//", sActions, "//", nPriority) for lToken in genTokenLines(sTokenLine): # Calculate positions dPos = {} # key: iGroup, value: iToken iGroup = 0 @@ -85,14 +85,14 @@ lToken[i] = sToken[1:-1] iGroup += 1 dPos[iGroup] = i + 1 # we add 1, for we count tokens from 1 to n (not from 0) # Parse actions - for nAction, sAction in enumerate(sActions.split(" <<- ")): + for iAction, sAction in enumerate(sActions.split(" <<- "), 1): sAction = sAction.strip() if sAction: - sActionId = sRuleName + "_a" + str(nAction) + sActionId = sRuleName + "__b" + str(iActionBlock) + "_a" + str(iAction) aAction = createAction(sActionId, sAction, nPriority, len(lToken), dPos) if aAction: dACTIONS[sActionId] = aAction lResult = list(lToken) lResult.extend(["##"+str(iLine), sActionId]) @@ -234,10 +234,11 @@ lTokenLine = [] sActions = "" nPriority = 4 dAllGraph = {} sGraphName = "" + iActionBlock = 0 for i, sLine in lRule: sLine = sLine.rstrip() if "\t" in sLine: # tabulation not allowed @@ -258,10 +259,11 @@ elif sLine.startswith("__") and sLine.endswith("__"): # new rule group m = re.match("__(\\w+)(!\\d|)__", sLine) if m: sRuleName = m.group(1) + iActionBlock = 1 nPriority = int(m.group(2)[1:]) if m.group(2) else 4 else: print("Error at rule group: ", sLine, " -- line:", i) break elif re.match("[  ]*$", sLine): @@ -273,13 +275,14 @@ exit() if not sGraphName: print("Error. All rules must belong to a named graph. Line: ", i) exit() for j, sTokenLine in lTokenLine: - dAllGraph[sGraphName].append((j, sRuleName, sTokenLine, sActions, nPriority)) + dAllGraph[sGraphName].append((j, sRuleName, sTokenLine, iActionBlock, sActions, nPriority)) lTokenLine.clear() sActions = "" + iActionBlock += 1 elif re.search(" +<<- ", sLine): # actions sActions += " " + sLine.strip() elif sLine.startswith((" ")): # tokens @@ -290,12 +293,12 @@ # processing rules print(" preparing rules...") for sGraphName, lRuleLine in dAllGraph.items(): lPreparedRule = [] - for i, sRuleGroup, sTokenLine, sActions, nPriority in lRuleLine: - for lRule in createRule(i, sRuleGroup, sTokenLine, sActions, nPriority): + for i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority in lRuleLine: + for lRule in createRule(i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority): lPreparedRule.append(lRule) # Show rules for e in lPreparedRule: print(e) # Graph creation