Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -261,10 +261,46 @@ return [sOption, sCondition, cAction, sAction] else: print("# Unknown action at line " + sActionId) return None + +def checkRegexes (dAllGraph): + "check validity of regexes" + print(" checking regexes...") + for sGraphName, dGraph in dAllGraph.items(): + for nKey, dVal in dGraph.items(): + if "" in dVal: + for sRegex in dVal[""]: + _checkRegex(sRegex) + if "" in dVal: + for sRegex in dVal[""]: + _checkRegex(sRegex) + +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 @@ -378,12 +414,14 @@ print("\nActions:") for sActionName, aAction in dACTIONS.items(): print(sActionName, aAction) print("\nFunctions:") print(sPyCallables) + + checkRegexes(dAllGraph) # Result return { "graph_callables": sPyCallables, "rules_graphs": dAllGraph, "rules_actions": dACTIONS }