mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
161 lines
6.1 KiB
JavaScript
161 lines
6.1 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 ScalaHighlightRules = function() {
|
||
|
|
||
|
// taken from http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
|
||
|
var keywords = (
|
||
|
"case|default|do|else|for|if|match|while|throw|return|try|catch|finally|yield|" +
|
||
|
"abstract|class|def|extends|final|forSome|implicit|implicits|import|lazy|new|object|" +
|
||
|
"override|package|private|protected|sealed|super|this|trait|type|val|var|with"
|
||
|
);
|
||
|
|
||
|
var buildinConstants = ("true|false");
|
||
|
|
||
|
var langClasses = (
|
||
|
"AbstractMethodError|AssertionError|ClassCircularityError|"+
|
||
|
"ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
|
||
|
"ExceptionInInitializerError|IllegalAccessError|"+
|
||
|
"IllegalThreadStateException|InstantiationError|InternalError|"+
|
||
|
|
||
|
"NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
|
||
|
"ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
|
||
|
"SuppressWarnings|TypeNotPresentException|UnknownError|"+
|
||
|
"UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
|
||
|
"InstantiationException|IndexOutOfBoundsException|"+
|
||
|
"ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
|
||
|
"NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
|
||
|
"SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
|
||
|
"InterruptedException|NoSuchMethodException|IllegalAccessException|"+
|
||
|
"UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
|
||
|
"Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
|
||
|
"NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
|
||
|
"NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
|
||
|
"Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
|
||
|
"Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
|
||
|
"StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
|
||
|
"ArrayStoreException|ClassCastException|LinkageError|"+
|
||
|
"NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
|
||
|
"Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
|
||
|
"Cloneable|Class|CharSequence|Comparable|String|Object|" +
|
||
|
"Unit|Any|AnyVal|AnyRef|Null|ScalaObject|Singleton|Seq|Iterable|List|" +
|
||
|
"Option|Array|Char|Byte|Short|Int|Long|Nothing"
|
||
|
|
||
|
|
||
|
);
|
||
|
|
||
|
var keywordMapper = this.createKeywordMapper({
|
||
|
"variable.language": "this",
|
||
|
"keyword": keywords,
|
||
|
"support.function": langClasses,
|
||
|
"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",
|
||
|
regex : '"""',
|
||
|
next : "tstring"
|
||
|
}, {
|
||
|
token : "string",
|
||
|
regex : '"(?=.)', // " strings can't span multiple lines
|
||
|
next : "string"
|
||
|
}, {
|
||
|
token : "symbol.constant", // single line
|
||
|
regex : "'[\\w\\d_]+"
|
||
|
}, {
|
||
|
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 : "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 : ".+"
|
||
|
}
|
||
|
],
|
||
|
"string" : [
|
||
|
{
|
||
|
token : "escape",
|
||
|
regex : '\\\\"'
|
||
|
}, {
|
||
|
token : "string",
|
||
|
regex : '"',
|
||
|
next : "start"
|
||
|
}, {
|
||
|
token : "string.invalid",
|
||
|
regex : '[^"\\\\]*$',
|
||
|
next : "start"
|
||
|
}, {
|
||
|
token : "string",
|
||
|
regex : '[^"\\\\]+'
|
||
|
}
|
||
|
],
|
||
|
"tstring" : [
|
||
|
{
|
||
|
token : "string", // closing comment
|
||
|
regex : '"{3,5}',
|
||
|
next : "start"
|
||
|
}, {
|
||
|
token : "string", // comment spanning whole line
|
||
|
regex : ".+?"
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
|
||
|
this.embedRules(DocCommentHighlightRules, "doc-",
|
||
|
[ DocCommentHighlightRules.getEndRule("start") ]);
|
||
|
};
|
||
|
|
||
|
oop.inherits(ScalaHighlightRules, TextHighlightRules);
|
||
|
|
||
|
exports.ScalaHighlightRules = ScalaHighlightRules;
|
||
|
});
|