minor fixes

This commit is contained in:
Fabian Jakobs 2010-04-15 10:34:23 +02:00
commit b7e69d5da5
4 changed files with 32 additions and 13 deletions

View file

@ -44,6 +44,7 @@ ace.Editor.prototype.setDocument = function(doc) {
};
ace.Editor.prototype.setMode = function(mode) {
if (this.mode == mode) return;
this.mode = mode;
var tokenizer = mode.getTokenizer();

View file

@ -10,11 +10,10 @@ ace.Tokenizer = function(rules) {
for ( var i = 0; i < state.length; i++) {
ruleRegExps.push(state[i].regex);
}
;
};
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(")
+ ")|(.+))", "g");
+ ")|(.))", "g");
}
};
@ -37,7 +36,7 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
lastIndex = re.lastIndex;
// console.log(match);
// window.LOG && console.log(match);
for ( var i = 0; i < state.length; i++) {
if (match[i + 1]) {
@ -58,14 +57,12 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
}
break;
}
}
;
};
tokens.push(token);
}
;
};
// console.log(tokens, currentState)
// window.LOG && console.log(tokens, currentState);
return {
tokens : tokens,

View file

@ -19,11 +19,12 @@ ace.mode.JavaScript.prototype.increaseIndentPatterns = {
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
var re = this.increaseIndentPatterns[state];
if (!re) return
var match = line.match(re);
if (match) {
return (match[1] || "") + tab;
if (re) {
var match = line.match(re);
if (match) {
return (match[1] || "") + tab;
}
}
var match = line.match(/^(\s+).*$/);

View file

@ -0,0 +1,20 @@
var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
setUp : function() {
this.tokenizer = new ace.mode.JavaScript().getTokenizer();
},
"test: tokenize1" : function() {
var line = "foo = function";
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
assertEquals(5, tokens.length);
assertEquals("identifier", tokens[0].type);
assertEquals("text", tokens[1].type);
assertEquals("text", tokens[2].type);
assertEquals("text", tokens[3].type);
assertEquals("keyword", tokens[4].type);
}
});