From b7e69d5da56f83aacbd54afb20f0501530d72ae2 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 15 Apr 2010 10:34:23 +0200 Subject: [PATCH] minor fixes --- src/Editor.js | 1 + src/Tokenizer.js | 15 ++++++--------- src/mode/JavaScript.js | 9 +++++---- test/mode/JavaScriptTokenizerTest.js | 20 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 test/mode/JavaScriptTokenizerTest.js diff --git a/src/Editor.js b/src/Editor.js index e999c5fc..30d92c25 100644 --- a/src/Editor.js +++ b/src/Editor.js @@ -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(); diff --git a/src/Tokenizer.js b/src/Tokenizer.js index fd7d54d9..fb50fc74 100644 --- a/src/Tokenizer.js +++ b/src/Tokenizer.js @@ -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, diff --git a/src/mode/JavaScript.js b/src/mode/JavaScript.js index 65800a53..c4f25fd6 100644 --- a/src/mode/JavaScript.js +++ b/src/mode/JavaScript.js @@ -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+).*$/); diff --git a/test/mode/JavaScriptTokenizerTest.js b/test/mode/JavaScriptTokenizerTest.js new file mode 100644 index 00000000..0e5e019e --- /dev/null +++ b/test/mode/JavaScriptTokenizerTest.js @@ -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); + } + +}); \ No newline at end of file