add es6 template string highlighting to javascript mode

This commit is contained in:
nightwing 2014-09-02 13:42:59 +04:00
commit 30f7f8a3f2
2 changed files with 37 additions and 0 deletions

View file

@ -117,6 +117,7 @@ function BracketMatch() {
typeRe = new RegExp(
"(\\.?" +
token.type.replace(".", "\\.").replace("rparen", ".paren")
.replace(/\b(?:end|start|begin)\b/, "")
+ ")+"
);
}
@ -173,6 +174,7 @@ function BracketMatch() {
typeRe = new RegExp(
"(\\.?" +
token.type.replace(".", "\\.").replace("lparen", ".paren")
.replace(/\b(?:end|start|begin)\b/, "")
+ ")+"
);
}

View file

@ -193,6 +193,39 @@ var JavaScriptHighlightRules = function() {
token : "punctuation.operator",
regex : /\?|\:|\,|\;|\./,
next : "start"
}, {
regex: "[{}]", onMatch: function(val, state, stack) {
console.log(val, state, stack)
this.next = "";
if (val == "{" && stack.length) {
stack.unshift("start", state);
return "paren";
}
if (val == "}" && stack.length) {
stack.shift();
this.next = stack.shift();
if (this.next.indexOf("string") != -1)
return "paren.quasi.end";
}
return "paren";
}
}, {
token : "string.quasi.start",
regex : /`/,
push : [{
token : "constant.language.escape",
regex : escapedRe
}, {
token : "paren.quasi.start",
regex : /\${/,
push : "start"
}, {
token : "string.quasi.end",
regex : /`/,
next : "pop"
}, {
defaultToken: "string.quasi"
}]
}, {
token : "paren.lparen",
regex : /[\[({]/,
@ -357,6 +390,8 @@ var JavaScriptHighlightRules = function() {
this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("no_regex") ]);
this.normalizeRules();
};
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);