minor fixes
This commit is contained in:
parent
58d2b6917f
commit
b7e69d5da5
4 changed files with 32 additions and 13 deletions
|
|
@ -44,6 +44,7 @@ ace.Editor.prototype.setDocument = function(doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.setMode = function(mode) {
|
ace.Editor.prototype.setMode = function(mode) {
|
||||||
|
if (this.mode == mode) return;
|
||||||
|
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
var tokenizer = mode.getTokenizer();
|
var tokenizer = mode.getTokenizer();
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,10 @@ ace.Tokenizer = function(rules) {
|
||||||
|
|
||||||
for ( var i = 0; i < state.length; i++) {
|
for ( var i = 0; i < state.length; i++) {
|
||||||
ruleRegExps.push(state[i].regex);
|
ruleRegExps.push(state[i].regex);
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(")
|
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"); }
|
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
|
||||||
lastIndex = re.lastIndex;
|
lastIndex = re.lastIndex;
|
||||||
|
|
||||||
// console.log(match);
|
// window.LOG && console.log(match);
|
||||||
|
|
||||||
for ( var i = 0; i < state.length; i++) {
|
for ( var i = 0; i < state.length; i++) {
|
||||||
if (match[i + 1]) {
|
if (match[i + 1]) {
|
||||||
|
|
@ -58,14 +57,12 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
// console.log(tokens, currentState)
|
// window.LOG && console.log(tokens, currentState);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tokens : tokens,
|
tokens : tokens,
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,13 @@ ace.mode.JavaScript.prototype.increaseIndentPatterns = {
|
||||||
|
|
||||||
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
|
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
|
||||||
var re = this.increaseIndentPatterns[state];
|
var re = this.increaseIndentPatterns[state];
|
||||||
if (!re) return
|
|
||||||
|
|
||||||
|
if (re) {
|
||||||
var match = line.match(re);
|
var match = line.match(re);
|
||||||
if (match) {
|
if (match) {
|
||||||
return (match[1] || "") + tab;
|
return (match[1] || "") + tab;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var match = line.match(/^(\s+).*$/);
|
var match = line.match(/^(\s+).*$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|
|
||||||
20
test/mode/JavaScriptTokenizerTest.js
Normal file
20
test/mode/JavaScriptTokenizerTest.js
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue