Index: compile_rules.py ================================================================== --- compile_rules.py +++ compile_rules.py @@ -1,11 +1,15 @@ +""" +Grammalecte: compile rules +""" import re import traceback import json import compile_rules_js_convert as jsconv +import compile_rules_graph as crg dDEF = {} lFUNCTIONS = [] @@ -17,10 +21,11 @@ sWORDLIMITLEFT = r"(?" try: return re.compile(sRegex).groups except: traceback.print_exc() print(sRegex) @@ -110,20 +116,28 @@ def createRule (s, nIdLine, sLang, bParagraph, dOptPriority): "returns rule as list [option name, regex, bCaseInsensitive, identifier, list of actions]" global dJSREGEXES global nRULEWITHOUTNAME - #### OPTIONS sLineId = str(nIdLine) + ("p" if bParagraph else "s") sRuleId = sLineId + + #### GRAPH CALL + if s.startswith("@@@@"): + if bParagraph: + print("Error. Graph call can be made only after the first pass (sentence by sentence)") + exit() + return ["@@@@", s[4:], sLineId] + + #### OPTIONS sOption = False # False or [a-z0-9]+ name nPriority = 4 # Default is 4, value must be between 0 and 9 tGroups = None # code for groups positioning (only useful for JavaScript) cCaseMode = 'i' # i: case insensitive, s: case sensitive, u: uppercasing allowed cWordLimitLeft = '[' # [: word limit, <: no specific limit cWordLimitRight = ']' # ]: word limit, >: no specific limit - m = re.match("^__(?P[[<]\\w[]>])(?P