Grammalecte  Check-in [ba6939effa]

Overview
Comment:[core][py] gc engine: better debugging information
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | rg
Files: files | file ages | folders
SHA3-256: ba6939effa5af5b121661602d37b59660ec604982ea4f150241282b1b9ee5e95
User & Date: olr on 2018-09-12 09:44:15
Other Links: branch diff | manifest | tags
Context
2018-09-12
09:46
[core][build][js] fix several issues, better debugging information, create RegExp at runtime instead of preprocessing them at build check-in: 50bef581ca user: olr tags: build, core, rg
09:44
[core][py] gc engine: better debugging information check-in: ba6939effa user: olr tags: core, rg
08:05
[build] update code conversion to JS check-in: 0c1e2728dd user: olr tags: build, rg
Changes

Modified gc_core/py/lang_core/gc_engine.py from [ce1482f7e7] to [a6af5aa7ed].

   506    506           "execute actions found in the DARG"
   507    507           bChange = False
   508    508           for sLineId, nextNodeKey in dNode.items():
   509    509               bCondMemo = None
   510    510               for sRuleId in dGraph[nextNodeKey]:
   511    511                   try:
   512    512                       if bDebug:
   513         -                        echo("   >TRY: " + sRuleId)
          513  +                        echo("   >TRY: " + sRuleId + " " + sLineId)
   514    514                       sOption, sFuncCond, cActionType, sWhat, *eAct = _rules_graph.dRule[sRuleId]
   515    515                       # Suggestion    [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL ]
   516    516                       # TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ]
   517    517                       # Disambiguator [ option, condition, "=", replacement/suggestion/action ]
   518    518                       # Tag           [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ]
   519    519                       # Immunity      [ option, condition, "%", "",                            iTokenStart, iTokenEnd ]
   520    520                       # Test          [ option, condition, ">", "" ]
................................................................................
   529    529                                       nTokenErrorEnd = nTokenOffset + iTokenEnd  if iTokenEnd > 0  else nLastToken + iTokenEnd
   530    530                                       nErrorStart = self.nOffsetWithinParagraph + (self.lToken[nTokenErrorStart]["nStart"] if cStartLimit == "<"  else self.lToken[nTokenErrorStart]["nEnd"])
   531    531                                       nErrorEnd = self.nOffsetWithinParagraph + (self.lToken[nTokenErrorEnd]["nEnd"] if cEndLimit == ">"  else self.lToken[nTokenErrorEnd]["nStart"])
   532    532                                       if nErrorStart not in self.dError or nPriority > self.dErrorPriority.get(nErrorStart, -1):
   533    533                                           self.dError[nErrorStart] = self._createErrorFromTokens(sWhat, nTokenOffset, nLastToken, nTokenErrorStart, nErrorStart, nErrorEnd, sLineId, sRuleId, bCaseSvty, sMessage, sURL, bShowRuleId, sOption, bContext)
   534    534                                           self.dErrorPriority[nErrorStart] = nPriority
   535    535                                           if bDebug:
   536         -                                            echo("    NEW_ERROR:  {}  {}:  {}".format(sRuleId, sLineId, self.dError[nErrorStart]))
          536  +                                            echo("    NEW_ERROR: {}".format(self.dError[nErrorStart]))
   537    537                               elif cActionType == "~":
   538    538                                   # text processor
   539    539                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   540    540                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   541    541                                   self._tagAndPrepareTokenForRewriting(sWhat, nTokenStart, nTokenEnd, nTokenOffset, nLastToken, eAct[2], bDebug)
   542    542                                   bChange = True
   543    543                                   if bDebug:
   544         -                                    echo("    TEXT_PROCESSOR:  " + sRuleId + " " + sLineId)
   545         -                                    echo("       " + self.lToken[nTokenStart]["sValue"] + " : " + self.lToken[nTokenEnd]["sValue"] + "  > ", sWhat)
          544  +                                    echo("    TEXT_PROCESSOR: [{}:{}]  > {}".format(self.lToken[nTokenStart]["sValue"], self.lToken[nTokenEnd]["sValue"], sWhat))
   546    545                               elif cActionType == "=":
   547    546                                   # disambiguation
   548    547                                   globals()[sWhat](self.lToken, nTokenOffset, nLastToken)
   549    548                                   if bDebug:
   550         -                                    echo("    DISAMBIGUATOR:  {} {} ({})  {}:{}".format(sRuleId, sLineId, sWhat, self.lToken[nTokenOffset+1]["sValue"], self.lToken[nLastToken]["sValue"]))
          549  +                                    echo("    DISAMBIGUATOR: ({})  [{}:{}]".format(sWhat, self.lToken[nTokenOffset+1]["sValue"], self.lToken[nLastToken]["sValue"]))
   551    550                               elif cActionType == ">":
   552    551                                   # we do nothing, this test is just a condition to apply all following actions
   553    552                                   if bDebug:
   554         -                                    echo("    COND_OK:  " + sRuleId + " " + sLineId)
          553  +                                    echo("    COND_OK")
   555    554                                   pass
   556    555                               elif cActionType == "/":
   557    556                                   # Tag
   558    557                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   559    558                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   560    559                                   for i in range(nTokenStart, nTokenEnd+1):
   561    560                                       if "tags" in self.lToken[i]:
   562    561                                           self.lToken[i]["tags"].update(sWhat.split("|"))
   563    562                                       else:
   564    563                                           self.lToken[i]["tags"] = set(sWhat.split("|"))
   565    564                                   if bDebug:
   566         -                                    echo("    TAG:  " + sRuleId + " " + sLineId)
   567         -                                    echo("       " + sWhat + " > " + self.lToken[nTokenStart]["sValue"] + " : " + self.lToken[nTokenEnd]["sValue"])
          565  +                                    echo("    TAG: {} >  [{}:{}]".format(sWhat, self.lToken[nTokenStart]["sValue"], self.lToken[nTokenEnd]["sValue"]))
   568    566                                   if sWhat not in self.dTags:
   569    567                                       self.dTags[sWhat] = [nTokenStart, nTokenStart]
   570    568                                   else:
   571    569                                       self.dTags[sWhat][0] = min(nTokenStart, self.dTags[sWhat][0])
   572    570                                       self.dTags[sWhat][1] = max(nTokenEnd, self.dTags[sWhat][1])
   573    571                               elif cActionType == "%":
   574    572                                   # immunity
   575    573                                   if bDebug:
   576         -                                    echo("    IMMUNITY:\n      " + _rules_graph.dRule[sRuleId])
          574  +                                    echo("    IMMUNITY: " + _rules_graph.dRule[sRuleId])
   577    575                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   578    576                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   579    577                                   if nTokenEnd - nTokenStart == 0:
   580    578                                       self.lToken[nTokenStart]["bImmune"] = True
   581    579                                       nErrorStart = self.nOffsetWithinParagraph + self.lToken[nTokenStart]["nStart"]
   582    580                                       if nErrorStart in self.dError:
   583    581                                           del self.dError[nErrorStart]
................................................................................
   587    585                                           nErrorStart = self.nOffsetWithinParagraph + self.lToken[i]["nStart"]
   588    586                                           if nErrorStart in self.dError:
   589    587                                               del self.dError[nErrorStart]
   590    588                               else:
   591    589                                   echo("# error: unknown action at " + sLineId)
   592    590                           elif cActionType == ">":
   593    591                               if bDebug:
   594         -                                echo("    COND_BREAK:  " + sRuleId + " " + sLineId)
          592  +                                echo("    COND_BREAK")
   595    593                               break
   596    594                   except Exception as e:
   597    595                       raise Exception(str(e), sLineId, sRuleId, self.sSentence)
   598    596           return bChange
   599    597   
   600    598       def _createErrorFromRegex (self, sText, sText0, sRepl, nOffset, m, iGroup, sLineId, sRuleId, bUppercase, sMsg, sURL, bShowRuleId, sOption, bContext):
   601    599           nStart = nOffset + m.start(iGroup)
................................................................................
   699    697           else:
   700    698               sNew = m.expand(sRepl)
   701    699               sNew = sNew + " " * (nLen-len(sNew))
   702    700           return sText[0:m.start(iGroup)] + sNew + sText[m.end(iGroup):]
   703    701   
   704    702       def _tagAndPrepareTokenForRewriting (self, sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug):
   705    703           "text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position"
   706         -        if bDebug:
   707         -            echo("   START: {} - END: {}  ".format(nTokenRewriteStart, nTokenRewriteEnd))
   708    704           if sWhat == "*":
   709    705               # purge text
   710    706               if nTokenRewriteEnd - nTokenRewriteStart == 0:
   711    707                   self.lToken[nTokenRewriteStart]["bToRemove"] = True
   712    708               else:
   713    709                   for i in range(nTokenRewriteStart, nTokenRewriteEnd+1):
   714    710                       self.lToken[i]["bToRemove"] = True
................................................................................
   851    847       if sNegPattern and re.search(sNegPattern, s):
   852    848           return False
   853    849       if re.search(sPattern, s):
   854    850           return True
   855    851       return False
   856    852   
   857    853   
   858         -def look_chk1 (dTokenPos, s, nOffset, sPattern, sPatternGroup1, sNegPatternGroup1=None):
          854  +def look_chk1 (dTokenPos, s, nOffset, sPattern, sPatternGroup1, sNegPatternGroup1=""):
   859    855       "returns True if s has pattern sPattern and m.group(1) has pattern sPatternGroup1"
   860    856       m = re.search(sPattern, s)
   861    857       if not m:
   862    858           return False
   863    859       try:
   864    860           sWord = m.group(1)
   865    861           nPos = m.start(1) + nOffset
   866    862       except:
   867    863           return False
   868         -    if sNegPatternGroup1:
   869         -        return morphex(dTokenPos, (nPos, sWord), sPatternGroup1, sNegPatternGroup1)
   870         -    return morph(dTokenPos, (nPos, sWord), sPatternGroup1, False)
          864  +    return morph(dTokenPos, (nPos, sWord), sPatternGroup1, sNegPatternGroup1)
          865  +
   871    866   
   872    867   
   873    868   #### Analyse groups for regex rules
   874    869   
   875    870   def displayInfo (dTokenPos, tWord):
   876    871       "for debugging: retrieve info of word"
   877    872       if not tWord: