Merge pull request #415 from Gozala/bug/parens-color
Allow highlighting parens with a diff color via .ace_paren style.
This commit is contained in:
commit
b697708092
14 changed files with 82 additions and 35 deletions
|
|
@ -46,15 +46,42 @@ 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";
|
||||
|
||||
var deprecated = lang.arrayToMap(
|
||||
("__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("|")
|
||||
);
|
||||
|
|
@ -109,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",
|
||||
|
|
@ -120,8 +147,12 @@ var JavaScriptHighlightRules = function() {
|
|||
next : "regex_allowed"
|
||||
}, {
|
||||
token : function(value) {
|
||||
if (value == "this")
|
||||
if (globals.hasOwnProperty(value))
|
||||
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))
|
||||
|
|
@ -139,11 +170,15 @@ var JavaScriptHighlightRules = function() {
|
|||
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)",
|
||||
next : "regex_allowed"
|
||||
}, {
|
||||
token : "lparen",
|
||||
token : "punctuation.operator",
|
||||
regex : "\\?|\\:|\\,|\\;|\\.",
|
||||
next : "regex_allowed"
|
||||
}, {
|
||||
token : "paren.lparen",
|
||||
regex : "[[({]",
|
||||
next : "regex_allowed"
|
||||
}, {
|
||||
token : "rparen",
|
||||
token : "paren.rparen",
|
||||
regex : "[\\])}]"
|
||||
}, {
|
||||
token : "keyword.operator",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue