remove flag parameter from tokenizer

This commit is contained in:
nightwing 2013-02-07 23:13:11 +04:00
commit 382eb6ab55
12 changed files with 30 additions and 19 deletions

View file

@ -39,7 +39,7 @@ var TextMode = require("./text").Mode;
var oop = require("../lib/oop"); var oop = require("../lib/oop");
function Mode() { function Mode() {
this.$tokenizer = new Tokenizer(new Rules().getRules(), "i"); this.$tokenizer = new Tokenizer(new Rules().getRules());
this.foldingRules = new FoldMode(); this.foldingRules = new FoldMode();
} }

View file

@ -113,17 +113,18 @@ var AbapHighlightRules = function() {
{token : "variable.parameter", regex : /sy|pa?\d\d\d\d\|t\d\d\d\.|innnn/}, {token : "variable.parameter", regex : /sy|pa?\d\d\d\d\|t\d\d\d\.|innnn/},
{token : "keyword", regex : compoundKeywords}, {token : "keyword", regex : compoundKeywords},
{token : "variable.parameter", regex : /\w+-\w+(?:-\w+)*/}, {token : "variable.parameter", regex : /\w+-\w+(?:-\w+)*/},
{token : keywordMapper, regex : "\\b\\w+\\b"}, {token : keywordMapper, regex : "\\b\\w+\\b"},
{caseInsensitive: true}
], ],
"qstring" : [ "qstring" : [
{token : "constant.language.escape", regex : "''"}, {token : "constant.language.escape", regex : "''"},
{token : "string", regex : "'", next : "start"}, {token : "string", regex : "'", next : "start"},
{token : "string", regex : ".|\w+"} {defaultToken : "string"}
], ],
"string" : [ "string" : [
{token : "constant.language.escape", regex : "``"}, {token : "constant.language.escape", regex : "``"},
{token : "string", regex : "`", next : "start"}, {token : "string", regex : "`", next : "start"},
{token : "string", regex : ".|\w+"} {defaultToken : "string"}
] ]
} }
}; };

View file

@ -39,7 +39,7 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd
var C9StyleFoldMode = require("./folding/c9search").FoldMode; var C9StyleFoldMode = require("./folding/c9search").FoldMode;
var Mode = function() { var Mode = function() {
this.$tokenizer = new Tokenizer(new C9SearchHighlightRules().getRules(), "i"); this.$tokenizer = new Tokenizer(new C9SearchHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new C9StyleFoldMode(); this.foldingRules = new C9StyleFoldMode();
}; };

View file

@ -41,7 +41,7 @@ var CssBehaviour = require("./behaviour/css").CssBehaviour;
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(), "i"); this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CssBehaviour(); this.$behaviour = new CssBehaviour();
this.foldingRules = new CStyleFoldMode(); this.foldingRules = new CStyleFoldMode();

View file

@ -92,6 +92,8 @@ var CssHighlightRules = function() {
}, { }, {
token : keywordMapper, token : keywordMapper,
regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
}, {
caseInsensitive: true
} }
]; ];
@ -160,6 +162,8 @@ var CssHighlightRules = function() {
},{ },{
token: "constant", token: "constant",
regex: "[a-z0-9-_]+" regex: "[a-z0-9-_]+"
},{
caseInsensitive: true
}], }],
"media" : [ { "media" : [ {
@ -186,6 +190,8 @@ var CssHighlightRules = function() {
},{ },{
token: "constant", token: "constant",
regex: "[a-z0-9-_]+" regex: "[a-z0-9-_]+"
},{
caseInsensitive: true
}], }],
"comment" : comment, "comment" : comment,

View file

@ -38,8 +38,8 @@ var HighlightRules = require("./diff_highlight_rules").DiffHighlightRules;
var FoldMode = require("./folding/diff").FoldMode; var FoldMode = require("./folding/diff").FoldMode;
var Mode = function() { var Mode = function() {
this.$tokenizer = new Tokenizer(new HighlightRules().getRules(), "i"); this.$tokenizer = new Tokenizer(new HighlightRules().getRules());
this.foldingRules = new FoldMode(["diff", "index", "\\+{3}", "@@|\\*{5}"], "i"); this.foldingRules = new FoldMode(["diff", "index", "\\+{3}", "@@|\\*{5}"], "i");
}; };
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);

View file

@ -92,7 +92,8 @@ var DiffHighlightRules = function() {
regex: "\\s*$", regex: "\\s*$",
token: "invalid" token: "invalid"
}, { }, {
defaultToken: "invisible" defaultToken: "invisible",
caseInsensitive: true
} }
] ]
}; };

View file

@ -40,7 +40,7 @@ var CssBehaviour = require("./behaviour/css").CssBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode; var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() { var Mode = function() {
this.$tokenizer = new Tokenizer(new LessHighlightRules().getRules(), "i"); this.$tokenizer = new Tokenizer(new LessHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CssBehaviour(); this.$behaviour = new CssBehaviour();
this.foldingRules = new CStyleFoldMode(); this.foldingRules = new CStyleFoldMode();

View file

@ -247,6 +247,8 @@ var LessHighlightRules = function() {
}, { }, {
token : "text", token : "text",
regex : "\\s+" regex : "\\s+"
}, {
caseInsensitive: true
} }
], ],
"comment" : [ "comment" : [

View file

@ -40,7 +40,7 @@ var CssBehaviour = require("./behaviour/css").CssBehaviour;
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(), "i"); this.$tokenizer = new Tokenizer(new ScssHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CssBehaviour(); this.$behaviour = new CssBehaviour();
this.foldingRules = new CStyleFoldMode(); this.foldingRules = new CStyleFoldMode();

View file

@ -249,6 +249,8 @@ var ScssHighlightRules = function() {
}, { }, {
token : "text", token : "text",
regex : "\\s+" regex : "\\s+"
}, {
caseInsensitive: true
} }
], ],
"comment" : [ "comment" : [

View file

@ -43,15 +43,10 @@ var MAX_TOKEN_COUNT = 1000;
/** /**
* Constructs a new tokenizer based on the given rules and flags. * Constructs a new tokenizer based on the given rules and flags.
* @param {Object} rules The highlighting rules * @param {Object} rules The highlighting rules
* @param {String} flag Any additional regular expression flags to pass (like "i" for case insensitive)
*
*
*
* *
* @constructor * @constructor
**/ **/
var Tokenizer = function(rules, flag) { var Tokenizer = function(rules) {
flag = flag ? "g" + flag : "g";
this.states = rules; this.states = rules;
this.regExps = {}; this.regExps = {};
@ -61,13 +56,17 @@ var Tokenizer = function(rules, flag) {
var ruleRegExps = []; var ruleRegExps = [];
var matchTotal = 0; var matchTotal = 0;
var mapping = this.matchMappings[key] = {defaultToken: "text"}; var mapping = this.matchMappings[key] = {defaultToken: "text"};
var flag = "g";
for (var i = 0; i < state.length; i++) { for (var i = 0; i < state.length; i++) {
var rule = state[i]; var rule = state[i];
if (rule.defaultToken) { if (rule.defaultToken)
mapping.defaultToken = rule.defaultToken; mapping.defaultToken = rule.defaultToken;
if (rule.caseInsensitive)
flag = "gi";
if (rule.regex == null)
continue; continue;
}
if (rule.regex instanceof RegExp) if (rule.regex instanceof RegExp)
rule.regex = rule.regex.toString().slice(1, -1); rule.regex = rule.regex.toString().slice(1, -1);