mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 20:33:12 -05:00
99 lines
3.5 KiB
JavaScript
99 lines
3.5 KiB
JavaScript
|
define(function(require, exports, module) {
|
||
|
"use strict";
|
||
|
|
||
|
var oop = require("../lib/oop");
|
||
|
|
||
|
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
|
||
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||
|
|
||
|
var HaxeHighlightRules = function() {
|
||
|
|
||
|
var keywords = (
|
||
|
"break|case|cast|catch|class|continue|default|else|enum|extends|for|function|if|implements|import|in|inline|interface|new|override|package|private|public|return|static|super|switch|this|throw|trace|try|typedef|untyped|var|while|Array|Void|Bool|Int|UInt|Float|Dynamic|String|List|Hash|IntHash|Error|Unknown|Type|Std"
|
||
|
);
|
||
|
|
||
|
var buildinConstants = (
|
||
|
"null|true|false"
|
||
|
);
|
||
|
|
||
|
var keywordMapper = this.createKeywordMapper({
|
||
|
"variable.language": "this",
|
||
|
"keyword": keywords,
|
||
|
"constant.language": buildinConstants
|
||
|
}, "identifier");
|
||
|
|
||
|
// regexp must not have capturing parentheses. Use (?:) instead.
|
||
|
// regexps are ordered -> the first match is used
|
||
|
|
||
|
this.$rules = {
|
||
|
"start" : [
|
||
|
{
|
||
|
token : "comment",
|
||
|
regex : "\\/\\/.*$"
|
||
|
},
|
||
|
DocCommentHighlightRules.getStartRule("doc-start"),
|
||
|
{
|
||
|
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 : keywordMapper,
|
||
|
// 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 : "punctuation.operator",
|
||
|
regex : "\\?|\\:|\\,|\\;|\\."
|
||
|
}, {
|
||
|
token : "paren.lparen",
|
||
|
regex : "[[({<]"
|
||
|
}, {
|
||
|
token : "paren.rparen",
|
||
|
regex : "[\\])}>]"
|
||
|
}, {
|
||
|
token : "text",
|
||
|
regex : "\\s+"
|
||
|
}
|
||
|
],
|
||
|
"comment" : [
|
||
|
{
|
||
|
token : "comment", // closing comment
|
||
|
regex : ".*?\\*\\/",
|
||
|
next : "start"
|
||
|
}, {
|
||
|
token : "comment", // comment spanning whole line
|
||
|
regex : ".+"
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
|
||
|
this.embedRules(DocCommentHighlightRules, "doc-",
|
||
|
[ DocCommentHighlightRules.getEndRule("start") ]);
|
||
|
};
|
||
|
|
||
|
oop.inherits(HaxeHighlightRules, TextHighlightRules);
|
||
|
|
||
|
exports.HaxeHighlightRules = HaxeHighlightRules;
|
||
|
});
|