add ability to Tokenizer to use "i" flag for caseInsensitve languages
This commit is contained in:
parent
ba334cae71
commit
c4bdcd8bad
5 changed files with 24 additions and 145 deletions
|
|
@ -46,7 +46,7 @@ var WorkerClient = require("../worker/worker_client").WorkerClient;
|
||||||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules(), "i");
|
||||||
this.$outdent = new MatchingBraceOutdent();
|
this.$outdent = new MatchingBraceOutdent();
|
||||||
this.foldingRules = new CStyleFoldMode();
|
this.foldingRules = new CStyleFoldMode();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -108,20 +108,6 @@ var CssHighlightRules = function() {
|
||||||
|
|
||||||
var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
|
var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
|
||||||
|
|
||||||
function ic(str) {
|
|
||||||
var re = [];
|
|
||||||
var chars = str.split("");
|
|
||||||
for (var i=0; i<chars.length; i++) {
|
|
||||||
re.push(
|
|
||||||
"[",
|
|
||||||
chars[i].toLowerCase(),
|
|
||||||
chars[i].toUpperCase(),
|
|
||||||
"]"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return re.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
var base_ruleset = [
|
var base_ruleset = [
|
||||||
{
|
{
|
||||||
token : "comment", // multi line comment
|
token : "comment", // multi line comment
|
||||||
|
|
@ -136,61 +122,13 @@ var CssHighlightRules = function() {
|
||||||
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric",
|
token : "constant.numeric",
|
||||||
regex : numRe + ic("em")
|
regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("ex")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("px")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("cm")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("mm")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("in")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("pt")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("pc")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("deg")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("rad")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("grad")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("ms")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("s")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("hz")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("khz")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + "%"
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe
|
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric", // hex6 color
|
token : "constant.numeric", // hex6 color
|
||||||
regex : "#[a-fA-F0-9]{6}"
|
regex : "#[a-f0-9]{6}"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric", // hex3 color
|
token : "constant.numeric", // hex3 color
|
||||||
regex : "#[a-fA-F0-9]{3}"
|
regex : "#[a-f0-9]{3}"
|
||||||
}, {
|
}, {
|
||||||
token : function(value) {
|
token : function(value) {
|
||||||
if (properties.hasOwnProperty(value.toLowerCase())) {
|
if (properties.hasOwnProperty(value.toLowerCase())) {
|
||||||
|
|
@ -270,16 +208,16 @@ var CssHighlightRules = function() {
|
||||||
next: "media"
|
next: "media"
|
||||||
},{
|
},{
|
||||||
token: "keyword",
|
token: "keyword",
|
||||||
regex: "#[a-zA-Z0-9-_]+"
|
regex: "#[a-z0-9-_]+"
|
||||||
},{
|
},{
|
||||||
token: "variable",
|
token: "variable",
|
||||||
regex: "\\.[a-zA-Z0-9-_]+"
|
regex: "\\.[a-z0-9-_]+"
|
||||||
},{
|
},{
|
||||||
token: "string",
|
token: "string",
|
||||||
regex: ":[a-zA-Z0-9-_]+"
|
regex: ":[a-z0-9-_]+"
|
||||||
},{
|
},{
|
||||||
token: "constant",
|
token: "constant",
|
||||||
regex: "[a-zA-Z0-9-_]+"
|
regex: "[a-z0-9-_]+"
|
||||||
}],
|
}],
|
||||||
|
|
||||||
"media" : [ {
|
"media" : [ {
|
||||||
|
|
@ -297,16 +235,16 @@ var CssHighlightRules = function() {
|
||||||
next: "start"
|
next: "start"
|
||||||
},{
|
},{
|
||||||
token: "keyword",
|
token: "keyword",
|
||||||
regex: "#[a-zA-Z0-9-_]+"
|
regex: "#[a-z0-9-_]+"
|
||||||
},{
|
},{
|
||||||
token: "variable",
|
token: "variable",
|
||||||
regex: "\\.[a-zA-Z0-9-_]+"
|
regex: "\\.[a-z0-9-_]+"
|
||||||
},{
|
},{
|
||||||
token: "string",
|
token: "string",
|
||||||
regex: ":[a-zA-Z0-9-_]+"
|
regex: ":[a-z0-9-_]+"
|
||||||
},{
|
},{
|
||||||
token: "constant",
|
token: "constant",
|
||||||
regex: "[a-zA-Z0-9-_]+"
|
regex: "[a-z0-9-_]+"
|
||||||
}],
|
}],
|
||||||
|
|
||||||
"comment" : comment,
|
"comment" : comment,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd
|
||||||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new ScssHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new ScssHighlightRules().getRules(), "i");
|
||||||
this.$outdent = new MatchingBraceOutdent();
|
this.$outdent = new MatchingBraceOutdent();
|
||||||
this.foldingRules = new CStyleFoldMode();
|
this.foldingRules = new CStyleFoldMode();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -171,21 +171,6 @@ var ScssHighlightRules = function() {
|
||||||
|
|
||||||
var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
|
var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
|
||||||
|
|
||||||
function ic(str) {
|
|
||||||
var re = [];
|
|
||||||
var chars = str.split("");
|
|
||||||
for (var i=0; i<chars.length; i++) {
|
|
||||||
re.push(
|
|
||||||
"[",
|
|
||||||
chars[i].toLowerCase(),
|
|
||||||
chars[i].toUpperCase(),
|
|
||||||
"]"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return re.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
|
|
@ -218,58 +203,13 @@ var ScssHighlightRules = function() {
|
||||||
next : "qstring"
|
next : "qstring"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric",
|
token : "constant.numeric",
|
||||||
regex : numRe + ic("em")
|
regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("ex")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("px")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("cm")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("mm")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("in")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("pt")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("pc")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("deg")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("rad")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("grad")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("ms")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("s")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("hz")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + ic("khz")
|
|
||||||
}, {
|
|
||||||
token : "constant.numeric",
|
|
||||||
regex : numRe + "%"
|
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric", // hex6 color
|
token : "constant.numeric", // hex6 color
|
||||||
regex : "#[a-fA-F0-9]{6}"
|
regex : "#[a-f0-9]{6}"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric", // hex3 color
|
token : "constant.numeric", // hex3 color
|
||||||
regex : "#[a-fA-F0-9]{3}"
|
regex : "#[a-f0-9]{3}"
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric",
|
token : "constant.numeric",
|
||||||
regex : numRe
|
regex : numRe
|
||||||
|
|
@ -290,22 +230,22 @@ var ScssHighlightRules = function() {
|
||||||
else
|
else
|
||||||
return "text";
|
return "text";
|
||||||
},
|
},
|
||||||
regex : "\\-?[@a-zA-Z_][@a-zA-Z0-9_\\-]*"
|
regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
|
||||||
}, {
|
}, {
|
||||||
token : "variable",
|
token : "variable",
|
||||||
regex : "[a-zA-Z_\\-$][a-zA-Z0-9_\\-$]*\\b"
|
regex : "[a-z_\\-$][a-z0-9_\\-$]*\\b"
|
||||||
}, {
|
}, {
|
||||||
token: "variable.language",
|
token: "variable.language",
|
||||||
regex: "#[a-zA-Z0-9-_]+"
|
regex: "#[a-z0-9-_]+"
|
||||||
}, {
|
}, {
|
||||||
token: "variable.language",
|
token: "variable.language",
|
||||||
regex: "\\.[a-zA-Z0-9-_]+"
|
regex: "\\.[a-z0-9-_]+"
|
||||||
}, {
|
}, {
|
||||||
token: "variable.language",
|
token: "variable.language",
|
||||||
regex: ":[a-zA-Z0-9-_]+"
|
regex: ":[a-z0-9-_]+"
|
||||||
}, {
|
}, {
|
||||||
token: "constant",
|
token: "constant",
|
||||||
regex: "[a-zA-Z0-9-_]+"
|
regex: "[a-z0-9-_]+"
|
||||||
}, {
|
}, {
|
||||||
token : "keyword.operator",
|
token : "keyword.operator",
|
||||||
regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
|
regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ var Tokenizer = function(rules) {
|
||||||
|
|
||||||
this.regExps = {};
|
this.regExps = {};
|
||||||
this.matchMappings = {};
|
this.matchMappings = {};
|
||||||
|
var flag = flag ? "g" + flag : "g";
|
||||||
for ( var key in this.rules) {
|
for ( var key in this.rules) {
|
||||||
var rule = this.rules[key];
|
var rule = this.rules[key];
|
||||||
var state = rule;
|
var state = rule;
|
||||||
|
|
@ -68,7 +69,7 @@ var Tokenizer = function(rules) {
|
||||||
ruleRegExps.push(adjustedregex);
|
ruleRegExps.push(adjustedregex);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", "g");
|
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", flag);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue