fix tokenizer on ie8
changes $arrayTokens to use exec instead of split 1 it works on ie8 2 it is faster on chrome http://jsperf.com/capturing-split-vs-exec unfortunately exec is slow on firefox but ff regexes are a bit rusty atm (v21), and whole tokenizer is slow on it anyway.
This commit is contained in:
parent
118c80ce89
commit
77b5ae1062
6 changed files with 51 additions and 13 deletions
|
|
@ -310,7 +310,7 @@ var actions = exports.actions = {
|
|||
fn: function(editor, range, count, param) {
|
||||
editor.modifyNumber(count || 1);
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
var inputBuffer = exports.inputBuffer = {
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ define(function(require, exports, module) {
|
|||
token : "string", regex : "'''", next : [
|
||||
{token : "string", regex : "'''", next : "start"},
|
||||
{token : "constant.language.escape", regex : stringEscape},
|
||||
{defaultToken: "string"},
|
||||
{defaultToken: "string"}
|
||||
]
|
||||
}, {
|
||||
stateName: "qqdoc",
|
||||
|
|
@ -115,21 +115,21 @@ define(function(require, exports, module) {
|
|||
token : "string", regex : "'", next : [
|
||||
{token : "string", regex : "'", next : "start"},
|
||||
{token : "constant.language.escape", regex : stringEscape},
|
||||
{defaultToken: "string"},
|
||||
{defaultToken: "string"}
|
||||
]
|
||||
}, {
|
||||
stateName: "qqstring",
|
||||
token : "string.start", regex : '"', next : [
|
||||
{token : "string.end", regex : '"', next : "start"},
|
||||
{token : "constant.language.escape", regex : stringEscape},
|
||||
{defaultToken: "string"},
|
||||
{defaultToken: "string"}
|
||||
]
|
||||
}, {
|
||||
stateName: "js",
|
||||
token : "string", regex : "`", next : [
|
||||
{token : "string", regex : "`", next : "start"},
|
||||
{token : "constant.language.escape", regex : stringEscape},
|
||||
{defaultToken: "string"},
|
||||
{defaultToken: "string"}
|
||||
]
|
||||
}, {
|
||||
token : "string.regex",
|
||||
|
|
|
|||
|
|
@ -46,19 +46,19 @@ var SnippetHighlightRules = function() {
|
|||
{regex: /\[/, token: "regex.start", next: "charClass"},
|
||||
{regex: "/", token: "string.regex", next: "format"},
|
||||
//{"default": "string.regex"},
|
||||
{"token": "string.regex", regex:"."},
|
||||
{"token": "string.regex", regex:"."}
|
||||
],
|
||||
charClass : [
|
||||
{regex: "\\.", token: "escape"},
|
||||
{regex: "\\]", token: "regex.end", next: "regexp"},
|
||||
{"token": "string.regex", regex:"."},
|
||||
{"token": "string.regex", regex:"."}
|
||||
],
|
||||
"format" : [
|
||||
{regex: /\\[ulULE]/, token: "keyword"},
|
||||
{regex: /\$\d+/, token: "variable"},
|
||||
{regex: "/[gim]*:?", token: "string.regex", next: "start"},
|
||||
// {"default": "string"},
|
||||
{"token": "string", regex:"."},
|
||||
{"token": "string", regex:"."}
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -451,7 +451,7 @@ module.exports = {
|
|||
assert.position(ranges[1].end, 0, 11);
|
||||
assert.position(ranges[0].start, 0, 0);
|
||||
assert.position(ranges[0].end, 0, 3);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -111,12 +111,12 @@ var Tokenizer = function(rules) {
|
|||
this.$arrayTokens = function(str) {
|
||||
if (!str)
|
||||
return [];
|
||||
var values = str.split(this.splitRegex)
|
||||
var values = this.splitRegex.exec(str);
|
||||
var tokens = [];
|
||||
var types = this.tokenArray;
|
||||
if (types.length != values.length - 2) {
|
||||
if (types.length != values.length - 1) {
|
||||
if (window.console)
|
||||
console.error(types.length , values.length - 2, str, this.splitRegex);
|
||||
console.error(types , values, str, this.splitRegex, this);
|
||||
return [{type: "error.invalid", value: str}];
|
||||
}
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
|
|
@ -140,7 +140,7 @@ var Tokenizer = function(rules) {
|
|||
|
||||
this.createSplitterRegexp = function(src, flag) {
|
||||
src = src.replace(/\(\?=([^()]|\\.|\(([^()]|\\.)*?\))*\)(?=\)*$)/, "");
|
||||
return new RegExp(src, flag);
|
||||
return new RegExp(src, (flag||"").replace("g", ""));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue