scala_highlight_rules.js 6.1 KB

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