fix js_highlight_rules
This commit is contained in:
parent
ce891c2c2e
commit
e8a5c0dc2f
4 changed files with 107 additions and 61 deletions
|
|
@ -124,11 +124,11 @@ var JavaScriptHighlightRules = function() {
|
||||||
next : "comment"
|
next : "comment"
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : "'",
|
regex : "'(?=.)",
|
||||||
next : "qstring"
|
next : "qstring"
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : '"',
|
regex : '"(?=.)',
|
||||||
next : "qqstring"
|
next : "qqstring"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric", // hex
|
token : "constant.numeric", // hex
|
||||||
|
|
@ -148,11 +148,10 @@ var JavaScriptHighlightRules = function() {
|
||||||
"text",
|
"text",
|
||||||
"storage.type",
|
"storage.type",
|
||||||
"text",
|
"text",
|
||||||
"paren.lparen",
|
"paren.lparen"
|
||||||
"variable.parameter",
|
|
||||||
"paren.rparen"
|
|
||||||
],
|
],
|
||||||
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))"
|
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
|
||||||
|
next: "function_arguments"
|
||||||
}, { // match stuff like: Sound.prototype.play = myfunc
|
}, { // match stuff like: Sound.prototype.play = myfunc
|
||||||
token : [
|
token : [
|
||||||
"storage.type",
|
"storage.type",
|
||||||
|
|
@ -164,7 +163,8 @@ var JavaScriptHighlightRules = function() {
|
||||||
"keyword.operator",
|
"keyword.operator",
|
||||||
"text"
|
"text"
|
||||||
],
|
],
|
||||||
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)"
|
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)",
|
||||||
|
next: "function_arguments"
|
||||||
}, { // match stuff like: Sound.play = function() { }
|
}, { // match stuff like: Sound.play = function() { }
|
||||||
token : [
|
token : [
|
||||||
"storage.type",
|
"storage.type",
|
||||||
|
|
@ -175,11 +175,10 @@ var JavaScriptHighlightRules = function() {
|
||||||
"text",
|
"text",
|
||||||
"storage.type",
|
"storage.type",
|
||||||
"text",
|
"text",
|
||||||
"paren.lparen",
|
"paren.lparen"
|
||||||
"variable.parameter",
|
|
||||||
"paren.rparen"
|
|
||||||
],
|
],
|
||||||
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))"
|
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
|
||||||
|
next: "function_arguments"
|
||||||
}, { // match stuff like: play = function() { }
|
}, { // match stuff like: play = function() { }
|
||||||
token : [
|
token : [
|
||||||
"entity.name.function",
|
"entity.name.function",
|
||||||
|
|
@ -188,22 +187,20 @@ var JavaScriptHighlightRules = function() {
|
||||||
"text",
|
"text",
|
||||||
"storage.type",
|
"storage.type",
|
||||||
"text",
|
"text",
|
||||||
"paren.lparen",
|
"paren.lparen"
|
||||||
"variable.parameter",
|
|
||||||
"paren.rparen"
|
|
||||||
],
|
],
|
||||||
regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()(.*?)(\\))"
|
regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
|
||||||
|
next: "function_arguments"
|
||||||
}, { // match regular function like: function myFunc(arg) { }
|
}, { // match regular function like: function myFunc(arg) { }
|
||||||
token : [
|
token : [
|
||||||
"storage.type",
|
"storage.type",
|
||||||
"text",
|
"text",
|
||||||
"entity.name.function",
|
"entity.name.function",
|
||||||
"text",
|
"text",
|
||||||
"paren.lparen",
|
"paren.lparen"
|
||||||
"variable.parameter",
|
|
||||||
"paren.rparen"
|
|
||||||
],
|
],
|
||||||
regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()(.*?)(\\))"
|
regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
|
||||||
|
next: "function_arguments"
|
||||||
}, { // match stuff like: foobar: function() { }
|
}, { // match stuff like: foobar: function() { }
|
||||||
token : [
|
token : [
|
||||||
"entity.name.function",
|
"entity.name.function",
|
||||||
|
|
@ -212,22 +209,20 @@ var JavaScriptHighlightRules = function() {
|
||||||
"text",
|
"text",
|
||||||
"storage.type",
|
"storage.type",
|
||||||
"text",
|
"text",
|
||||||
"paren.lparen",
|
"paren.lparen"
|
||||||
"variable.parameter",
|
|
||||||
"paren.rparen"
|
|
||||||
],
|
],
|
||||||
regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()(.*?)(\\))"
|
regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
|
||||||
|
next: "function_arguments"
|
||||||
}, { // Attempt to match : function() { } (this is for issues with 'foo': function() { })
|
}, { // Attempt to match : function() { } (this is for issues with 'foo': function() { })
|
||||||
token : [
|
token : [
|
||||||
"text",
|
"text",
|
||||||
"text",
|
"text",
|
||||||
"storage.type",
|
"storage.type",
|
||||||
"text",
|
"text",
|
||||||
"paren.lparen",
|
"paren.lparen"
|
||||||
"variable.parameter",
|
|
||||||
"paren.rparen"
|
|
||||||
],
|
],
|
||||||
regex : "(:)(\\s*)(function)?(\\s*)(\\()([^)]*)(\\))"
|
regex : "(:)(\\s*)(function)(\\s*)(\\()",
|
||||||
|
next: "function_arguments"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.language.boolean",
|
token : "constant.language.boolean",
|
||||||
regex : /(?:true|false)\b/
|
regex : /(?:true|false)\b/
|
||||||
|
|
@ -324,10 +319,9 @@ var JavaScriptHighlightRules = function() {
|
||||||
"regex": [
|
"regex": [
|
||||||
{
|
{
|
||||||
token: "regexp.keyword.operator",
|
token: "regexp.keyword.operator",
|
||||||
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",
|
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
|
||||||
next: "regex"
|
|
||||||
}, {
|
}, {
|
||||||
// flag
|
// flag
|
||||||
token: "string.regexp",
|
token: "string.regexp",
|
||||||
regex: "/\\w*",
|
regex: "/\\w*",
|
||||||
next: "start",
|
next: "start",
|
||||||
|
|
@ -335,7 +329,6 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token: "string.regexp",
|
token: "string.regexp",
|
||||||
regex: "[^\\\\/\\[]+",
|
regex: "[^\\\\/\\[]+",
|
||||||
next: "regex",
|
|
||||||
merge: true
|
merge: true
|
||||||
}, {
|
}, {
|
||||||
token: "string.regexp.charachterclass",
|
token: "string.regexp.charachterclass",
|
||||||
|
|
@ -351,8 +344,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
"regex_character_class": [
|
"regex_character_class": [
|
||||||
{
|
{
|
||||||
token: "regexp.keyword.operator",
|
token: "regexp.keyword.operator",
|
||||||
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",
|
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
|
||||||
next: "regex_character_class"
|
|
||||||
}, {
|
}, {
|
||||||
token: "string.regexp.charachterclass",
|
token: "string.regexp.charachterclass",
|
||||||
regex: "]",
|
regex: "]",
|
||||||
|
|
@ -361,7 +353,24 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token: "string.regexp.charachterclass",
|
token: "string.regexp.charachterclass",
|
||||||
regex: "[^\\\\\\]]+",
|
regex: "[^\\\\\\]]+",
|
||||||
next: "regex_character_class",
|
merge: true
|
||||||
|
}, {
|
||||||
|
token: "empty",
|
||||||
|
regex: "",
|
||||||
|
next: "start"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"function_arguments": [
|
||||||
|
{
|
||||||
|
token: "variable.parameter",
|
||||||
|
regex: identifierRe,
|
||||||
|
}, {
|
||||||
|
token: "punctuation.operator",
|
||||||
|
regex: "[, ]+",
|
||||||
|
merge: true
|
||||||
|
}, {
|
||||||
|
token: "punctuation.operator",
|
||||||
|
regex: "$",
|
||||||
merge: true
|
merge: true
|
||||||
}, {
|
}, {
|
||||||
token: "empty",
|
token: "empty",
|
||||||
|
|
@ -399,11 +408,18 @@ var JavaScriptHighlightRules = function() {
|
||||||
regex : escapedRe
|
regex : escapedRe
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : '[^"\\\\]+'
|
regex : '[^"\\\\]+',
|
||||||
|
merge : true
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : '"',
|
regex : "\\\\$",
|
||||||
next : "start"
|
next : "qqstring",
|
||||||
|
merge : true
|
||||||
|
}, {
|
||||||
|
token : "string",
|
||||||
|
regex : '"|$',
|
||||||
|
next : "start",
|
||||||
|
merge : true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"qstring" : [
|
"qstring" : [
|
||||||
|
|
@ -412,11 +428,18 @@ var JavaScriptHighlightRules = function() {
|
||||||
regex : escapedRe
|
regex : escapedRe
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : "[^'\\\\]+"
|
regex : "[^'\\\\]+",
|
||||||
|
merge : true
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : "'",
|
regex : "\\\\$",
|
||||||
next : "start"
|
next : "qstring",
|
||||||
|
merge : true
|
||||||
|
}, {
|
||||||
|
token : "string",
|
||||||
|
regex : "'|$",
|
||||||
|
next : "start",
|
||||||
|
merge : true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -71,10 +71,10 @@ module.exports = {
|
||||||
|
|
||||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||||
|
|
||||||
assert.equal(27, tokens.length);
|
assert.equal(23, tokens.length);
|
||||||
assert.equal("support.function", tokens[2].type); // charCodeAt
|
assert.equal("support.function", tokens[2].type); // charCodeAt
|
||||||
assert.equal("support.function.dom", tokens[10].type); // getElementById
|
assert.equal("support.function.dom", tokens[10].type); // getElementById
|
||||||
assert.equal("support.function.firebug", tokens[20].type); // log
|
assert.equal("support.function.firebug", tokens[18].type); // log
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: tokenize doc comment" : function() {
|
"test: tokenize doc comment" : function() {
|
||||||
|
|
@ -181,14 +181,40 @@ module.exports = {
|
||||||
var line = "console.log('Meh\\nNeh');"
|
var line = "console.log('Meh\\nNeh');"
|
||||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||||
|
|
||||||
assert.equal(11, tokens.length);
|
assert.equal(9, tokens.length);
|
||||||
assert.equal("constant.language.escape", tokens[6].type);
|
assert.equal("constant.language.escape", tokens[5].type);
|
||||||
|
|
||||||
line = "console.log('\\u1232Feh');";
|
line = "console.log('\\u1232Feh');";
|
||||||
tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||||
|
|
||||||
assert.equal(10, tokens.length);
|
assert.equal(9, tokens.length);
|
||||||
assert.equal("constant.language.escape", tokens[5].type);
|
assert.equal("constant.language.escape", tokens[5].type);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test multiline strings": function() {
|
||||||
|
var line = "console.log('Meh\\"
|
||||||
|
var data = this.tokenizer.getLineTokens(line, "start")
|
||||||
|
|
||||||
|
assert.equal(5, data.tokens.length);
|
||||||
|
assert.equal(data.state, "qstring");
|
||||||
|
|
||||||
|
line = "console.log('Meh\\ "
|
||||||
|
data = this.tokenizer.getLineTokens(line, "start")
|
||||||
|
|
||||||
|
assert.equal(6, data.tokens.length);
|
||||||
|
assert.equal(data.state, "start");
|
||||||
|
|
||||||
|
line = 'console.log("\\'
|
||||||
|
data = this.tokenizer.getLineTokens(line, "start")
|
||||||
|
|
||||||
|
assert.equal(5, data.tokens.length);
|
||||||
|
assert.equal(data.state, "qqstring");
|
||||||
|
|
||||||
|
line = 'a="'
|
||||||
|
data = this.tokenizer.getLineTokens(line, "start")
|
||||||
|
|
||||||
|
assert.equal(3, data.tokens.length);
|
||||||
|
assert.equal(data.state, "start");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,6 @@ var TextHighlightRules = function() {
|
||||||
var rule = state[i];
|
var rule = state[i];
|
||||||
if (rule.next) {
|
if (rule.next) {
|
||||||
rule.next = prefix + rule.next;
|
rule.next = prefix + rule.next;
|
||||||
} else {
|
|
||||||
rule.next = prefix + key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.$rules[prefix + key] = state;
|
this.$rules[prefix + key] = state;
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,8 @@ var Tokenizer = function(rules, flag) {
|
||||||
else
|
else
|
||||||
type = rule.token;
|
type = rule.token;
|
||||||
|
|
||||||
var next = rule.next;
|
if (rule.next) {
|
||||||
if (next && next !== currentState) {
|
currentState = rule.next;
|
||||||
currentState = next;
|
|
||||||
state = this.rules[currentState];
|
state = this.rules[currentState];
|
||||||
mapping = this.matchMappings[currentState];
|
mapping = this.matchMappings[currentState];
|
||||||
lastIndex = re.lastIndex;
|
lastIndex = re.lastIndex;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue