update tests

This commit is contained in:
nightwing 2014-09-02 15:12:15 +04:00
commit 3d6b93b946
4 changed files with 47 additions and 47 deletions

View file

@ -379,7 +379,7 @@
["constant.numeric","1."],
["text","00"],
["identifier","E"],
["text","^"],
["keyword.operator","^"],
["constant.numeric","1"],
["punctuation.operator",","],
["text"," "],

View file

@ -35,7 +35,7 @@ var oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var JavaScriptHighlightRules = function() {
var JavaScriptHighlightRules = function(options) {
// see: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects
var keywordMapper = this.createKeywordMapper({
"variable.language":
@ -187,45 +187,12 @@ var JavaScriptHighlightRules = function() {
regex : identifierRe
}, {
token : "keyword.operator",
regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
regex : /--|\+\+|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|[!$%&*+\-~\/^]=?/,
next : "start"
}, {
token : "punctuation.operator",
regex : /\?|\:|\,|\;|\./,
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 : /[\[({]/,
@ -233,10 +200,6 @@ var JavaScriptHighlightRules = function() {
}, {
token : "paren.rparen",
regex : /[\])}]/
}, {
token : "keyword.operator",
regex : /\/=?/,
next : "start"
}, {
token: "comment",
regex: /^#!.*$/
@ -387,7 +350,45 @@ var JavaScriptHighlightRules = function() {
}
]
};
if (!options || !options.noES6) {
this.$rules.no_regex.unshift({
regex: "[{}]", onMatch: function(val, state, stack) {
this.next = val == "{" ? this.nextState : "";
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 val == "{" ? "paren.lparen" : "paren.rparen";
},
nextState: "start"
}, {
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"
}]
});
}
this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("no_regex") ]);

View file

@ -36,7 +36,7 @@ var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScrip
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var SJSHighlightRules = function() {
var parent = new JavaScriptHighlightRules();
var parent = new JavaScriptHighlightRules({noES6: true});
var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
"u[0-9a-fA-F]{4}|" + // unicode
"[0-2][0-7]{0,2}|" + // oct
@ -177,10 +177,10 @@ var SJSHighlightRules = function() {
// for use within interpreted contexts
// without interfering with context nesting
var embeddableRules = [];
for (var i=0; i<this.$rules.no_regex.length; i++) {
for (var i=0; i < this.$rules.no_regex.length; i++) {
var rule = this.$rules.no_regex[i];
var token = String(rule.token);
if(token.indexOf('paren') == -1 && (!rule.next || rule.next.isContextAware)) {
if (token.indexOf('paren') == -1 && (!rule.next || rule.next.isContextAware)) {
embeddableRules.push(rule);
}
};

View file

@ -60,7 +60,7 @@ var TextHighlightRules = function() {
var state = rules[key];
for (var i = 0; i < state.length; i++) {
var rule = state[i];
if (rule.next) {
if (rule.next || rule.onMatch) {
if (typeof rule.next != "string") {
if (rule.nextState && rule.nextState.indexOf(prefix) !== 0)
rule.nextState = prefix + rule.nextState;
@ -68,7 +68,6 @@ var TextHighlightRules = function() {
if (rule.next.indexOf(prefix) !== 0)
rule.next = prefix + rule.next;
}
}
}
this.$rules[prefix + key] = state;