Index: compile_rules.py ================================================================== --- compile_rules.py +++ compile_rules.py @@ -156,11 +156,11 @@ if i == -1: print("# Error: no condition at line " + sLineId) return None sRegex = s[:i].strip() s = s[i+4:] - + # JS groups positioning codes m = re.search("@@\\S+", sRegex) if m: tGroups = jsconv.groupsPositioningCodeToList(sRegex[m.start()+2:]) sRegex = sRegex[:m.start()].strip() @@ -248,25 +248,25 @@ #### CONDITION sCondition = sAction[:m.start()].strip() if sCondition: sCondition = prepareFunction(sCondition) - lFUNCTIONS.append(("c_"+sIdAction, sCondition)) + lFUNCTIONS.append(("_c_"+sIdAction, sCondition)) for x in re.finditer("[.](?:group|start|end)[(](\d+)[)]", sCondition): if int(x.group(1)) > nGroup: print("# Error in groups in condition at line " + sIdAction + " ("+str(nGroup)+" groups only)") if ".match" in sCondition: print("# Error. JS compatibility. Don't use .match() in condition, use .search()") - sCondition = "c_"+sIdAction + sCondition = "_c_"+sIdAction else: sCondition = None #### iGroup / positioning iGroup = int(m.group(2)) if m.group(2) else 0 if iGroup > nGroup: print("# Selected group > group number in regex at line " + sIdAction) - + #### ACTION sAction = sAction[m.end():].strip() cAction = m.group(1) if cAction == "-": ## error @@ -283,22 +283,22 @@ if mURL: sURL = mURL.group(1).strip() sMsg = sMsg[:mURL.start(0)].strip() if sMsg[0:1] == "=": sMsg = prepareFunction(sMsg[1:]) - lFUNCTIONS.append(("m_"+sIdAction, sMsg)) + lFUNCTIONS.append(("_m_"+sIdAction, sMsg)) for x in re.finditer("group[(](\d+)[)]", sMsg): if int(x.group(1)) > nGroup: print("# Error in groups in message at line " + sIdAction + " ("+str(nGroup)+" groups only)") - sMsg = "=m_"+sIdAction + sMsg = "=_m_"+sIdAction else: for x in re.finditer(r"\\(\d+)", sMsg): if int(x.group(1)) > nGroup: print("# Error in groups in message at line " + sIdAction + " ("+str(nGroup)+" groups only)") if re.search("[.]\\w+[(]", sMsg): print("# Error in message at line " + sIdAction + ": This message looks like code. Line should begin with =") - + if sAction[0:1] == "=" or cAction == "=": if "define" in sAction and not re.search(r"define\(\\\d+ *, *\[.*\] *\)", sAction): print("# Error in action at line " + sIdAction + ": second argument for define must be a list of strings") sAction = prepareFunction(sAction) sAction = sAction.replace("m.group(i[4])", "m.group("+str(iGroup)+")") @@ -315,12 +315,12 @@ if cAction == "-": ## error detected --> suggestion if not sAction: print("# Error in action at line " + sIdAction + ": This action is empty.") if sAction[0:1] == "=": - lFUNCTIONS.append(("s_"+sIdAction, sAction[1:])) - sAction = "=s_"+sIdAction + lFUNCTIONS.append(("_s_"+sIdAction, sAction[1:])) + sAction = "=_s_"+sIdAction elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] if not sMsg: print("# Error in action at line " + sIdAction + ": the message is empty.") return [sCondition, cAction, sAction, iGroup, sMsg, sURL] @@ -327,23 +327,23 @@ elif cAction == "~": ## text processor if not sAction: print("# Error in action at line " + sIdAction + ": This action is empty.") if sAction[0:1] == "=": - lFUNCTIONS.append(("p_"+sIdAction, sAction[1:])) - sAction = "=p_"+sIdAction + lFUNCTIONS.append(("_p_"+sIdAction, sAction[1:])) + sAction = "=_p_"+sIdAction elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] return [sCondition, cAction, sAction, iGroup] elif cAction == "=": ## disambiguator if sAction[0:1] == "=": sAction = sAction[1:] if not sAction: print("# Error in action at line " + sIdAction + ": This action is empty.") - lFUNCTIONS.append(("d_"+sIdAction, sAction)) - sAction = "d_"+sIdAction + lFUNCTIONS.append(("_d_"+sIdAction, sAction)) + sAction = "_d_"+sIdAction return [sCondition, cAction, sAction] elif cAction == ">": ## no action, break loop if condition is False return [sCondition, cAction, ""] else: @@ -547,20 +547,19 @@ # creating file with all functions callable by rules print(" creating callables...") sPyCallables = "# generated code, do not edit\n" sJSCallables = "// generated code, do not edit\nconst oEvalFunc = {\n" for sFuncName, sReturn in lFUNCTIONS: - cType = sFuncName[0:1] - if cType == "c": # condition - sParams = "s, sx, m, dTokenPos, sCountry, bCondMemo" - elif cType == "m": # message - sParams = "s, m" - elif cType == "s": # suggestion - sParams = "s, m" - elif cType == "p": # preprocessor - sParams = "s, m" - elif cType == "d": # disambiguator + if sFuncName.startswith("_c_"): # condition + sParams = "s, sx, m, dTokenPos, sCountry, bCondMemo" + elif sFuncName.startswith("_m_"): # message + sParams = "s, m" + elif sFuncName.startswith("_s_"): # suggestion + sParams = "s, m" + elif sFuncName.startswith("_p_"): # preprocessor + sParams = "s, m" + elif sFuncName.startswith("_d_"): # disambiguator sParams = "s, m, dTokenPos" else: print("# Unknown function type in [" + sFuncName + "]") continue sPyCallables += "def {} ({}):\n".format(sFuncName, sParams) Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -140,11 +140,11 @@ def createAction (sActionId, sAction, nPriority, nToken, dPos): # Option sOption = False - m = re.match("/(\\w+)/", sAction) + m = re.match("/(\\w+)/", sAction) if m: sOption = m.group(1) sAction = sAction[m.end():].strip() # valid action? m = re.search("(?P[-~=/])(?P\\d+|)(?P:\\d+|)>> ", sAction) @@ -154,13 +154,13 @@ return None # Condition sCondition = sAction[:m.start()].strip() if sCondition: sCondition = prepareFunction(sCondition) - sCondition = changeReferenceToken(sCondition, dPos) - dFUNCTIONS["g_c_"+sActionId] = sCondition - sCondition = "g_c_"+sActionId + sCondition = changeReferenceToken(sCondition, dPos) + dFUNCTIONS["_g_c_"+sActionId] = sCondition + sCondition = "_g_c_"+sActionId else: sCondition = "" # Action cAction = m.group("action") sAction = sAction[m.end():].strip() @@ -198,11 +198,11 @@ sMsg = prepareFunction(sMsg[1:], True) dFUNCTIONS["g_m_"+sActionId] = sMsg sMsg = "=g_m_"+sActionId else: checkIfThereIsCode(sMsg, sActionId) - + # checking consistancy checkTokenNumbers(sAction, sActionId, nToken) if cAction == ">": ## no action, break loop if condition is False @@ -216,22 +216,22 @@ if cAction == "-": ## error detected --> suggestion if sAction[0:1] == "=": sAction = prepareFunction(sAction, True) - dFUNCTIONS["g_s_"+sActionId] = sAction[1:] - sAction = "=g_s_"+sActionId + dFUNCTIONS["_g_s_"+sActionId] = sAction[1:] + sAction = "=_g_s_"+sActionId elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] if not sMsg: print("# Error in action at line " + sActionId + ": The message is empty.") return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction, nPriority, sMsg, sURL] elif cAction == "~": ## text processor if sAction[0:1] == "=": - dFUNCTIONS["g_p_"+sActionId] = sAction[1:] - sAction = "=g_p_"+sActionId + dFUNCTIONS["_g_p_"+sActionId] = sAction[1:] + sAction = "=_g_p_"+sActionId elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction] elif cAction == "/": ## tags @@ -241,12 +241,12 @@ if sAction[0:1] == "=": sAction = sAction[1:] if "define" in sAction and not re.search(r"define\(\\\d+ *, *\[.*\] *\)", sAction): print("# Error in action at line " + sActionId + ": second argument for must be a list of strings") sAction = prepareFunction(sAction) - dFUNCTIONS["g_d_"+sActionId] = sAction - sAction = "g_d_"+sActionId + dFUNCTIONS["_g_d_"+sActionId] = sAction + sAction = "_g_d_"+sActionId return [sOption, sCondition, cAction, sAction] else: print("# Unknown action at line " + sActionId) return None @@ -338,19 +338,19 @@ # creating file with all functions callable by rules print(" creating callables...") sPyCallables = "# generated code, do not edit\n" #sJSCallables = "// generated code, do not edit\nconst oEvalFunc = {\n" for sFuncName, sReturn in dFUNCTIONS.items(): - if sFuncName.startswith("g_c_"): # condition + if sFuncName.startswith("_g_c_"): # condition sParams = "lToken, nTokenOffset, nLastToken, sCountry, bCondMemo, dTags, sSentence, sSentence0" elif sFuncName.startswith("g_m_"): # message sParams = "lToken, nTokenOffset" - elif sFuncName.startswith("g_s_"): # suggestion + elif sFuncName.startswith("_g_s_"): # suggestion sParams = "lToken, nTokenOffset" - elif sFuncName.startswith("g_p_"): # preprocessor + elif sFuncName.startswith("_g_p_"): # preprocessor sParams = "lToken" - elif sFuncName.startswith("g_d_"): # disambiguator + elif sFuncName.startswith("_g_d_"): # disambiguator sParams = "lToken, nTokenOffset" else: print("# Unknown function type in [" + sFuncName + "]") continue sPyCallables += "def {} ({}):\n".format(sFuncName, sParams)