From 87d0a837967ffeb1ffa3f638084395184ef3ce5e Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 20 Oct 2010 12:12:58 +0200 Subject: [PATCH] highlight buildin constants and future reserved keywords --- src/ace/mode/JavaScriptHighlightRules.js | 51 ++++++++++-------------- src/ace/theme/tm.css | 5 +++ 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/ace/mode/JavaScriptHighlightRules.js b/src/ace/mode/JavaScriptHighlightRules.js index 5c06175f..3a2d29b1 100644 --- a/src/ace/mode/JavaScriptHighlightRules.js +++ b/src/ace/mode/JavaScriptHighlightRules.js @@ -8,40 +8,29 @@ require.def("ace/mode/JavaScriptHighlightRules", [ "ace/lib/oop", + "ace/lib/lang", "ace/mode/DocCommentHighlightRules", "ace/mode/TextHighlightRules" - ], function(oop, DocCommentHighlightRules, TextHighlightRules) { + ], function(oop, lang, DocCommentHighlightRules, TextHighlightRules) { JavaScriptHighlightRules = function() { var docComment = new DocCommentHighlightRules(); - var keywords = { - "break" : 1, - "case" : 1, - "catch" : 1, - "continue" : 1, - "default" : 1, - "delete" : 1, - "do" : 1, - "else" : 1, - "finally" : 1, - "for" : 1, - "function" : 1, - "if" : 1, - "in" : 1, - "instanceof" : 1, - "new" : 1, - "return" : 1, - "switch" : 1, - "throw" : 1, - "try" : 1, - "typeof" : 1, - "var" : 1, - "while" : 1, - "with" : 1 - }; + var keywords = lang.arrayToMap( + ("break|case|catch|continue|default|delete|do|else|finally|for|function|\ + if|in|instanceof|new|return|switch|throw|try|typeof|var|while|with").split("|") + ); + + var buildinConstants = lang.arrayToMap( + ("true|false|null|undefined|Infinity|NaN|undefined").split("|") + ); + + var futureReserved = lang.arrayToMap( + ("class|enum|extends|super|const|export|import|implements|let|private|\ + public|yield|interface|package|protected|static").split("|") + ); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -80,12 +69,14 @@ JavaScriptHighlightRules = function() { token : function(value) { if (value == "this") return "variable"; - if (keywords[value]) { + else if (keywords[value]) return "keyword"; - } - else { + else if (buildinConstants[value]) + return "buildin-constant"; + else if (futureReserved[value] || value == "debugger") + return "invalid"; + else return "identifier"; - } }, regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b" }, { diff --git a/src/ace/theme/tm.css b/src/ace/theme/tm.css index 1e557489..2f7cdd73 100644 --- a/src/ace/theme/tm.css +++ b/src/ace/theme/tm.css @@ -60,6 +60,11 @@ color: rgb(6, 150, 14); } +.ace-tm .ace_line .ace_invalid { + background-color: rgb(153, 0, 0); + color: white; +} + .ace-tm .ace_line .ace_buildin-function { color: rgb(60, 76, 114); }