scala_highlight_rules.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var ScalaHighlightRules = function() {
  7. var keywords = (
  8. "case|default|do|else|for|if|match|while|throw|return|try|trye|catch|finally|yield|" +
  9. "abstract|class|def|extends|final|forSome|implicit|implicits|import|lazy|new|object|null|" +
  10. "override|package|private|protected|sealed|super|this|trait|type|val|var|with|" +
  11. "assert|assume|require|print|println|printf|readLine|readBoolean|readByte|readShort|" + // package scala
  12. "readChar|readInt|readLong|readFloat|readDouble" // package scala
  13. );
  14. var buildinConstants = ("true|false");
  15. var langClasses = (
  16. "AbstractMethodError|AssertionError|ClassCircularityError|"+
  17. "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
  18. "ExceptionInInitializerError|IllegalAccessError|"+
  19. "IllegalThreadStateException|InstantiationError|InternalError|"+
  20. "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
  21. "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
  22. "SuppressWarnings|TypeNotPresentException|UnknownError|"+
  23. "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
  24. "InstantiationException|IndexOutOfBoundsException|"+
  25. "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
  26. "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
  27. "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
  28. "InterruptedException|NoSuchMethodException|IllegalAccessException|"+
  29. "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
  30. "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
  31. "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
  32. "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
  33. "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
  34. "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
  35. "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
  36. "ArrayStoreException|ClassCastException|LinkageError|"+
  37. "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
  38. "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
  39. "Cloneable|Class|CharSequence|Comparable|String|Object|" +
  40. "Unit|Any|AnyVal|AnyRef|Null|ScalaObject|Singleton|Seq|Iterable|List|" +
  41. "Option|Array|Char|Byte|Int|Long|Nothing|" +
  42. "App|Application|BufferedIterator|BigDecimal|BigInt|Console|Either|" +
  43. "Enumeration|Equiv|Fractional|Function|IndexedSeq|Integral|Iterator|" +
  44. "Map|Numeric|Nil|NotNull|Ordered|Ordering|PartialFunction|PartialOrdering|" +
  45. "Product|Proxy|Range|Responder|Seq|Serializable|Set|Specializable|Stream|" +
  46. "StringContext|Symbol|Traversable|TraversableOnce|Tuple|Vector|Pair|Triple"
  47. );
  48. var keywordMapper = this.createKeywordMapper({
  49. "variable.language": "this",
  50. "keyword": keywords,
  51. "support.function": langClasses,
  52. "constant.language": buildinConstants
  53. }, "identifier");
  54. // regexp must not have capturing parentheses. Use (?:) instead.
  55. // regexps are ordered -> the first match is used
  56. this.$rules = {
  57. "start" : [
  58. {
  59. token : "comment",
  60. regex : "\\/\\/.*$"
  61. },
  62. DocCommentHighlightRules.getStartRule("doc-start"),
  63. {
  64. token : "comment", // multi line comment
  65. regex : "\\/\\*",
  66. next : "comment"
  67. }, {
  68. token : "string.regexp",
  69. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  70. }, {
  71. token : "string",
  72. regex : '"""',
  73. next : "tstring"
  74. }, {
  75. token : "string",
  76. regex : '"(?=.)', // " strings can't span multiple lines
  77. next : "string"
  78. }, {
  79. token : "symbol.constant", // single line
  80. regex : "'[\\w\\d_]+"
  81. }, {
  82. token : "constant.numeric", // hex
  83. regex : "0[xX][0-9a-fA-F]+\\b"
  84. }, {
  85. token : "constant.numeric", // float
  86. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  87. }, {
  88. token : "constant.language.boolean",
  89. regex : "(?:true|false)\\b"
  90. }, {
  91. token : keywordMapper,
  92. // TODO: Unicode escape sequences
  93. // TODO: Unicode identifiers
  94. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  95. }, {
  96. token : "keyword.operator",
  97. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  98. }, {
  99. token : "paren.lparen",
  100. regex : "[[({]"
  101. }, {
  102. token : "paren.rparen",
  103. regex : "[\\])}]"
  104. }, {
  105. token : "text",
  106. regex : "\\s+"
  107. }
  108. ],
  109. "comment" : [
  110. {
  111. token : "comment", // closing comment
  112. regex : ".*?\\*\\/",
  113. next : "start"
  114. }, {
  115. token : "comment", // comment spanning whole line
  116. regex : ".+"
  117. }
  118. ],
  119. "string" : [
  120. {
  121. token : "escape",
  122. regex : '\\\\"'
  123. }, {
  124. token : "string",
  125. regex : '"',
  126. next : "start"
  127. }, {
  128. token : "string.invalid",
  129. regex : '[^"\\\\]*$',
  130. next : "start"
  131. }, {
  132. token : "string",
  133. regex : '[^"\\\\]+'
  134. }
  135. ],
  136. "tstring" : [
  137. {
  138. token : "string", // closing comment
  139. regex : '"{3,5}',
  140. next : "start"
  141. }, {
  142. token : "string", // comment spanning whole line
  143. regex : ".+?"
  144. }
  145. ]
  146. };
  147. this.embedRules(DocCommentHighlightRules, "doc-",
  148. [ DocCommentHighlightRules.getEndRule("start") ]);
  149. };
  150. oop.inherits(ScalaHighlightRules, TextHighlightRules);
  151. exports.ScalaHighlightRules = ScalaHighlightRules;
  152. });