From 314b95eb78f44270330a61883bc320735697b7af Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 28 Sep 2011 12:20:36 +0200 Subject: [PATCH] Multiple line commenting highlight fails when contains a single line comment. fix #426 --- lib/ace/mode/javascript_highlight_rules.js | 18 ++++++++++++++++++ lib/ace/mode/javascript_tokenizer_test.js | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 61903b05..0b665210 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -161,6 +161,11 @@ var JavaScriptHighlightRules = function() { // makes sure we don't mix up regexps with the divison operator "regex_allowed": [ { + token : "comment", // multi line comment + merge : true, + regex : "\\/\\*", + next : "comment_regex_allowed" + }, { token : "comment", regex : "\\/\\/.*$" }, { @@ -180,10 +185,23 @@ var JavaScriptHighlightRules = function() { next: "start" } ], + "comment_regex_allowed" : [ + { + token : "comment", // closing comment + regex : ".*?\\*\\/", + merge : true, + next : "regex_allowed" + }, { + token : "comment", // comment spanning whole line + merge : true, + regex : ".+" + } + ], "comment" : [ { token : "comment", // closing comment regex : ".*?\\*\\/", + merge : true, next : "start" }, { token : "comment", // comment spanning whole line diff --git a/lib/ace/mode/javascript_tokenizer_test.js b/lib/ace/mode/javascript_tokenizer_test.js index cc3bca64..bd745277 100644 --- a/lib/ace/mode/javascript_tokenizer_test.js +++ b/lib/ace/mode/javascript_tokenizer_test.js @@ -142,6 +142,15 @@ module.exports = { assert.equal("string.regexp", tokens[2].type); }, + "test tokenize multi-line comment containing a single line comment" : function() { + var tokens = this.tokenizer.getLineTokens("/* foo // bar */", "start").tokens; + assert.equal(1, tokens.length); + assert.equal("comment", tokens[0].type); + + var tokens = this.tokenizer.getLineTokens("/* foo // bar */", "regex_allowed").tokens; + assert.equal(1, tokens.length); + assert.equal("comment", tokens[0].type); + }, "test tokenize identifier with umlauts": function() { var tokens = this.tokenizer.getLineTokens("füße", "start").tokens;