Grammalecte  Check-in [a75b859e72]

Overview
Comment:[core][js] gc engine: fix several issues
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | rg
Files: files | file ages | folders
SHA3-256: a75b859e725e130458655bbf84e2c67579ab69c4f10ab598f4a6e890bd936405
User & Date: olr on 2018-09-11 21:20:48
Other Links: branch diff | manifest | tags
Context
2018-09-12
07:58
[core][js] gc engine: fix several issues check-in: b4074ae3b3 user: olr tags: core, rg
2018-09-11
21:20
[core][js] gc engine: fix several issues check-in: a75b859e72 user: olr tags: core, rg
20:50
[core][js] gc engine: fix several issues check-in: 19fa3fc573 user: olr tags: core, rg
Changes

Modified gc_core/js/lang_core/gc_engine.js from [efd2e8524d] to [ab940d7e96].

   522    522               }
   523    523               if (!bTokenFound  &&  dPointer.hasOwnProperty("bKeep")) {
   524    524                   yield dPointer;
   525    525               }
   526    526               // JUMP
   527    527               // Warning! Recurssion!
   528    528               if (dNode.hasOwnProperty("<>")) {
   529         -                let dPointer2 = { "iNode1": iNode1, "dNode": dGraph[dNode["<>"]], "bKeep": True };
          529  +                let dPointer2 = { "iNode1": iNode1, "dNode": dGraph[dNode["<>"]], "bKeep": true };
   530    530                   yield* this._getNextPointers(dToken, dGraph, dPointer2, bDebug);
   531    531               }
   532    532           }
   533    533           catch (e) {
   534    534               console.error(e);
   535    535           }
   536    536       }
................................................................................
   602    602                                       let nTokenErrorEnd = (iTokenEnd > 0) ? nTokenOffset + iTokenEnd : nLastToken + iTokenEnd;
   603    603                                       let nErrorStart = this.nOffsetWithinParagraph + ((cStartLimit == "<") ? this.lToken[nTokenErrorStart]["nStart"] : this.lToken[nTokenErrorStart]["nEnd"]);
   604    604                                       let nErrorEnd = this.nOffsetWithinParagraph + ((cEndLimit == ">") ? this.lToken[nTokenErrorEnd]["nEnd"] : this.lToken[nTokenErrorEnd]["nStart"]);
   605    605                                       if (!this.dError.has(nErrorStart) || nPriority > this.dErrorPriority.get(nErrorStart, -1)) {
   606    606                                           this.dError[nErrorStart] = this._createErrorFromTokens(sWhat, nTokenOffset, nLastToken, nTokenErrorStart, nErrorStart, nErrorEnd, sLineId, sRuleId, bCaseSvty, sMessage, sURL, bShowRuleId, sOption, bContext);
   607    607                                           this.dErrorPriority[nErrorStart] = nPriority;
   608    608                                           if (bDebug) {
   609         -                                            console.log("    NEW_ERROR:  {}  {}:  {}".format(sRuleId, sLineId, this.dError[nErrorStart]));
          609  +                                            console.log(`    NEW_ERROR:  ${sRuleId}  ${sLineId}:  ${this.dError[nErrorStart]}`);
   610    610                                           }
   611    611                                       }
   612    612                                   }
   613    613                               }
   614    614                               else if (cActionType == "~") {
   615    615                                   // text processor
   616    616                                   let nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0];
   617    617                                   let nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1];
   618    618                                   this._tagAndPrepareTokenForRewriting(sWhat, nTokenStart, nTokenEnd, nTokenOffset, nLastToken, eAct[2], bDebug);
   619    619                                   bChange = true;
   620    620                                   if (bDebug) {
   621         -                                    console.log("    TEXT_PROCESSOR:  " + sRuleId + " " + sLineId);
   622         -                                    console.log("       " + this.lToken[nTokenStart]["sValue"] + " : " + this.lToken[nTokenEnd]["sValue"] + "  > ", sWhat);
          621  +                                    console.log(`    TEXT_PROCESSOR:  ${sRuleId} ${sLineId}`);
          622  +                                    console.log(`      ${this.lToken[nTokenStart]["sValue"]} : ${this.lToken[nTokenEnd]["sValue"]}  > ${sWhat}`);
   623    623                                   }
   624    624                               }
   625    625                               else if (cActionType == "=") {
   626    626                                   // disambiguation
   627    627                                   oEvalFunc[sWhat](this.lToken, nTokenOffset, nLastToken);
   628    628                                   if (bDebug) {
   629         -                                    console.log("    DISAMBIGUATOR:  {} {} ({})  {}:{}".format(sRuleId, sLineId, sWhat, this.lToken[nTokenOffset+1]["sValue"], this.lToken[nLastToken]["sValue"]));
          629  +                                    console.log(`    DISAMBIGUATOR:  ${sRuleId} ${sLineId} (${sWhat})  ${this.lToken[nTokenOffset+1]["sValue"]}:${this.lToken[nLastToken]["sValue"]}`);
   630    630                                   }
   631    631                               }
   632    632                               else if (cActionType == ">") {
   633    633                                   // we do nothing, this test is just a condition to apply all following actions
   634    634                                   if (bDebug) {
   635         -                                    console.log("    COND_OK:  " + sRuleId + " " + sLineId);
          635  +                                    console.log(`    COND_OK:  ${sRuleId} ${sLineId}`);
   636    636                                   }
   637    637                               }
   638    638                               else if (cActionType == "/") {
   639    639                                   // Tag
   640    640                                   let nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0];
   641    641                                   let nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1];
   642    642                                   for (let i = nTokenStart; i <= nTokenEnd; i++) {
................................................................................
   643    643                                       if (this.lToken[i].hasOwnProperty("tags")) {
   644    644                                           this.lToken[i]["tags"].add(...sWhat.split("|"))
   645    645                                       } else {
   646    646                                           this.lToken[i]["tags"] = new Set(sWhat.split("|"));
   647    647                                       }
   648    648                                   }
   649    649                                   if (bDebug) {
   650         -                                    console.log("    TAG:  " + sRuleId + " " + sLineId);
   651         -                                    console.log("       " + sWhat + " > " + this.lToken[nTokenStart]["sValue"] + " : " + this.lToken[nTokenEnd]["sValue"]);
          650  +                                    console.log(`    TAG:  ${sRuleId} ${sLineId}`);
          651  +                                    console.log(`      ${sWhat} > ${this.lToken[nTokenStart]["sValue"]} : ${this.lToken[nTokenEnd]["sValue"]}`);
   652    652                                   }
   653    653                                   if (!this.dTags.has(sWhat)) {
   654    654                                       this.dTags.set(sWhat, [nTokenStart, nTokenStart]);
   655    655                                   } else {
   656    656                                       this.dTags.set(sWhat, [Math.min(nTokenStart, this.dTags.get(sWhat)[0]), Math.max(nTokenEnd, this.dTags.get(sWhat)[1])]);
   657    657                                   }
   658    658                               }
   659    659                               else if (cActionType == "%") {
   660    660                                   // immunity
   661    661                                   if (bDebug) {
   662         -                                    console.log("    IMMUNITY:\n      " + _rules_graph.dRule[sRuleId]);;
          662  +                                    console.log("    IMMUNITY:\n      " + _rules_graph.dRule[sRuleId]);
   663    663                                   }
   664    664                                   nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0];
   665    665                                   nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1];
   666    666                                   if (nTokenEnd - nTokenStart == 0) {
   667         -                                    this.lToken[nTokenStart]["bImmune"] = True
          667  +                                    this.lToken[nTokenStart]["bImmune"] = true;
   668    668                                       let nErrorStart = this.nOffsetWithinParagraph + this.lToken[nTokenStart]["nStart"];
   669         -                                    if (nErrorStart in this.dError) {
          669  +                                    if (this.dError.has(nErrorStart)) {
   670    670                                           this.dError.delete(nErrorStart);
   671    671                                       }
   672    672                                   } else {
   673    673                                       for (let i = nTokenStart;  i <= nTokenEnd;  i++) {
   674    674                                           this.lToken[i]["bImmune"] = true;
   675    675                                           let nErrorStart = this.nOffsetWithinParagraph + this.lToken[i]["nStart"];
   676    676                                           if (this.dError.has(nErrorStart)) {
................................................................................
   680    680                                   }
   681    681                               } else {
   682    682                                   console.log("# error: unknown action at " + sLineId);
   683    683                               }
   684    684                           }
   685    685                           else if (cActionType == ">") {
   686    686                               if (bDebug) {
   687         -                                console.log("    COND_BREAK:  " + sRuleId + " " + sLineId);
          687  +                                console.log(`    COND_BREAK:  ${sRuleId} ${sLineId}`);
   688    688                               }
   689    689                               break;
   690    690                           }
   691    691                       }
   692    692                   }
   693    693                   catch (e) {
   694    694                       console.log("Error: ", sLineId, sRuleId, this.sSentence);
................................................................................
   731    731               sSugg = oEvalFunc[sSugg.slice(1)](this.lToken, nTokenOffset, nLastToken);
   732    732               lSugg = (sSugg) ? sSugg.split("|") : [];
   733    733           } else if (sSugg == "_") {
   734    734               lSugg = [];
   735    735           } else {
   736    736               lSugg = this._expand(sSugg, nTokenOffset, nLastToken).split("|");
   737    737           }
   738         -        if (bCaseSvty && lSugg.length > 0 && this.lToken[iFirstToken]["sValue"].slice(0,1).isupper()) {
          738  +        if (bCaseSvty && lSugg.length > 0 && this.lToken[iFirstToken]["sValue"].slice(0,1).gl_isUpperCase()) {
   739    739               lSugg = capitalizeArray(lSugg);
   740    740           }
   741    741           // Message
   742    742           let sMessage = (sMsg.startsWith("=")) ? oEvalFunc[sMsg.slice(1)](this.lToken, nTokenOffset, nLastToken) : this._expand(sMsg, nTokenOffset, nLastToken);
   743    743           if (bShowRuleId) {
   744    744               sMessage += " ## " + sLineId + " # " + sRuleId;
   745    745           }
................................................................................
   836    836           }
   837    837           else {
   838    838               if (sWhat.startsWith("=")) {
   839    839                   sWhat = oEvalFunc[sWhat.slice(1)](this.lToken, nTokenOffset, nLastToken);
   840    840               } else {
   841    841                   sWhat = this._expand(sWhat, nTokenOffset, nLastToken);
   842    842               }
   843         -            let bUppercase = bCaseSvty && this.lToken[nTokenRewriteStart]["sValue"].slice(0,1).isupper();
          843  +            let bUppercase = bCaseSvty && this.lToken[nTokenRewriteStart]["sValue"].slice(0,1).gl_isUpperCase();
   844    844               if (nTokenRewriteEnd - nTokenRewriteStart == 0) {
   845    845                   // one token
   846    846                   if (bUppercase) {
   847    847                       sWhat = sWhat.gl_toCapitalize();
   848    848                   }
   849    849                   this.lToken[nTokenRewriteStart]["sNewValue"] = sWhat;
   850    850               }
................................................................................
   933    933                       console.log(dToken);
   934    934                   }
   935    935               }
   936    936           }
   937    937           if (bDebug) {
   938    938               console.log("  TEXT REWRITED: " + this.sSentence);
   939    939           }
   940         -        this.lToken.clear();
          940  +        this.lToken.length = 0;
   941    941           this.lToken = lNewToken;
   942    942       }
   943         -
   944    943   };
   945    944   
   946    945   
   947    946   //////// Common functions
   948    947   
   949    948   function option (sOpt) {
   950    949       // return true if option sOpt is active