Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -261,52 +261,10 @@ return [sOption, sCondition, cAction, sAction] else: print("# Unknown action at line " + sActionId) return None - -def checkRegexes (dAllGraph): - "check validity of regexes" - print(" checking regexes...") - aRegex = set() - for sGraphName, dGraph in dAllGraph.items(): - for nKey, dVal in dGraph.items(): - if "" in dVal: - for sRegex in dVal[""]: - if sRegex not in aRegex: - _checkRegex(sRegex) - aRegex.add(sRegex) - if "" in dVal: - for sRegex in dVal[""]: - if sRegex not in aRegex: - _checkRegex(sRegex) - aRegex.add(sRegex) - aRegex.clear() - -def _checkRegex (sRegex): - #print(sRegex) - if "¬" in sRegex: - sPattern, sNegPattern = sRegex.split("¬") - try: - if not sNegPattern: - print("# Warning! Empty negpattern:", sRegex) - re.compile(sPattern) - re.compile(sNegPattern) - except: - print("# Error. Wrong regex:", sRegex) - traceback.print_exc() - exit() - else: - try: - if not sRegex: - print("# Warning! Empty pattern:", sRegex) - re.compile(sRegex) - except: - print("# Error. Wrong regex:", sRegex) - traceback.print_exc() - exit() - def make (lRule, dDef, sLang, bJavaScript): "compile rules, returns a dictionary of values" # for clarity purpose, don’t create any file here Index: darg.py ================================================================== --- darg.py +++ darg.py @@ -118,10 +118,11 @@ dGraph[sHashId] = oNode.getNodeAsDict() else: print("Error. Double node… same id: ", sHashId) print(str(oNode.getNodeAsDict())) dGraph = self._rewriteKeysOfDARG(dGraph) + self._checkRegexes(dGraph) return dGraph def _rewriteKeysOfDARG (self, dGraph): "keys of DARG are long numbers (hashes): this function replace these hashes with smaller numbers (to reduce storing size)" # create translation dictionary @@ -138,10 +139,49 @@ dVal[sArc] = dKeyTrans[val] else: for sArc, nKey in val.items(): val[sArc] = dKeyTrans[nKey] return dNewGraph + + def _checkRegexes (dGraph): + "check validity of regexes" + aRegex = set() + for nKey, dVal in dGraph.items(): + if "" in dVal: + for sRegex in dVal[""]: + if sRegex not in aRegex: + _checkRegex(sRegex) + aRegex.add(sRegex) + if "" in dVal: + for sRegex in dVal[""]: + if sRegex not in aRegex: + _checkRegex(sRegex) + aRegex.add(sRegex) + aRegex.clear() + + def _checkRegex (sRegex): + #print(sRegex) + if "¬" in sRegex: + sPattern, sNegPattern = sRegex.split("¬") + try: + if not sNegPattern: + print("# Warning! Empty negpattern:", sRegex) + re.compile(sPattern) + re.compile(sNegPattern) + except: + print("# Error. Wrong regex:", sRegex) + traceback.print_exc() + exit() + else: + try: + if not sRegex: + print("# Warning! Empty pattern:", sRegex) + re.compile(sRegex) + except: + print("# Error. Wrong regex:", sRegex) + traceback.print_exc() + exit() class Node: """Node of the rule graph"""