Grammalecte  Check-in [bfd183b930]

Overview
Comment:[core][js] catch error in Map
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: bfd183b930d210959cd1a2207c546e466d7cc7bda535facad18944312569418a
User & Date: olr on 2017-07-31 05:41:46
Other Links: manifest | tags
Context
2017-07-31
06:52
[core][js] log error with helpers check-in: 6eb67129ef user: olr tags: core, trunk
05:41
[core][js] catch error in Map check-in: bfd183b930 user: olr tags: core, trunk
04:55
[fx][core][js] WebExtension: merge with 0053e9898b check-in: a43bd18afb user: olr tags: fx, trunk
Changes

Modified gc_core/js/jsex_regex.js from [cba83b3853] to [ebc9cfd90d].

    21     21               return null;
    22     22           }
    23     23   
    24     24           let codePos;
    25     25           let iPos = 0;
    26     26           m.start = [m.index];
    27     27           m.end = [this.lastIndex];
    28         -        if (m.length > 1) {
    29         -            // there is subgroup(s)
    30         -            if (aGroupsPos !== null) {
    31         -                // aGroupsPos is defined
    32         -                for (let i = 1; i <= m.length-1; i++) {
    33         -                    codePos = aGroupsPos[i-1];
    34         -                    if (typeof codePos === "number") {
    35         -                        // position as a number
    36         -                        m.start.push(m.index + codePos);
    37         -                        m.end.push(m.index + codePos + m[i].length);
    38         -                    } else if (codePos === "$") {
    39         -                        // at the end of the pattern
    40         -                        m.start.push(this.lastIndex - m[i].length);
    41         -                        m.end.push(this.lastIndex);
    42         -                    } else if (codePos === "w") {
    43         -                        // word in the middle of the pattern
    44         -                        iPos = m[0].search("[ ’,()«»“”]"+m[i]+"[ ,’()«»“”]") + 1 + m.index
    45         -                        m.start.push(iPos);
    46         -                        m.end.push(iPos + m[i].length)
    47         -                    } else if (codePos === "*") {
    48         -                        // anywhere
    49         -                        iPos = m[0].indexOf(m[i]) + m.index;
           28  +        try {
           29  +            if (m.length > 1) {
           30  +                // there is subgroup(s)
           31  +                if (aGroupsPos !== null) {
           32  +                    // aGroupsPos is defined
           33  +                    for (let i = 1; i <= m.length-1; i++) {
           34  +                        codePos = aGroupsPos[i-1];
           35  +                        if (typeof codePos === "number") {
           36  +                            // position as a number
           37  +                            m.start.push(m.index + codePos);
           38  +                            m.end.push(m.index + codePos + m[i].length);
           39  +                        } else if (codePos === "$") {
           40  +                            // at the end of the pattern
           41  +                            m.start.push(this.lastIndex - m[i].length);
           42  +                            m.end.push(this.lastIndex);
           43  +                        } else if (codePos === "w") {
           44  +                            // word in the middle of the pattern
           45  +                            iPos = m[0].search("[ ’,()«»“”]"+m[i]+"[ ,’()«»“”]") + 1 + m.index
           46  +                            m.start.push(iPos);
           47  +                            m.end.push(iPos + m[i].length)
           48  +                        } else if (codePos === "*") {
           49  +                            // anywhere
           50  +                            iPos = m[0].indexOf(m[i]) + m.index;
           51  +                            m.start.push(iPos);
           52  +                            m.end.push(iPos + m[i].length)
           53  +                        } else if (codePos === "**") {
           54  +                            // anywhere after previous group
           55  +                            iPos = m[0].indexOf(m[i], m.end[i-1]-m.index) + m.index;
           56  +                            m.start.push(iPos);
           57  +                            m.end.push(iPos + m[i].length)
           58  +                        } else if (codePos.startsWith(">")) {
           59  +                            // >x:_
           60  +                            // todo: look in substring x
           61  +                            iPos = m[0].indexOf(m[i]) + m.index;
           62  +                            m.start.push(iPos);
           63  +                            m.end.push(iPos + m[i].length);
           64  +                        } else {
           65  +                            console.error("# Error: unknown positioning code in regex [" + this.source + "], for group[" + i.toString() +"], code: [" + codePos + "]");
           66  +                        }
           67  +                    }
           68  +                } else {
           69  +                    // no aGroupsPos
           70  +                    for (let subm of m.slice(1)) {
           71  +                        iPos = m[0].indexOf(subm) + m.index;
    50     72                           m.start.push(iPos);
    51         -                        m.end.push(iPos + m[i].length)
    52         -                    } else if (codePos === "**") {
    53         -                        // anywhere after previous group
    54         -                        iPos = m[0].indexOf(m[i], m.end[i-1]-m.index) + m.index;
    55         -                        m.start.push(iPos);
    56         -                        m.end.push(iPos + m[i].length)
    57         -                    } else if (codePos.startsWith(">")) {
    58         -                        // >x:_
    59         -                        // todo: look in substring x
    60         -                        iPos = m[0].indexOf(m[i]) + m.index;
    61         -                        m.start.push(iPos);
    62         -                        m.end.push(iPos + m[i].length);
    63         -                    } else {
    64         -                        console.error("# Error: unknown positioning code in regex [" + this.source + "], for group[" + i.toString() +"], code: [" + codePos + "]");
           73  +                        m.end.push(iPos + subm.length);
    65     74                       }
    66     75                   }
    67         -            } else {
    68         -                // no aGroupsPos
    69         -                for (let subm of m.slice(1)) {
    70         -                    iPos = m[0].indexOf(subm) + m.index;
    71         -                    m.start.push(iPos);
    72         -                    m.end.push(iPos + subm.length);
    73         -                }
    74     76               }
    75     77           }
           78  +        catch (e) {
           79  +            console.error(e);
           80  +        }
    76     81           return m;
    77     82       }
    78     83   
    79     84       RegExp.prototype.grammalecte = true;
    80     85   }