From 5b08bf8e1e3e1f7ce5fc6e59ed5bce7b1cbb0106 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 4 Dec 2011 20:33:54 +0400 Subject: [PATCH 1/4] fix js regex highlighting adds coloring for escaped entities \s and fixes highlighting regexps like /[]/g --- lib/ace/mode/javascript_highlight_rules.js | 55 ++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 2ce21425..554df3df 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -205,10 +205,9 @@ var JavaScriptHighlightRules = function() { regex : "\\/\\/.*$" }, { token: "string.regexp", - regex: "\\/(?:(?:\\[(?:\\\\]|[^\\]])+\\])" - + "|(?:\\\\/|[^\\]/]))*" - + "[/]\\w*", - next: "start" + regex: "\\/", + next: "regex", + merge: true }, { token : "text", regex : "\\s+" @@ -220,6 +219,54 @@ var JavaScriptHighlightRules = function() { next: "start" } ], + "regex": [ + { + token: "regexp.keyword.operator", + regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)", + next: "regex" + }, { + // flag + token: "string.regexp", + regex: "/\\w*", + next: "start", + merge: true + }, { + token: "string.regexp", + regex: "[^\\\\/\\[]+", + next: "regex", + merge: true + }, { + token: "string.regexp.charachterclass", + regex: "\\[", + next: "regex_character_class", + merge: true + }, { + token: "empty", + regex: "", + next: "start" + } + ], + "regex_character_class": [ + { + token: "regexp.keyword.operator", + regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)", + next: "regex_character_class" + }, { + token: "string.regexp.charachterclass", + regex: "]", + next: "regex", + merge: true + }, { + token: "string.regexp.charachterclass", + regex: "[^\\\\\\]]+", + next: "regex_character_class", + merge: true + }, { + token: "empty", + regex: "", + next: "start" + } + ], "comment_regex_allowed" : [ { token : "comment", // closing comment From ba334cae71c1ac008cd382c65b03f8a4cc01fe90 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 4 Dec 2011 20:40:46 +0400 Subject: [PATCH 2/4] fix for broken paren matching in @keyframes rules --- demo/kitchen-sink/docs/css.css | 25 +++++++++++++++++++++++++ lib/ace/mode/css_highlight_rules.js | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/demo/kitchen-sink/docs/css.css b/demo/kitchen-sink/docs/css.css index 3bb89ff8..3e32ec1d 100644 --- a/demo/kitchen-sink/docs/css.css +++ b/demo/kitchen-sink/docs/css.css @@ -2,4 +2,29 @@ font-family: Monaco, "Courier New", monospace; font-size: 12px; cursor: text; +} + + + +.blinker { + animation-duration: 1s; + animation-name: blink; + animation-iteration-count: infinite; + nimation-direction: alternate; + animation-timing-function: linear; +} + +@keyframes blink { + 0% { + opacity: 0; + } + 40% { + opacity: 0; + } + 40.5% { + opacity: 1 + } + 100% { + opacity: 1 + } } \ No newline at end of file diff --git a/lib/ace/mode/css_highlight_rules.js b/lib/ace/mode/css_highlight_rules.js index 7780f44c..71139e0c 100644 --- a/lib/ace/mode/css_highlight_rules.js +++ b/lib/ace/mode/css_highlight_rules.js @@ -266,7 +266,7 @@ var CssHighlightRules = function() { next: "ruleset" }, { token: "string", - regex: "@media.*?{", + regex: "@.*?{", next: "media" },{ token: "keyword", From c4bdcd8bad6e5b9bc534551787f52a15146ebd66 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 4 Dec 2011 20:55:25 +0400 Subject: [PATCH 3/4] add ability to Tokenizer to use "i" flag for caseInsensitve languages --- lib/ace/mode/css.js | 2 +- lib/ace/mode/css_highlight_rules.js | 84 ++++------------------------ lib/ace/mode/scss.js | 2 +- lib/ace/mode/scss_highlight_rules.js | 78 +++----------------------- lib/ace/tokenizer.js | 3 +- 5 files changed, 24 insertions(+), 145 deletions(-) diff --git a/lib/ace/mode/css.js b/lib/ace/mode/css.js index 7fc14152..5661e6d8 100644 --- a/lib/ace/mode/css.js +++ b/lib/ace/mode/css.js @@ -46,7 +46,7 @@ var WorkerClient = require("../worker/worker_client").WorkerClient; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { - this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules()); + this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules(), "i"); this.$outdent = new MatchingBraceOutdent(); this.foldingRules = new CStyleFoldMode(); }; diff --git a/lib/ace/mode/css_highlight_rules.js b/lib/ace/mode/css_highlight_rules.js index 71139e0c..d3875c21 100644 --- a/lib/ace/mode/css_highlight_rules.js +++ b/lib/ace/mode/css_highlight_rules.js @@ -108,20 +108,6 @@ var CssHighlightRules = function() { var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; - function ic(str) { - var re = []; - var chars = str.split(""); - for (var i=0; i the first match is used @@ -218,58 +203,13 @@ var ScssHighlightRules = function() { next : "qstring" }, { token : "constant.numeric", - regex : numRe + ic("em") - }, { - token : "constant.numeric", - regex : numRe + ic("ex") - }, { - token : "constant.numeric", - regex : numRe + ic("px") - }, { - token : "constant.numeric", - regex : numRe + ic("cm") - }, { - token : "constant.numeric", - regex : numRe + ic("mm") - }, { - token : "constant.numeric", - regex : numRe + ic("in") - }, { - token : "constant.numeric", - regex : numRe + ic("pt") - }, { - token : "constant.numeric", - regex : numRe + ic("pc") - }, { - token : "constant.numeric", - regex : numRe + ic("deg") - }, { - token : "constant.numeric", - regex : numRe + ic("rad") - }, { - token : "constant.numeric", - regex : numRe + ic("grad") - }, { - token : "constant.numeric", - regex : numRe + ic("ms") - }, { - token : "constant.numeric", - regex : numRe + ic("s") - }, { - token : "constant.numeric", - regex : numRe + ic("hz") - }, { - token : "constant.numeric", - regex : numRe + ic("khz") - }, { - token : "constant.numeric", - regex : numRe + "%" + regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)" }, { token : "constant.numeric", // hex6 color - regex : "#[a-fA-F0-9]{6}" + regex : "#[a-f0-9]{6}" }, { token : "constant.numeric", // hex3 color - regex : "#[a-fA-F0-9]{3}" + regex : "#[a-f0-9]{3}" }, { token : "constant.numeric", regex : numRe @@ -290,22 +230,22 @@ var ScssHighlightRules = function() { else return "text"; }, - regex : "\\-?[@a-zA-Z_][@a-zA-Z0-9_\\-]*" + regex : "\\-?[@a-z_][@a-z0-9_\\-]*" }, { token : "variable", - regex : "[a-zA-Z_\\-$][a-zA-Z0-9_\\-$]*\\b" + regex : "[a-z_\\-$][a-z0-9_\\-$]*\\b" }, { token: "variable.language", - regex: "#[a-zA-Z0-9-_]+" + regex: "#[a-z0-9-_]+" }, { token: "variable.language", - regex: "\\.[a-zA-Z0-9-_]+" + regex: "\\.[a-z0-9-_]+" }, { token: "variable.language", - regex: ":[a-zA-Z0-9-_]+" + regex: ":[a-z0-9-_]+" }, { token: "constant", - regex: "[a-zA-Z0-9-_]+" + regex: "[a-z0-9-_]+" }, { token : "keyword.operator", regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*" diff --git a/lib/ace/tokenizer.js b/lib/ace/tokenizer.js index bf4727fe..edcd817a 100644 --- a/lib/ace/tokenizer.js +++ b/lib/ace/tokenizer.js @@ -42,6 +42,7 @@ var Tokenizer = function(rules) { this.regExps = {}; this.matchMappings = {}; + var flag = flag ? "g" + flag : "g"; for ( var key in this.rules) { var rule = this.rules[key]; var state = rule; @@ -68,7 +69,7 @@ var Tokenizer = function(rules) { ruleRegExps.push(adjustedregex); } - this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", "g"); + this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", flag); } }; From f1c4eab5509d3afc7b2a0224e0c58d4d193f5341 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 4 Dec 2011 21:03:58 +0400 Subject: [PATCH 4/4] cstyle folding throws if matching bracket isn't found --- lib/ace/mode/folding/cstyle.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index d44a7de6..e52f70f4 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -60,17 +60,17 @@ oop.inherits(FoldMode, BaseFoldMode); var start = {row: row, column: i+1}; var end = session.$findClosingBracket(match[1], start); - if (end) { - var fw = session.foldWidgets[end.row]; - if (fw == null) - fw = this.getFoldWidget(session, end.row); + if (!end) + return; - if (fw == "start"){ - end.row --; - end.column = session.getLine(end.row).length; - } + var fw = session.foldWidgets[end.row]; + if (fw == null) + fw = this.getFoldWidget(session, end.row); + + if (fw == "start") { + end.row --; + end.column = session.getLine(end.row).length; } - return Range.fromPoints(start, end); } @@ -84,10 +84,11 @@ oop.inherits(FoldMode, BaseFoldMode); var end = {row: row, column: i}; var start = session.$findOpeningBracket(match[1], end); - if (start) { - start.column++; - end.column--; - } + if (!start) + return; + + start.column++; + end.column--; return Range.fromPoints(start, end); }