Fixed to allow tokenizing of an empty line. eg. a rule with a regex of ^$

This commit is contained in:
Daniel Krech 2011-02-06 23:53:02 +08:00 committed by Fabian Jakobs
commit ae4b171065

View file

@ -74,11 +74,8 @@ var Tokenizer = function(rules) {
var type = "text";
var value = match[0];
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
lastIndex = re.lastIndex;
for ( var i = 0; i < state.length; i++) {
if (match[i + 1]) {
if (match[i + 1] !== undefined) {
if (typeof state[i].token == "function") {
type = state[i].token(match[0]);
}
@ -110,6 +107,10 @@ var Tokenizer = function(rules) {
} else {
token.value += value;
}
if (lastIndex == line.length) {
break;
}
lastIndex = re.lastIndex;
};
if (token.type) {