134 lines
4.2 KiB
JavaScript
134 lines
4.2 KiB
JavaScript
define(function(require, exports, module) {
|
|
|
|
var oop = require("pilot/oop");
|
|
var lang = require("pilot/lang");
|
|
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
|
|
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
|
|
|
JavaHighlightRules = function() {
|
|
|
|
var docComment = new DocCommentHighlightRules();
|
|
|
|
// taken from http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
|
|
var keywords = lang.arrayToMap(
|
|
("abstract|continue|for|new|switch|" +
|
|
"assert|default|goto|package|synchronized" +
|
|
"boolean|do|if|private|this" +
|
|
"break|double|implements|protected|throw" +
|
|
"byte|else|import|public|throws" +
|
|
"case|enum|instanceof|return|transient" +
|
|
"catch|extends|int|short|try" +
|
|
"char|final|interface|static|void" +
|
|
"class|finally|long|strictfp|volatile|" +
|
|
"const|float|native|super|while").split("|")
|
|
);
|
|
|
|
var buildinConstants = lang.arrayToMap(
|
|
("null|Infinity|NaN|undefined").split("|")
|
|
);
|
|
|
|
|
|
// regexp must not have capturing parentheses. Use (?:) instead.
|
|
// regexps are ordered -> the first match is used
|
|
|
|
this.$rules = {
|
|
"start" : [
|
|
{
|
|
token : "comment",
|
|
regex : "\\/\\/.*$"
|
|
},
|
|
docComment.getStartRule("doc-start"),
|
|
{
|
|
token : "comment", // multi line comment
|
|
regex : "\\/\\*",
|
|
next : "comment"
|
|
}, {
|
|
token : "comment", // multi line comment
|
|
regex : "\\/\\*\\*",
|
|
next : "comment"
|
|
}, {
|
|
token : "string.regexp",
|
|
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
|
}, {
|
|
token : "string", // single line
|
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
|
}, {
|
|
token : "string", // single line
|
|
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
|
}, {
|
|
token : "constant.numeric", // hex
|
|
regex : "0[xX][0-9a-fA-F]+\\b"
|
|
}, {
|
|
token : "constant.numeric", // float
|
|
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
|
}, {
|
|
token : "constant.language.boolean",
|
|
regex : "(?:true|false)\\b"
|
|
}, {
|
|
token : function(value) {
|
|
if (value == "this")
|
|
return "variable.language";
|
|
else if (keywords[value])
|
|
return "keyword";
|
|
else if (buildinConstants[value])
|
|
return "constant.language";
|
|
else
|
|
return "identifier";
|
|
},
|
|
// TODO: Unicode escape sequences
|
|
// TODO: Unicode identifiers
|
|
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
|
}, {
|
|
token : "keyword.operator",
|
|
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
|
}, {
|
|
token : "lparen",
|
|
regex : "[[({]"
|
|
}, {
|
|
token : "rparen",
|
|
regex : "[\\])}]"
|
|
}, {
|
|
token : "text",
|
|
regex : "\\s+"
|
|
}
|
|
],
|
|
"comment" : [
|
|
{
|
|
token : "comment", // closing comment
|
|
regex : ".*?\\*\\/",
|
|
next : "start"
|
|
}, {
|
|
token : "comment", // comment spanning whole line
|
|
regex : ".+"
|
|
}
|
|
],
|
|
"qqstring" : [
|
|
{
|
|
token : "string",
|
|
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
|
next : "start"
|
|
}, {
|
|
token : "string",
|
|
regex : '.+'
|
|
}
|
|
],
|
|
"qstring" : [
|
|
{
|
|
token : "string",
|
|
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
|
next : "start"
|
|
}, {
|
|
token : "string",
|
|
regex : '.+'
|
|
}
|
|
]
|
|
};
|
|
|
|
this.addRules(docComment.getRules(), "doc-");
|
|
this.$rules["doc-start"][0].next = "start";
|
|
};
|
|
|
|
oop.inherits(JavaHighlightRules, TextHighlightRules);
|
|
|
|
exports.JavaHighlightRules = JavaHighlightRules;
|
|
});
|