Grammalecte  Check-in [a88fc2da75]

Overview
Comment:[core] gc core: new action -> merge and rewrite
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: a88fc2da75fab029d30ebf404e92f6226f56595bdd92ff52cc7850017fd07523
User & Date: olr on 2020-09-28 12:51:43
Other Links: manifest | tags
Context
2020-09-30
12:01
[fr] ajustements check-in: 66a7f50008 user: olr tags: fr, trunk
2020-09-28
12:51
[core] gc core: new action -> merge and rewrite check-in: a88fc2da75 user: olr tags: core, trunk
2020-09-20
09:06
[fr] ajustements check-in: e60b89c599 user: olr tags: fr, trunk
Changes

Modified gc_core/js/lang_core/gc_engine.js from [5b16fd7058] to [e5451f03eb].

   909    909                   }
   910    910               }
   911    911           }
   912    912           else if (sWhat === "␣") {
   913    913               // merge tokens
   914    914               this.lTokens[nTokenRewriteStart]["nMergeUntil"] = nTokenRewriteEnd;
   915    915           }
          916  +        else if (sWhat.startsWith("␣")) {
          917  +            sWhat = this._expand(sWhat, nTokenOffset, nLastToken);
          918  +            this.lTokens[nTokenRewriteStart]["nMergeUntil"] = nTokenRewriteEnd;
          919  +            this.lTokens[nTokenRewriteStart]["sMergedValue"] = sWhat.slice(1);
          920  +        }
   916    921           else if (sWhat === "_") {
   917    922               // neutralized token
   918    923               if (nTokenRewriteEnd - nTokenRewriteStart == 0) {
   919    924                   this.lTokens[nTokenRewriteStart]["sNewValue"] = "_";
   920    925               } else {
   921    926                   for (let i = nTokenRewriteStart;  i <= nTokenRewriteEnd;  i++) {
   922    927                       this.lTokens[i]["sNewValue"] = "_";
................................................................................
   979    984                       oMergingToken["sValue"] += " ".repeat(oToken["nStart"] - oMergingToken["nEnd"]) + oToken["sValue"];
   980    985                       oMergingToken["nEnd"] = oToken["nEnd"];
   981    986                       if (bDebug) {
   982    987                           console.log("  MERGED TOKEN: " + oMergingToken["sValue"]);
   983    988                       }
   984    989                       oToken["bMerged"] = true;
   985    990                       bKeepToken = false;
          991  +                    if (iToken == nMergeUntil && oMergingToken.hasOwnProperty("sMergedValue")) {
          992  +                        oMergingToken["sValue"] = oMergingToken["sMergedValue"];
          993  +                        let sSpaceFiller = " ".repeat(oToken["nEnd"] - oMergingToken["nStart"] - oMergingToken["sMergedValue"].length);
          994  +                        this.sSentence = this.sSentence.slice(0, oMergingToken["nStart"]) + oMergingToken["sMergedValue"] + sSpaceFiller + this.sSentence.slice(oToken["nEnd"]);
          995  +                    }
   986    996                   }
   987    997                   if (oToken.hasOwnProperty("nMergeUntil")) {
   988    998                       if (iToken > nMergeUntil) { // this token is not already merged with a previous token
   989    999                           oMergingToken = oToken;
   990   1000                       }
   991   1001                       if (oToken["nMergeUntil"] > nMergeUntil) {
   992   1002                           nMergeUntil = oToken["nMergeUntil"];

Modified gc_core/py/lang_core/gc_engine.py from [20a4e92e8f] to [05ee688cb4].

   792    792                   self.lTokens[nTokenRewriteStart]["bToRemove"] = True
   793    793               else:
   794    794                   for i in range(nTokenRewriteStart, nTokenRewriteEnd+1):
   795    795                       self.lTokens[i]["bToRemove"] = True
   796    796           elif sWhat == "␣":
   797    797               # merge tokens
   798    798               self.lTokens[nTokenRewriteStart]["nMergeUntil"] = nTokenRewriteEnd
          799  +        elif sWhat.startswith("␣"):
          800  +            sWhat = self._expand(sWhat, nTokenOffset, nLastToken)
          801  +            self.lTokens[nTokenRewriteStart]["nMergeUntil"] = nTokenRewriteEnd
          802  +            self.lTokens[nTokenRewriteStart]["sMergedValue"] = sWhat[1:]
   799    803           elif sWhat == "_":
   800    804               # neutralized token
   801    805               if nTokenRewriteEnd - nTokenRewriteStart == 0:
   802    806                   self.lTokens[nTokenRewriteStart]["sNewValue"] = "_"
   803    807               else:
   804    808                   for i in range(nTokenRewriteStart, nTokenRewriteEnd+1):
   805    809                       self.lTokens[i]["sNewValue"] = "_"
................................................................................
   844    848                       # token to merge
   845    849                       dTokenMerger["sValue"] += " " * (dToken["nStart"] - dTokenMerger["nEnd"]) + dToken["sValue"]
   846    850                       dTokenMerger["nEnd"] = dToken["nEnd"]
   847    851                       if bDebug:
   848    852                           echo("  MERGED TOKEN: " + dTokenMerger["sValue"])
   849    853                       dToken["bMerged"] = True
   850    854                       bKeepToken = False
          855  +                    if iToken == nMergeUntil and "sMergedValue" in dTokenMerger:
          856  +                        dTokenMerger["sValue"] = dTokenMerger["sMergedValue"]
          857  +                        sSpaceFiller = " " * (dToken["nEnd"] - dTokenMerger["nStart"] - len(dTokenMerger["sMergedValue"]))
          858  +                        self.sSentence = self.sSentence[:dTokenMerger["nStart"]] + dTokenMerger["sMergedValue"] + sSpaceFiller + self.sSentence[dToken["nEnd"]:]
   851    859                   if "nMergeUntil" in dToken:
   852    860                       # first token to be merge with
   853    861                       if iToken > nMergeUntil: # this token is not to be merged with a previous token
   854    862                           dTokenMerger = dToken
   855    863                       if dToken["nMergeUntil"] > nMergeUntil:
   856    864                           nMergeUntil = dToken["nMergeUntil"]
   857    865                       del dToken["nMergeUntil"]