Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -14,20 +14,33 @@ dFUNCTIONS = {} dFUNCNAME = {} def createFunction (sType, sActionId, sCode, bStartWithEqual=False): - "create a function (stored in dFUNCTIONS) and return function name" + "create a function (stored in ) and return function name" sCode = prepareFunction(sCode) if sType not in dFUNCNAME: dFUNCNAME[sType] = {} if sCode not in dFUNCNAME[sType]: dFUNCNAME[sType][sCode] = len(dFUNCNAME[sType])+1 sFuncName = "_g_" + sType + "_" + str(dFUNCNAME[sType][sCode]) dFUNCTIONS[sFuncName] = sCode return sFuncName if not bStartWithEqual else "="+sFuncName + +def storeAction (sActionId, aAction): + "store in avoiding duplicates" + nVar = 0 + while True: + sActionName = sActionId + str(nVar) + if sActionName not in dACTIONS: + dACTIONS[sActionName] = aAction + return sActionName + elif aAction == dACTIONS[sActionName]: + return sActionName + nVar += 1 + def prepareFunction (sCode): "convert simple rule syntax to a string of Python code" if sCode[0:1] == "=": sCode = sCode[1:] @@ -135,16 +148,16 @@ # Parse actions for iAction, sAction in enumerate(sActions.split(" <<- ")): sAction = sAction.strip() if sAction: - sActionId = sRuleName + "__b" + str(iActionBlock) + "_l" + str(iLine) + "_a" + str(iAction) + "_" + str(len(lToken)) + sActionId = sRuleName + "__b" + str(iActionBlock) + "_a" + str(iAction) aAction = createAction(sActionId, sAction, nPriority, dOptPriority, len(lToken), dPos) if aAction: - dACTIONS[sActionId] = aAction + sActionName = storeAction(sActionId, aAction) lResult = list(lToken) - lResult.extend(["##"+str(iLine), sActionId]) + lResult.extend(["##"+str(iLine), sActionName]) #if iLine == 13341: # print(" ".join(lToken)) # print(sActionId, aAction) yield lResult else: