Grammalecte  Check-in [d614738660]

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

Overview
Comment:[build][core] colors for errors (draft)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core | build
Files: files | file ages | folders
SHA3-256:d614738660fb4ee6ca81738e8602ea8903e005c215903d58ffb13b8226ef4e11
User & Date: olr 2018-09-23 10:13:19
Context
2018-09-24
08:14
[fr] nr: qu’en-dira-t-on, + faux positif: à l’arrache check-in: dffdca5554 user: olr tags: fr, trunk
2018-09-23
10:13
[build][core] colors for errors (draft) check-in: d614738660 user: olr tags: build, core, trunk
2018-09-21
08:22
[fr] règle: aussi +adj que >être check-in: 86b8eee060 user: olr tags: fr, trunk
Changes

Changes to compile_rules.py.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33


34









35
36
37
38
39
40
41
42
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
...
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
"""
Grammalecte: compile rules
"""

import re
import traceback
import json


import compile_rules_js_convert as jsconv
import compile_rules_graph as crg


dDEF = {}
lFUNCTIONS = []
................................................................................

dJSREGEXES = {}

sWORDLIMITLEFT  = r"(?<![\w.,–-])"   # r"(?<![-.,—])\b"  seems slower
sWORDLIMITRIGHT = r"(?![\w–-])"      # r"\b(?!-—)"       seems slower


def _rgb (r, g, b):
    return (r & 255) << 16 | (g & 255) << 8 | (b & 255)


def getRGB (sHex):
    if sHex:
        r = int(sHex[:2], 16)
        g = int(sHex[2:4], 16)
        b = int(sHex[4:], 16)


        return _rgb(r, g, b)









    return _rgb(0, 0, 0)


def prepareFunction (s):
    "convert simple rule syntax to a string of Python code"
    s = s.replace("__also__", "bCondMemo")
    s = s.replace("__else__", "not bCondMemo")
    s = re.sub(r"isStart *\(\)", 'before("^ *$|, *$")', s)
................................................................................
            m = re.match("OPT/([a-z0-9]+):(.+)$", sLine)
            for i, sOpt in enumerate(m.group(2).split()):
                lOpt[i][1][m.group(1)] = eval(sOpt)
        elif sLine.startswith("OPTCOLORSOFTWARE:"):
            lOptColor = [ [s, {}]  for s in sLine[17:].strip().split() ]  # don’t use tuples (s, {}), because unknown to JS
        elif sLine.startswith("OPTCOLOR/"):
            m = re.match("OPTCOLOR/([a-z0-9]+):(.+)$", sLine)
            for i, sOpt in enumerate(m.group(2).split()):
                lOptColor[i][1][m.group(1)] = [ int(s)  for s in sOpt.split(",") ]
        elif sLine.startswith("OPTPRIORITY/"):
            m = re.match("OPTPRIORITY/([a-z0-9]+): *([0-9])$", sLine)
            dOptPriority[m.group(1)] = int(m.group(2))
        elif sLine.startswith("OPTLANG/"):
            m = re.match("OPTLANG/([a-z][a-z](?:_[A-Z][A-Z]|)):(.+)$", sLine)
            sLang = m.group(1)[:2]
            dOptLabel[sLang] = { "__optiontitle__": m.group(2).strip() }
................................................................................
        elif sLine.startswith("OPTLABEL/"):
            m = re.match("OPTLABEL/([a-z0-9]+):(.+)$", sLine)
            dOptLabel[sLang][m.group(1)] = list(map(str.strip, m.group(2).split("|")))  if "|" in m.group(2)  else  [m.group(2).strip(), ""]
        else:
            print("# Error. Wrong option line in:\n  ")
            print(sLine)
    print("  options defined for: " + ", ".join([ t[0] for t in lOpt ]))
    print(lOptColor)
    dOptions = { "lStructOpt": lStructOpt, "dOptLabel": dOptLabel, "sDefaultUILang": sDefaultUILang }
    dOptions.update({ "dOpt"+k: v  for k, v in lOpt })

    return dOptions, dOptPriority


def printBookmark (nLevel, sComment, nLine):
    "print bookmark within the rules file"
    print("  {:>6}:  {}".format(nLine, "  " * nLevel + sComment))








>







 







|



|
|
|
<
<
>
>
|
>
>
>
>
>
>
>
>
>
|







 







|
|







 







<


>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
...
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
...
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458
459
460
"""
Grammalecte: compile rules
"""

import re
import traceback
import json
import colorsys

import compile_rules_js_convert as jsconv
import compile_rules_graph as crg


dDEF = {}
lFUNCTIONS = []
................................................................................

dJSREGEXES = {}

sWORDLIMITLEFT  = r"(?<![\w.,–-])"   # r"(?<![-.,—])\b"  seems slower
sWORDLIMITRIGHT = r"(?![\w–-])"      # r"\b(?!-—)"       seems slower


def convertRGBToInteger (r, g, b):
    return (r & 255) << 16 | (g & 255) << 8 | (b & 255)


def convertHSLToInteger (h, s, l):
    r, g, b = colorsys.hls_to_rgb(h/360, l/100, s/100)
    return convertRGBToInteger(round(r*255), round(g*255), round(b*255))




def createColors (lOptColor):
    dAppColor = {}
    for sApp, dOptColor in lOptColor:
        if sApp == "Writer":
            dAppColor["dOptColor"+sApp] = { sKey: convertHSLToInteger(*aColor)  for sKey, aColor in dOptColor.items() }
        elif sApp in ("Firefox", "Thunderbird"):
            dAppColor["dOptColor"+sApp] = { sKey: "hsl({}, {}%, {}%)".format(*aColor)  for sKey, aColor in dOptColor.items() }
        else:
            dAppColor["dOptColor"+sApp] = dOptColor
    #print(dAppColor)
    return dAppColor


def prepareFunction (s):
    "convert simple rule syntax to a string of Python code"
    s = s.replace("__also__", "bCondMemo")
    s = s.replace("__else__", "not bCondMemo")
    s = re.sub(r"isStart *\(\)", 'before("^ *$|, *$")', s)
................................................................................
            m = re.match("OPT/([a-z0-9]+):(.+)$", sLine)
            for i, sOpt in enumerate(m.group(2).split()):
                lOpt[i][1][m.group(1)] = eval(sOpt)
        elif sLine.startswith("OPTCOLORSOFTWARE:"):
            lOptColor = [ [s, {}]  for s in sLine[17:].strip().split() ]  # don’t use tuples (s, {}), because unknown to JS
        elif sLine.startswith("OPTCOLOR/"):
            m = re.match("OPTCOLOR/([a-z0-9]+):(.+)$", sLine)
            for i, sColor in enumerate(m.group(2).split()):
                lOptColor[i][1][m.group(1)] = [ int(s) for s in sColor.split(",") ]
        elif sLine.startswith("OPTPRIORITY/"):
            m = re.match("OPTPRIORITY/([a-z0-9]+): *([0-9])$", sLine)
            dOptPriority[m.group(1)] = int(m.group(2))
        elif sLine.startswith("OPTLANG/"):
            m = re.match("OPTLANG/([a-z][a-z](?:_[A-Z][A-Z]|)):(.+)$", sLine)
            sLang = m.group(1)[:2]
            dOptLabel[sLang] = { "__optiontitle__": m.group(2).strip() }
................................................................................
        elif sLine.startswith("OPTLABEL/"):
            m = re.match("OPTLABEL/([a-z0-9]+):(.+)$", sLine)
            dOptLabel[sLang][m.group(1)] = list(map(str.strip, m.group(2).split("|")))  if "|" in m.group(2)  else  [m.group(2).strip(), ""]
        else:
            print("# Error. Wrong option line in:\n  ")
            print(sLine)
    print("  options defined for: " + ", ".join([ t[0] for t in lOpt ]))

    dOptions = { "lStructOpt": lStructOpt, "dOptLabel": dOptLabel, "sDefaultUILang": sDefaultUILang }
    dOptions.update({ "dOpt"+k: v  for k, v in lOpt })
    dOptions.update(createColors(lOptColor))
    return dOptions, dOptPriority


def printBookmark (nLevel, sComment, nLine):
    "print bookmark within the rules file"
    print("  {:>6}:  {}".format(nLine, "  " * nLevel + sComment))

Changes to gc_core/js/lang_core/gc_options.js.

8
9
10
11
12
13
14







15
16
17
18
19
20
21
22






23
24
25
26
27
28
29

30
31

32
33
var gc_options = {
    getOptions: function (sContext="JavaScript") {
        if (this.dOpt.hasOwnProperty(sContext)) {
            return this.dOpt[sContext];
        }
        return this.dOpt["JavaScript"];
    },








    lStructOpt: ${lStructOpt},

    dOpt: {
        "JavaScript": new Map (${dOptJavaScript}),
        "Firefox": new Map (${dOptFirefox}),
        "Thunderbird": new Map (${dOptThunderbird}),
    },







    dOptLabel: ${dOptLabel}
}


if (typeof(exports) !== 'undefined') {
	exports.getOptions = gc_options.getOptions;

	exports.lStructOpt = gc_options.lStructOpt;
    exports.dOpt = gc_options.dOpt;

	exports.dOptLabel = gc_options.dOptLabel;
}







>
>
>
>
>
>
>








>
>
>
>
>
>







>


>


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var gc_options = {
    getOptions: function (sContext="JavaScript") {
        if (this.dOpt.hasOwnProperty(sContext)) {
            return this.dOpt[sContext];
        }
        return this.dOpt["JavaScript"];
    },

    getOptionsColors: function (sContext="JavaScript") {
        if (this.dOptColor.hasOwnProperty(sContext)) {
            return this.dOptColor[sContext];
        }
        return this.dOptColor["JavaScript"];
    },

    lStructOpt: ${lStructOpt},

    dOpt: {
        "JavaScript": new Map (${dOptJavaScript}),
        "Firefox": new Map (${dOptFirefox}),
        "Thunderbird": new Map (${dOptThunderbird}),
    },

    dOptColor: {
        "JavaScript": new Map (${dOptColorJavaScript}),
        "Firefox": new Map (${dOptColorFirefox}),
        "Thunderbird": new Map (${dOptColorThunderbird}),
    },

    dOptLabel: ${dOptLabel}
}


if (typeof(exports) !== 'undefined') {
	exports.getOptions = gc_options.getOptions;
    exports.getOptionsColors = gc_options.getOptionsColors;
	exports.lStructOpt = gc_options.lStructOpt;
    exports.dOpt = gc_options.dOpt;
    exports.dOptColor = gc_options.dOptColor;
	exports.dOptLabel = gc_options.dOptLabel;
}

Changes to gc_core/py/lang_core/gc_options.py.

13
14
15
16
17
18
19







20
21
22
23
24
25
26
27
28
29




30

31

def getOptions (sContext="Python"):
    "returns dictionary of options"
    if sContext in dOpt:
        return dOpt[sContext]
    return dOpt["Python"]









lStructOpt = ${lStructOpt}


dOpt = {
    "Python": ${dOptPython},
    "Server": ${dOptServer},
    "Writer": ${dOptWriter}
}







_dOptLabel = ${dOptLabel}







>
>
>
>
>
>
>










>
>
>
>
|
>

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

def getOptions (sContext="Python"):
    "returns dictionary of options"
    if sContext in dOpt:
        return dOpt[sContext]
    return dOpt["Python"]


def getOptionsColors (sContext="Python"):
    "returns dictionary of options"
    if sContext in dOptColor:
        return dOptColor[sContext]
    return dOptColor["Python"]


lStructOpt = ${lStructOpt}


dOpt = {
    "Python": ${dOptPython},
    "Server": ${dOptServer},
    "Writer": ${dOptWriter}
}

dOptColor = {
    "Python": ${dOptColorPython},
    "Server": ${dOptColorServer},
    "Writer": ${dOptColorWriter}
}

_dOptLabel = ${dOptLabel}