do not loose currentState if tokenizer uses combination of next and push

This commit is contained in:
nightwing 2013-11-30 18:40:02 +04:00
commit d87ba89c49
2 changed files with 19 additions and 3 deletions

View file

@ -188,11 +188,13 @@ var RubyHighlightRules = function() {
rules: { rules: {
heredoc: [{ heredoc: [{
onMatch: function(value, currentState, stack) { onMatch: function(value, currentState, stack) {
if (value == stack[1]) { if (value === stack[1]) {
stack.shift(); stack.shift();
stack.shift(); stack.shift();
this.next = stack[0] || "start";
return "support.class"; return "support.class";
} }
this.next = "";
return "string"; return "string";
}, },
regex: ".*$", regex: ".*$",
@ -203,17 +205,27 @@ var RubyHighlightRules = function() {
regex: "^ +" regex: "^ +"
}, { }, {
onMatch: function(value, currentState, stack) { onMatch: function(value, currentState, stack) {
if (value == stack[1]) { if (value === stack[1]) {
stack.shift(); stack.shift();
stack.shift(); stack.shift();
this.next = stack[0] || "start";
return "support.class"; return "support.class";
} }
this.next = "";
return "string"; return "string";
}, },
regex: ".*$", regex: ".*$",
next: "start" next: "start"
}] }]
} }
}, {
regex : "$",
token : "empty",
next : function(currentState, stack) {
if (stack[0] === "heredoc" || stack[0] === "indentedHeredoc")
return stack[0];
return currentState;
}
}, { }, {
token : "keyword.operator", token : "keyword.operator",
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"

View file

@ -321,6 +321,10 @@ var Tokenizer = function(rules) {
if (token.type) if (token.type)
tokens.push(token); tokens.push(token);
if (stack.length > 1) {
if (stack[0] !== currentState)
stack.unshift(currentState);
}
return { return {
tokens : tokens, tokens : tokens,
state : stack.length ? stack : currentState state : stack.length ? stack : currentState