From 4f482437d72ea628dda0d063449374dbc439ec1e Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 8 Sep 2011 12:33:45 +0200 Subject: [PATCH 1/5] Allow highlighting parens with a diff color via .ace_paren style. --- lib/ace/mode/c_cpp_highlight_rules.js | 4 ++-- lib/ace/mode/coffee_highlight_rules.js | 4 ++-- lib/ace/mode/csharp_highlight_rules.js | 4 ++-- lib/ace/mode/css_highlight_rules.js | 8 ++++---- lib/ace/mode/javascript_highlight_rules.js | 4 ++-- lib/ace/mode/json_highlight_rules.js | 6 +++--- lib/ace/mode/lua_highlight_rules.js | 4 ++-- lib/ace/mode/ocaml_highlight_rules.js | 4 ++-- lib/ace/mode/php_highlight_rules.js | 4 ++-- lib/ace/mode/python_highlight_rules.js | 6 +++--- lib/ace/mode/ruby_highlight_rules.js | 4 ++-- lib/ace/mode/scad_highlight_rules.js | 4 ++-- lib/ace/mode/scala_highlight_rules.js | 4 ++-- lib/ace/mode/scss_highlight_rules.js | 4 ++-- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/ace/mode/c_cpp_highlight_rules.js b/lib/ace/mode/c_cpp_highlight_rules.js index 8efffa3a..e5576eee 100644 --- a/lib/ace/mode/c_cpp_highlight_rules.js +++ b/lib/ace/mode/c_cpp_highlight_rules.js @@ -121,10 +121,10 @@ var c_cppHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", diff --git a/lib/ace/mode/coffee_highlight_rules.js b/lib/ace/mode/coffee_highlight_rules.js index 7ab53559..afefad0c 100644 --- a/lib/ace/mode/coffee_highlight_rules.js +++ b/lib/ace/mode/coffee_highlight_rules.js @@ -127,10 +127,10 @@ define(function(require, exports, module) { token : "comment", regex : "#.*" }, { - token : "lparen", + token : "paren.lparen", regex : "[({[]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\]})]" }, { token : "keyword.operator", diff --git a/lib/ace/mode/csharp_highlight_rules.js b/lib/ace/mode/csharp_highlight_rules.js index a246a296..13e96315 100644 --- a/lib/ace/mode/csharp_highlight_rules.js +++ b/lib/ace/mode/csharp_highlight_rules.js @@ -67,10 +67,10 @@ var CSharpHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", diff --git a/lib/ace/mode/css_highlight_rules.js b/lib/ace/mode/css_highlight_rules.js index 967d7d67..2dddabab 100644 --- a/lib/ace/mode/css_highlight_rules.js +++ b/lib/ace/mode/css_highlight_rules.js @@ -215,14 +215,14 @@ var CssHighlightRules = function() { var ruleset = lang.copyArray(base_ruleset); ruleset.unshift({ - token : "rparen", + token : "paren.rparen", regex : "\\}", next: "start" }); var media_ruleset = lang.copyArray( base_ruleset ); media_ruleset.unshift({ - token : "rparen", + token : "paren.rparen", regex : "\\}", next: "media" }); @@ -261,7 +261,7 @@ var CssHighlightRules = function() { regex : "\\/\\*", next : "comment" }, { - token: "lparen", + token: "paren.lparen", regex: "\\{", next: "ruleset" }, { @@ -288,7 +288,7 @@ var CssHighlightRules = function() { regex : "\\/\\*", next : "media_comment" }, { - token: "lparen", + token: "paren.lparen", regex: "\\{", next: "media_ruleset" },{ diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 61903b05..1c19bc03 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -139,11 +139,11 @@ var JavaScriptHighlightRules = function() { regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", next : "regex_allowed" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]", next : "regex_allowed" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "keyword.operator", diff --git a/lib/ace/mode/json_highlight_rules.js b/lib/ace/mode/json_highlight_rules.js index 116b093c..872c3939 100644 --- a/lib/ace/mode/json_highlight_rules.js +++ b/lib/ace/mode/json_highlight_rules.js @@ -67,10 +67,10 @@ var JsonHighlightRules = function() { token : "invalid.illegal", // comments are not allowed regex : "\\/\\/.*$" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", @@ -84,4 +84,4 @@ var JsonHighlightRules = function() { oop.inherits(JsonHighlightRules, TextHighlightRules); exports.JsonHighlightRules = JsonHighlightRules; -}); \ No newline at end of file +}); diff --git a/lib/ace/mode/lua_highlight_rules.js b/lib/ace/mode/lua_highlight_rules.js index 3a2fa3b8..bca749dd 100644 --- a/lib/ace/mode/lua_highlight_rules.js +++ b/lib/ace/mode/lua_highlight_rules.js @@ -279,10 +279,10 @@ var LuaHighlightRules = function() { token : "keyword.operator", regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\." }, { - token : "lparen", + token : "paren.lparen", regex : "[\\[\\(\\{]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\]\\)\\}]" }, { token : "text", diff --git a/lib/ace/mode/ocaml_highlight_rules.js b/lib/ace/mode/ocaml_highlight_rules.js index 892ce409..1d15b245 100644 --- a/lib/ace/mode/ocaml_highlight_rules.js +++ b/lib/ace/mode/ocaml_highlight_rules.js @@ -309,11 +309,11 @@ var OcamlHighlightRules = function() { regex : "\\+\\.|\\-\\.|\\*\\.|\\/\\.|#|;;|\\+|\\-|\\*|\\*\\*\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|<-|=" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { diff --git a/lib/ace/mode/php_highlight_rules.js b/lib/ace/mode/php_highlight_rules.js index e9c2268c..50f79952 100644 --- a/lib/ace/mode/php_highlight_rules.js +++ b/lib/ace/mode/php_highlight_rules.js @@ -1004,10 +1004,10 @@ var PhpHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", diff --git a/lib/ace/mode/python_highlight_rules.js b/lib/ace/mode/python_highlight_rules.js index eb060df2..0c566d0b 100644 --- a/lib/ace/mode/python_highlight_rules.js +++ b/lib/ace/mode/python_highlight_rules.js @@ -145,10 +145,10 @@ var PythonHighlightRules = function() { token : "keyword.operator", regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|=" }, { - token : "lparen", + token : "lparen.paren", regex : "[\\[\\(\\{]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\]\\)\\}]" }, { token : "text", @@ -178,4 +178,4 @@ var PythonHighlightRules = function() { oop.inherits(PythonHighlightRules, TextHighlightRules); exports.PythonHighlightRules = PythonHighlightRules; -}); \ No newline at end of file +}); diff --git a/lib/ace/mode/ruby_highlight_rules.js b/lib/ace/mode/ruby_highlight_rules.js index 24cca739..9fe03e05 100644 --- a/lib/ace/mode/ruby_highlight_rules.js +++ b/lib/ace/mode/ruby_highlight_rules.js @@ -163,10 +163,10 @@ var RubyHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", diff --git a/lib/ace/mode/scad_highlight_rules.js b/lib/ace/mode/scad_highlight_rules.js index 627a6497..d75c7b68 100644 --- a/lib/ace/mode/scad_highlight_rules.js +++ b/lib/ace/mode/scad_highlight_rules.js @@ -112,10 +112,10 @@ var scadHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", diff --git a/lib/ace/mode/scala_highlight_rules.js b/lib/ace/mode/scala_highlight_rules.js index 11456522..5b1d6dec 100644 --- a/lib/ace/mode/scala_highlight_rules.js +++ b/lib/ace/mode/scala_highlight_rules.js @@ -110,10 +110,10 @@ var ScalaHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", diff --git a/lib/ace/mode/scss_highlight_rules.js b/lib/ace/mode/scss_highlight_rules.js index d93bf0e4..a4553ad3 100644 --- a/lib/ace/mode/scss_highlight_rules.js +++ b/lib/ace/mode/scss_highlight_rules.js @@ -310,10 +310,10 @@ var ScssHighlightRules = function() { token : "keyword.operator", regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*" }, { - token : "lparen", + token : "paren.lparen", regex : "[[({]" }, { - token : "rparen", + token : "paren.rparen", regex : "[\\])}]" }, { token : "text", From 61237fea689f49ca3d115a483d20d6db3f086f9f Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 16:59:35 +0200 Subject: [PATCH 2/5] Highlighter support for JS globals. --- lib/ace/mode/javascript_highlight_rules.js | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 1c19bc03..545e1d69 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -46,12 +46,33 @@ var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightR var JavaScriptHighlightRules = function() { + // see: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects + var globals = lang.arrayToMap( + // Constructors + ("Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + + // E4X + "Namespace|QName|XML|XMLList|" + + "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" + + "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" + + // Errors + "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + + "SyntaxError|TypeError|URIError|" + + // Non-constructor functions + "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + + "isNaN|parseFloat|parseInt|" + + // Other + "JSON|Math|" + + // Pseudo + "this|arguments|prototype|window|document" + ).split("|") + ); + var keywords = lang.arrayToMap( ("break|case|catch|continue|default|delete|do|else|finally|for|function|" + "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|" + "const|yield|import|get|set").split("|") ); - + // keywords which can be followed by regular expressions var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield"; @@ -120,7 +141,7 @@ var JavaScriptHighlightRules = function() { next : "regex_allowed" }, { token : function(value) { - if (value == "this") + if (globals.hasOwnProperty(value)) return "variable.language"; else if (keywords.hasOwnProperty(value)) return "keyword"; From 7d68dc7d040b1099a1beecf8e14d86f2f39c2ad2 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 17:00:45 +0200 Subject: [PATCH 3/5] Highlighter support for JS deprecated. --- lib/ace/mode/javascript_highlight_rules.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 545e1d69..46306409 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -76,6 +76,10 @@ var JavaScriptHighlightRules = function() { // keywords which can be followed by regular expressions var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield"; + var deprecated = lang.arrayToMap( + ("__parent__|__count__|escape|unescape|with|__proto__").split("|") + ); + var buildinConstants = lang.arrayToMap( ("null|Infinity|NaN|undefined").split("|") ); @@ -143,6 +147,8 @@ var JavaScriptHighlightRules = function() { token : function(value) { if (globals.hasOwnProperty(value)) return "variable.language"; + else if (deprecated.hasOwnProperty(value)) + return "invalid.deprecated"; else if (keywords.hasOwnProperty(value)) return "keyword"; else if (buildinConstants.hasOwnProperty(value)) From 0d5bb63e1dd83086e34a6daccefc2f43478e947f Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 17:01:21 +0200 Subject: [PATCH 4/5] Highlighter support for JS definitions. --- lib/ace/mode/javascript_highlight_rules.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 46306409..5fc05192 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -80,6 +80,8 @@ var JavaScriptHighlightRules = function() { ("__parent__|__count__|escape|unescape|with|__proto__").split("|") ); + var definitions = lang.arrayToMap(("const|let|var|function").split("|")); + var buildinConstants = lang.arrayToMap( ("null|Infinity|NaN|undefined").split("|") ); @@ -134,7 +136,7 @@ var JavaScriptHighlightRules = function() { token : "constant.numeric", // float regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" }, { - token : ["keyword", "text", "entity.name.function"], + token : ["keyword.definition", "text", "entity.name.function"], regex : "(function)(\\s+)(" + identifierRe + ")" }, { token : "constant.language.boolean", @@ -149,6 +151,8 @@ var JavaScriptHighlightRules = function() { return "variable.language"; else if (deprecated.hasOwnProperty(value)) return "invalid.deprecated"; + else if (definitions.hasOwnProperty(value)) + return "keyword.definition"; else if (keywords.hasOwnProperty(value)) return "keyword"; else if (buildinConstants.hasOwnProperty(value)) From 4e56be878ffb9bea5130af2488c29a2a9eff67ee Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 17:02:29 +0200 Subject: [PATCH 5/5] Highlighter support for c++, coffee, c#, js punctuation operators. --- lib/ace/mode/c_cpp_highlight_rules.js | 4 ++++ lib/ace/mode/coffee_highlight_rules.js | 4 ++++ lib/ace/mode/csharp_highlight_rules.js | 4 ++++ lib/ace/mode/javascript_highlight_rules.js | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/lib/ace/mode/c_cpp_highlight_rules.js b/lib/ace/mode/c_cpp_highlight_rules.js index e5576eee..4a909641 100644 --- a/lib/ace/mode/c_cpp_highlight_rules.js +++ b/lib/ace/mode/c_cpp_highlight_rules.js @@ -120,6 +120,10 @@ var c_cppHighlightRules = function() { }, { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)" + }, { + token : "punctuation.operator", + regex : "\\?|\\:|\\,|\\;|\\.", + next : "regex_allowed" }, { token : "paren.lparen", regex : "[[({]" diff --git a/lib/ace/mode/coffee_highlight_rules.js b/lib/ace/mode/coffee_highlight_rules.js index afefad0c..9f83290d 100644 --- a/lib/ace/mode/coffee_highlight_rules.js +++ b/lib/ace/mode/coffee_highlight_rules.js @@ -126,6 +126,10 @@ define(function(require, exports, module) { }, { token : "comment", regex : "#.*" + }, { + token : "punctuation.operator", + regex : "\\?|\\:|\\,|\\.", + next : "regex_allowed" }, { token : "paren.lparen", regex : "[({[]" diff --git a/lib/ace/mode/csharp_highlight_rules.js b/lib/ace/mode/csharp_highlight_rules.js index 13e96315..953c6f96 100644 --- a/lib/ace/mode/csharp_highlight_rules.js +++ b/lib/ace/mode/csharp_highlight_rules.js @@ -66,6 +66,10 @@ var CSharpHighlightRules = function() { }, { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" + }, { + token : "punctuation.operator", + regex : "\\?|\\:|\\,|\\;|\\.", + next : "regex_allowed" }, { token : "paren.lparen", regex : "[[({]" diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 5fc05192..865db54f 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -169,6 +169,10 @@ var JavaScriptHighlightRules = function() { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)", next : "regex_allowed" + }, { + token : "punctuation.operator", + regex : "\\?|\\:|\\,|\\;|\\.", + next : "regex_allowed" }, { token : "paren.lparen", regex : "[[({]",