Grammalecte  Check-in [f746aaf996]

Overview
Comment:[build] use rule id instead of line id for callables
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | build | major_change
Files: files | file ages | folders
SHA3-256: f746aaf996f110268010bf8e0e409c5c254e697bced9f8b94c19a9b492f0935d
User & Date: olr on 2017-05-13 07:49:20
Other Links: manifest | tags
Context
2017-05-13
07:52
[fr] renommage de règles check-in: 7591e79cfd user: olr tags: fr, trunk
07:49
[build] use rule id instead of line id for callables check-in: f746aaf996 user: olr tags: build, major_change, trunk
07:35
[fr] processeur de texte: dans ces cas-là check-in: 6838ca1ac2 user: olr tags: fr, trunk
Changes

Modified compile_rules.py from [d1b7f6f58e] to [e2df43feb0].

   180    180           cWordLimitLeft = m.group('borders_and_case')[0]
   181    181           cCaseMode = m.group('borders_and_case')[1]
   182    182           cWordLimitRight = m.group('borders_and_case')[2]
   183    183           sOption = m.group('option')[1:]  if m.group('option')  else False
   184    184           if m.group('ruleid'):
   185    185               sRuleId =  m.group('ruleid')[1:-1]
   186    186               if sRuleId in RULESET:
   187         -                print("# Warning. Several rules have the same id: " + sRuleId)
          187  +                print("# Error. Several rules have the same id: " + sRuleId)
          188  +                exit()
   188    189               RULESET.add(sRuleId)
   189    190           nPriority = dOptPriority.get(sOption, 4)
   190    191           if m.group('priority'):
   191    192               nPriority = int(m.group('priority')[1:])
   192    193           s = s[m.end(0):]
   193    194       else:
   194    195           print("# Warning. No option defined at line: " + sLineId)
................................................................................
   265    266       for x in re.finditer("\(\?:[^)]*\([[\w -]", sRegex):
   266    267           print("# Warning: groups inside non grouping parenthesis in regex at line " + sLineId)
   267    268   
   268    269       #### PARSE ACTIONS
   269    270       lActions = []
   270    271       nAction = 1
   271    272       for sAction in s.split(" <<- "):
   272         -        t = createAction(sLineId + "_" + str(nAction), sAction, nGroup)
          273  +        t = createAction(sRuleId + "_" + str(nAction), sAction, nGroup)
   273    274           nAction += 1
   274    275           if t:
   275    276               lActions.append(t)
   276    277       if not lActions:
   277    278           return None
   278    279   
   279    280       return [sOption, sRegex, bCaseInsensitive, sLineId, sRuleId, nPriority, lActions, tGroups]
................................................................................
   288    289           print("# No action at line " + sIdAction)
   289    290           return None
   290    291   
   291    292       #### CONDITION
   292    293       sCondition = sAction[:m.start()].strip()
   293    294       if sCondition:
   294    295           sCondition = prepareFunction(sCondition)
   295         -        FUNCTIONS.append(("c"+sIdAction, sCondition))
          296  +        FUNCTIONS.append(("c_"+sIdAction, sCondition))
   296    297           for x in re.finditer("[.](?:group|start|end)[(](\d+)[)]", sCondition):
   297    298               if int(x.group(1)) > nGroup:
   298    299                   print("# Error in groups in condition at line " + sIdAction + " ("+str(nGroup)+" groups only)")
   299    300           if ".match" in sCondition:
   300    301               print("# Error. JS compatibility. Don't use .match() in condition, use .search()")
   301         -        sCondition = "c"+sIdAction
          302  +        sCondition = "c_"+sIdAction
   302    303       else:
   303    304           sCondition = None
   304    305   
   305    306       #### iGroup / positioning
   306    307       iGroup = int(m.group(2)) if m.group(2) else 0
   307    308       if iGroup > nGroup:
   308    309           print("# Selected group > group number in regex at line " + sIdAction)
................................................................................
   318    319           sURL = ""
   319    320           mURL = re.search("[|] *(https?://.*)", sMsg)
   320    321           if mURL:
   321    322               sURL = mURL.group(1).strip()
   322    323               sMsg = sMsg[:mURL.start(0)].strip()
   323    324           if sMsg[0:1] == "=":
   324    325               sMsg = prepareFunction(sMsg[1:])
   325         -            FUNCTIONS.append(("m"+sIdAction, sMsg))
          326  +            FUNCTIONS.append(("m_"+sIdAction, sMsg))
   326    327               for x in re.finditer("group[(](\d+)[)]", sMsg):
   327    328                   if int(x.group(1)) > nGroup:
   328    329                       print("# Error in groups in message at line " + sIdAction + " ("+str(nGroup)+" groups only)")
   329         -            sMsg = "=m"+sIdAction
          330  +            sMsg = "=m_"+sIdAction
   330    331           else:
   331    332               for x in re.finditer(r"\\(\d+)", sMsg):
   332    333                   if int(x.group(1)) > nGroup:
   333    334                       print("# Error in groups in message at line " + sIdAction + " ("+str(nGroup)+" groups only)")
   334    335               if re.search("[.]\\w+[(]", sMsg):
   335    336                   print("# Error in message at line " + sIdAction + ":  This message looks like code. Line should begin with =")
   336    337               
................................................................................
   346    347           for x in re.finditer(r"\\(\d+)", sAction):
   347    348               if int(x.group(1)) > nGroup:
   348    349                   print("# Error in groups in replacement at line " + sIdAction + " ("+str(nGroup)+" groups only)")
   349    350           if re.search("[.]\\w+[(]", sAction):
   350    351               print("# Error in action at line " + sIdAction + ":  This action looks like code. Line should begin with =")
   351    352   
   352    353       if cAction == "-":
   353         -        ## error detected
          354  +        ## error detected --> suggestion
   354    355           if not sAction:
   355    356               print("# Error in action at line " + sIdAction + ":  This action is empty.")
   356    357           if sAction[0:1] == "=":
   357         -            FUNCTIONS.append(("s"+sIdAction, sAction[1:]))
   358         -            sAction = "=s"+sIdAction
          358  +            FUNCTIONS.append(("s_"+sIdAction, sAction[1:]))
          359  +            sAction = "=s_"+sIdAction
   359    360           elif sAction.startswith('"') and sAction.endswith('"'):
   360    361               sAction = sAction[1:-1]
   361    362           if not sMsg:
   362    363               print("# Error in action at line " + sIdAction + ":  the message is empty.")
   363    364           return [sCondition, cAction, sAction, iGroup, sMsg, sURL]
   364    365       elif cAction == "~":
   365         -        ## text preprocessor
          366  +        ## text processor
   366    367           if not sAction:
   367    368               print("# Error in action at line " + sIdAction + ":  This action is empty.")
   368    369           if sAction[0:1] == "=":
   369         -            FUNCTIONS.append(("p"+sIdAction, sAction[1:]))
   370         -            sAction = "=p"+sIdAction
          370  +            FUNCTIONS.append(("p_"+sIdAction, sAction[1:]))
          371  +            sAction = "=p_"+sIdAction
   371    372           elif sAction.startswith('"') and sAction.endswith('"'):
   372    373               sAction = sAction[1:-1]
   373    374           return [sCondition, cAction, sAction, iGroup]
   374    375       elif cAction == "=":
   375    376           ## disambiguator
   376    377           if sAction[0:1] == "=":
   377    378               sAction = sAction[1:]
   378    379           if not sAction:
   379    380               print("# Error in action at line " + sIdAction + ":  This action is empty.")
   380         -        FUNCTIONS.append(("d"+sIdAction, sAction))
   381         -        sAction = "d"+sIdAction
          381  +        FUNCTIONS.append(("d_"+sIdAction, sAction))
          382  +        sAction = "d_"+sIdAction
   382    383           return [sCondition, cAction, sAction]
   383    384       elif cAction == ">":
   384    385           ## no action, break loop if condition is False
   385    386           return [sCondition, cAction, ""]
   386    387       else:
   387    388           print("# Unknown action at line " + sIdAction)
   388    389           return None