Grammalecte  Check-in [7542272427]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[build] add tests to text processor actions to prevent weird bugs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | build
Files: files | file ages | folders
SHA3-256:7542272427235bcfbbbf62f6ff1ae20763d148b8551dc916b42d3896dabf3875
User & Date: olr 2019-08-20 16:31:28
Context
2019-08-21
07:04
[server] code clarity, +version 1.3.1 check-in: 137cf12feb user: olr tags: server, trunk, v1.3.1
2019-08-20
16:31
[build] add tests to text processor actions to prevent weird bugs check-in: 7542272427 user: olr tags: build, trunk
13:00
[cli] show Python version check-in: 57bb3560a3 user: olr tags: cli, trunk
Changes

Changes to compile_rules_graph.py.

   234    234           sAction = sAction[m.end():].strip()
   235    235       if nPriority == -1:
   236    236           nPriority = dOptPriority.get(sOption, 4)
   237    237   
   238    238       # valid action?
   239    239       m = re.search(r"(?P<action>[-=~/!>])(?P<start>-?\d+\.?|)(?P<end>:\.?-?\d+|)(?P<casing>:|)>>", sAction)
   240    240       if not m:
   241         -        print(" # Error. No action found at: ", sActionId)
          241  +        print("\n# Error. No action found at: ", sActionId)
   242    242           return None
   243    243   
   244    244       # Condition
   245    245       sCondition = sAction[:m.start()].strip()
   246    246       if sCondition:
   247    247           sCondition = changeReferenceToken(sCondition, dPos)
   248    248           sCondition = createFunction("cond", sCondition)
................................................................................
   260    260       cStartLimit = "<"
   261    261       cEndLimit = ">"
   262    262       if not m.group("start"):
   263    263           iStartAction = 1
   264    264           iEndAction = 0
   265    265       else:
   266    266           if cAction != "-" and (m.group("start").endswith(".") or m.group("end").startswith(":.")):
   267         -            print(" # Error. Wrong selection on tokens.", sActionId)
          267  +            print("\n# Error. Wrong selection on tokens.", sActionId)
   268    268               return None
   269    269           if m.group("start").endswith("."):
   270    270               cStartLimit = ">"
   271    271           iStartAction = int(m.group("start").rstrip("."))
   272    272           if not m.group("end"):
   273    273               iEndAction = iStartAction
   274    274           else:
................................................................................
   286    286   
   287    287       if cAction == "-":
   288    288           ## error
   289    289           iMsg = sAction.find(" # ")
   290    290           if iMsg == -1:
   291    291               sMsg = "# Error. Error message not found."
   292    292               sURL = ""
   293         -            print(sMsg + " Action id: " + sActionId)
          293  +            print("\n" + sMsg + " Action id: " + sActionId)
   294    294           else:
   295    295               sMsg = sAction[iMsg+3:].strip()
   296    296               sAction = sAction[:iMsg].strip()
   297    297               sURL = ""
   298    298               mURL = re.search("[|] *(https?://.*)", sMsg)
   299    299               if mURL:
   300    300                   sURL = mURL.group(1).strip()
................................................................................
   309    309       checkTokenNumbers(sAction, sActionId, nToken)
   310    310   
   311    311       if cAction == ">":
   312    312           ## no action, break loop if condition is False
   313    313           return [sOption, sCondition, cAction, ""]
   314    314   
   315    315       if not sAction and cAction != "!":
   316         -        print("# Error in action at line " + sActionId + ":  This action is empty.")
          316  +        print("\n# Error in action at line <" + sActionId + ">:  This action is empty.")
   317    317   
   318    318       if sAction[0:1] != "=" and cAction != "=":
   319    319           checkIfThereIsCode(sAction, sActionId)
   320    320   
   321    321       if cAction == "-":
   322    322           ## error detected --> suggestion
   323    323           if sAction[0:1] == "=":
   324    324               sAction = createFunction("sugg", sAction, True)
   325    325           elif sAction.startswith('"') and sAction.endswith('"'):
   326    326               sAction = sAction[1:-1]
   327    327           if not sMsg:
   328         -            print("# Error in action at line " + sActionId + ":  The message is empty.")
          328  +            print("\n# Error in action at line <" + sActionId + ">:  The message is empty.")
   329    329           return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction, cStartLimit, cEndLimit, bCaseSensitivity, nPriority, sMsg, sURL]
   330    330       if cAction == "~":
   331    331           ## text processor
   332    332           if sAction[0:1] == "=":
   333    333               sAction = createFunction("tp", sAction, True)
   334    334           elif sAction.startswith('"') and sAction.endswith('"'):
   335    335               sAction = sAction[1:-1]
          336  +        elif sAction not in "␣*_":
          337  +            nToken = sAction.count("|") + 1
          338  +            if iStartAction > 0 and iEndAction > 0:
          339  +                if (iEndAction - iStartAction + 1) != nToken:
          340  +                    print("\n# Error in action at line <" + sActionId + ">: numbers of modified tokens modified.")
          341  +            elif iStartAction < 0 or iEndAction < 0 and iStartAction != iEndAction:
          342  +                print("\n# Warning in action at line <" + sActionName + ">: rewriting with possible token position modified.")
   336    343           return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction, bCaseSensitivity]
   337    344       if cAction in "!/":
   338    345           ## tags
   339    346           return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction]
   340    347       if cAction == "=":
   341    348           ## disambiguator
   342    349           if "define(" in sAction and not re.search(r"define\(\\-?\d+ *, *\[.*\] *\)", sAction):
   343         -            print("# Error in action at line " + sActionId + ": second argument for <define> must be a list of strings")
          350  +            print("\n# Error in action at line <" + sActionId + ">: second argument for <define> must be a list of strings")
   344    351           sAction = createFunction("da", sAction)
   345    352           return [sOption, sCondition, cAction, sAction]
   346         -    print(" # Unknown action.", sActionId)
          353  +    print("\n# Unknown action.", sActionId)
   347    354       return None
   348    355   
   349    356   
   350    357   def make (lRule, sLang, dDef, dDecl, dOptPriority):
   351    358       "compile rules, returns a dictionary of values"
   352    359       # for clarity purpose, don’t create any file here
   353    360