highlight buildin constants and future reserved keywords

This commit is contained in:
Fabian Jakobs 2010-10-20 12:12:58 +02:00
commit 87d0a83796
2 changed files with 26 additions and 30 deletions

View file

@ -8,40 +8,29 @@
require.def("ace/mode/JavaScriptHighlightRules", require.def("ace/mode/JavaScriptHighlightRules",
[ [
"ace/lib/oop", "ace/lib/oop",
"ace/lib/lang",
"ace/mode/DocCommentHighlightRules", "ace/mode/DocCommentHighlightRules",
"ace/mode/TextHighlightRules" "ace/mode/TextHighlightRules"
], function(oop, DocCommentHighlightRules, TextHighlightRules) { ], function(oop, lang, DocCommentHighlightRules, TextHighlightRules) {
JavaScriptHighlightRules = function() { JavaScriptHighlightRules = function() {
var docComment = new DocCommentHighlightRules(); var docComment = new DocCommentHighlightRules();
var keywords = { var keywords = lang.arrayToMap(
"break" : 1, ("break|case|catch|continue|default|delete|do|else|finally|for|function|\
"case" : 1, if|in|instanceof|new|return|switch|throw|try|typeof|var|while|with").split("|")
"catch" : 1, );
"continue" : 1,
"default" : 1, var buildinConstants = lang.arrayToMap(
"delete" : 1, ("true|false|null|undefined|Infinity|NaN|undefined").split("|")
"do" : 1, );
"else" : 1,
"finally" : 1, var futureReserved = lang.arrayToMap(
"for" : 1, ("class|enum|extends|super|const|export|import|implements|let|private|\
"function" : 1, public|yield|interface|package|protected|static").split("|")
"if" : 1, );
"in" : 1,
"instanceof" : 1,
"new" : 1,
"return" : 1,
"switch" : 1,
"throw" : 1,
"try" : 1,
"typeof" : 1,
"var" : 1,
"while" : 1,
"with" : 1
};
// regexp must not have capturing parentheses. Use (?:) instead. // regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used // regexps are ordered -> the first match is used
@ -80,12 +69,14 @@ JavaScriptHighlightRules = function() {
token : function(value) { token : function(value) {
if (value == "this") if (value == "this")
return "variable"; return "variable";
if (keywords[value]) { else if (keywords[value])
return "keyword"; return "keyword";
} else if (buildinConstants[value])
else { return "buildin-constant";
else if (futureReserved[value] || value == "debugger")
return "invalid";
else
return "identifier"; return "identifier";
}
}, },
regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b" regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
}, { }, {

View file

@ -60,6 +60,11 @@
color: rgb(6, 150, 14); 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 { .ace-tm .ace_line .ace_buildin-function {
color: rgb(60, 76, 114); color: rgb(60, 76, 114);
} }