Index: compile_rules_js_convert.py ================================================================== --- compile_rules_js_convert.py +++ compile_rules_js_convert.py @@ -8,11 +8,10 @@ def py2js (sCode): "convert Python code to JavaScript code" # Python strings - sCode = sCode.replace(' ', ' ') sCode = sCode.replace('(r"', '("') sCode = sCode.replace("(r'", "('") sCode = sCode.replace(' r"', ' "') sCode = sCode.replace(" r'", " '") sCode = sCode.replace(',r"', ',"') @@ -125,12 +124,12 @@ return lRuleJS del lRule[-1] # tGroups positioning codes are useless for Python # error messages for aAction in lRuleJS[6]: if aAction[1] == "-": - aAction[2] = aAction[2].replace(" ", " ") # nbsp --> nnbsp - aAction[4] = aAction[4].replace("« ", "« ").replace(" »", " »").replace(" :", " :").replace(" :", " :") + aAction[4] = aAction[4].replace(" ", " ") # nbsp --> nnbsp + aAction[4] = aAction[4].replace("« ", "« ").replace(" »", " »").replace(" :", " :").replace(" ;", " ;").replace(" ?", " ?").replace(" !", " :") # js regexes lRuleJS[1], lNegLookBehindRegex = regex2js(dJSREGEXES.get(lRuleJS[3], lRuleJS[1]), sWORDLIMITLEFT) lRuleJS.append(lNegLookBehindRegex) return lRuleJS Index: gc_core/js/lang_core/gc_engine.js ================================================================== --- gc_core/js/lang_core/gc_engine.js +++ gc_core/js/lang_core/gc_engine.js @@ -303,11 +303,10 @@ let bCondMemo = null; for (let [sFuncCond, cActionType, sWhat, ...eAct] of lActions) { // action in lActions: [ condition, action type, replacement/suggestion/action[, iGroup[, message, URL]] ] try { bCondMemo = (!sFuncCond || gc_functions[sFuncCond](sText, sText0, m, this.dTokenPos, sCountry, bCondMemo)); - //bCondMemo = (!sFuncCond || oEvalFunc[sFuncCond](sText, sText0, m, this.dTokenPos, sCountry, bCondMemo)); if (bCondMemo) { switch (cActionType) { case "-": // grammar error //console.log("-> error detected in " + sLineId + "\nzRegex: " + zRegex.source); @@ -329,11 +328,10 @@ break; case "=": // disambiguation //console.log("-> disambiguation by " + sLineId + "\nzRegex: " + zRegex.source); gc_functions[sWhat](sText, m, this.dTokenPos); - //oEvalFunc[sWhat](sText, m, this.dTokenPos); if (bDebug) { console.log("= " + m[0] + " # " + sLineId, "\nDA:", this.dTokenPos); } break; case ">": @@ -662,11 +660,10 @@ // Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] // Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] // Test [ option, condition, ">", "" ] if (!sOption || dOptions.gl_get(sOption, false)) { bCondMemo = !sFuncCond || gc_functions[sFuncCond](this.lTokens, nTokenOffset, nLastToken, sCountry, bCondMemo, this.dTags, this.sSentence, this.sSentence0); - //bCondMemo = !sFuncCond || oEvalFunc[sFuncCond](this.lTokens, nTokenOffset, nLastToken, sCountry, bCondMemo, this.dTags, this.sSentence, this.sSentence0); if (bCondMemo) { if (cActionType == "-") { // grammar error let [iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL] = eAct; let nTokenErrorStart = (iTokenStart > 0) ? nTokenOffset + iTokenStart : nLastToken + iTokenStart; @@ -696,11 +693,10 @@ } } else if (cActionType == "=") { // disambiguation gc_functions[sWhat](this.lTokens, nTokenOffset, nLastToken); - //oEvalFunc[sWhat](this.lTokens, nTokenOffset, nLastToken); if (bDebug) { console.log(` DISAMBIGUATOR: (${sWhat}) [${this.lTokens[nTokenOffset+1]["sValue"]}:${this.lTokens[nLastToken]["sValue"]}]`); } } else if (cActionType == ">") { @@ -780,23 +776,21 @@ let nEnd = nOffset + m.end[iGroup]; // suggestions let lSugg = []; if (sSugg.startsWith("=")) { sSugg = gc_functions[sSugg.slice(1)](sText, m); - //sSugg = oEvalFunc[sSugg.slice(1)](sText, m); - lSugg = (sSugg) ? sSugg.split("|") : []; + lSugg = (sSugg) ? sSugg.replace(/ /g, " ").split("|") : []; } else if (sSugg == "_") { lSugg = []; } else { - lSugg = sSugg.gl_expand(m).split("|"); + lSugg = sSugg.gl_expand(m).replace(/ /g, " ").split("|"); } if (bCaseSvty && lSugg.length > 0 && m[iGroup].slice(0,1).gl_isUpperCase()) { lSugg = (m[iGroup].gl_isUpperCase()) ? lSugg.map((s) => s.toUpperCase()) : capitalizeArray(lSugg); } // Message let sMessage = (sMsg.startsWith("=")) ? gc_functions[sMsg.slice(1)](sText, m) : sMsg.gl_expand(m); - //let sMessage = (sMsg.startsWith("=")) ? oEvalFunc[sMsg.slice(1)](sText, m) : sMsg.gl_expand(m); if (bShowRuleId) { sMessage += " #" + sLineId + " / " + sRuleId; } // return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); @@ -805,23 +799,21 @@ _createErrorFromTokens (sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext) { // suggestions let lSugg = []; if (sSugg.startsWith("=")) { sSugg = gc_functions[sSugg.slice(1)](this.lTokens, nTokenOffset, nLastToken); - //sSugg = oEvalFunc[sSugg.slice(1)](this.lTokens, nTokenOffset, nLastToken); - lSugg = (sSugg) ? sSugg.split("|") : []; + lSugg = (sSugg) ? sSugg.replace(/ /g, " ").split("|") : []; } else if (sSugg == "_") { lSugg = []; } else { - lSugg = this._expand(sSugg, nTokenOffset, nLastToken).split("|"); + lSugg = this._expand(sSugg, nTokenOffset, nLastToken).replace(/ /g, " ").split("|"); } if (bCaseSvty && lSugg.length > 0 && this.lTokens[iFirstToken]["sValue"].slice(0,1).gl_isUpperCase()) { lSugg = (this.sSentence.slice(nStart, nEnd).gl_isUpperCase()) ? lSugg.map((s) => s.toUpperCase()) : capitalizeArray(lSugg); } // Message let sMessage = (sMsg.startsWith("=")) ? gc_functions[sMsg.slice(1)](this.lTokens, nTokenOffset, nLastToken) : this._expand(sMsg, nTokenOffset, nLastToken); - //let sMessage = (sMsg.startsWith("=")) ? oEvalFunc[sMsg.slice(1)](this.lTokens, nTokenOffset, nLastToken) : this._expand(sMsg, nTokenOffset, nLastToken); if (bShowRuleId) { sMessage += " #" + sLineId + " / " + sRuleId; } // return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); @@ -872,11 +864,10 @@ else if (sRepl === "@") { sNew = "@".repeat(ln); } else if (sRepl.slice(0,1) === "=") { sNew = gc_functions[sRepl.slice(1)](sText, m); - //sNew = oEvalFunc[sRepl.slice(1)](sText, m); sNew = sNew + " ".repeat(ln-sNew.length); if (bUppercase && m[iGroup].slice(0,1).gl_isUpperCase()) { sNew = sNew.gl_toCapitalize(); } } else { @@ -919,11 +910,10 @@ } } else { if (sWhat.startsWith("=")) { sWhat = gc_functions[sWhat.slice(1)](this.lTokens, nTokenOffset, nLastToken); - //sWhat = oEvalFunc[sWhat.slice(1)](this.lTokens, nTokenOffset, nLastToken); } else { sWhat = this._expand(sWhat, nTokenOffset, nLastToken); } let bUppercase = bCaseSvty && this.lTokens[nTokenRewriteStart]["sValue"].slice(0,1).gl_isUpperCase(); if (nTokenRewriteEnd - nTokenRewriteStart == 0) { Index: gc_lang/fr/rules.grx ================================================================== --- gc_lang/fr/rules.grx +++ gc_lang/fr/rules.grx @@ -1305,12 +1305,12 @@ !! __[s]/num(num_grand_nombre_soudé)__ \d\d\d\d+ <<- not before("NF[  -]?(C|E|P|Q|X|Z|EN(?:[  -]ISO|)) *$") >>> - <<- ((after("^(?:,[0-9]+[⁰¹²³⁴⁵⁶⁷⁸⁹]?|[⁰¹²³⁴⁵⁶⁷⁸⁹])") and not (re.search("^[01]+$", \0) and after("^,[01]+\\b"))) - or after("^[   ]*(?:[kcmµn]?(?:[slgJKΩ]|m[²³]?|Wh?|Hz|dB)|[%‰€$£¥Åℓhj]|min|°C|℃)(?![\\w’'])")) + <<- (after("^(?:,[0-9]+[⁰¹²³⁴⁵⁶⁷⁸⁹]?|[⁰¹²³⁴⁵⁶⁷⁸⁹])") and not (re.search("^[01]+$", \0) and after("^,[01]+\\b"))) + or after("^[    ]*(?:[kcmµn]?(?:[slgJKΩ]|m[²³]?|Wh?|Hz|dB)|[%‰€$£¥Åℓhj]|min|°C|℃)(?![\\w’'])") ->> =formatNumber(\0, True) && Formatage des grands nombres. <<- __else__ and \0.__len__() > 4 ->> =formatNumber(\0) && Formatage des grands nombres. __[s]/num(num_nombre_quatre_chiffres)__ (?> 0 234 567 890|02 34 56 78 90|023 456 78 90|0234 567-890 TEST: {{12345678901}} ->> 12 345 678 901 TEST: {{112798931830912839}} ->> 112 798 931 830 912 839 TEST: {{2308393909}} ->> 2 308 393 909|2308 393-909 TEST: {{2024}},9 ->> 2 024 -TEST: {{4000}} Å ->> 4 000 +TEST: {{4000}} Å ->> 4 000 TEST: {{10010}} € ->> 10 010 +TEST: {{12010}} kg ->> 12 010 +TEST: {{12010}} m² ->> 12 010 +TEST: {{12010}} dB ->> 12 010 +TEST: {{12010}} % ->> 12 010 +TEST: {{11010}} min ->> 11 010 TEST: {{3240}} µA ->> 3 240 TEST: 1111 0011,01 (binaire) __[s>(num_grand_nombre_avec_points)__