groovy_highlight_rules.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 GroovyHighlightRules = function() {
  7. var keywords = (
  8. "assert|with|abstract|continue|for|new|switch|" +
  9. "assert|default|goto|package|synchronized|" +
  10. "boolean|do|if|private|this|" +
  11. "break|double|implements|protected|throw|" +
  12. "byte|else|import|public|throws|" +
  13. "case|enum|instanceof|return|transient|" +
  14. "catch|extends|int|short|try|" +
  15. "char|final|interface|static|void|" +
  16. "class|finally|long|strictfp|volatile|" +
  17. "def|float|native|super|while"
  18. );
  19. var buildinConstants = (
  20. "null|Infinity|NaN|undefined"
  21. );
  22. var langClasses = (
  23. "AbstractMethodError|AssertionError|ClassCircularityError|"+
  24. "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+
  25. "ExceptionInInitializerError|IllegalAccessError|"+
  26. "IllegalThreadStateException|InstantiationError|InternalError|"+
  27. "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+
  28. "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+
  29. "SuppressWarnings|TypeNotPresentException|UnknownError|"+
  30. "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+
  31. "InstantiationException|IndexOutOfBoundsException|"+
  32. "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+
  33. "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+
  34. "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+
  35. "InterruptedException|NoSuchMethodException|IllegalAccessException|"+
  36. "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+
  37. "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+
  38. "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+
  39. "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+
  40. "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+
  41. "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+
  42. "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+
  43. "ArrayStoreException|ClassCastException|LinkageError|"+
  44. "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+
  45. "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+
  46. "Cloneable|Class|CharSequence|Comparable|String|Object"
  47. );
  48. // TODO var importClasses = "";
  49. var keywordMapper = this.createKeywordMapper({
  50. "variable.language": "this",
  51. "keyword": keywords,
  52. "support.function": langClasses,
  53. "constant.language": buildinConstants
  54. }, "identifier");
  55. // regexp must not have capturing parentheses. Use (?:) instead.
  56. // regexps are ordered -> the first match is used
  57. this.$rules = {
  58. "start" : [
  59. {
  60. token : "comment",
  61. regex : "\\/\\/.*$"
  62. },
  63. DocCommentHighlightRules.getStartRule("doc-start"),
  64. {
  65. token : "comment", // multi line comment
  66. regex : "\\/\\*",
  67. next : "comment"
  68. }, {
  69. token : "string.regexp",
  70. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  71. }, {
  72. token : "string",
  73. regex : '"""',
  74. next : "qqstring"
  75. }, {
  76. token : "string",
  77. regex : "'''",
  78. next : "qstring"
  79. }, {
  80. token : "string", // single line
  81. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  82. }, {
  83. token : "string", // single line
  84. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  85. }, {
  86. token : "constant.numeric", // hex
  87. regex : "0[xX][0-9a-fA-F]+\\b"
  88. }, {
  89. token : "constant.numeric", // float
  90. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  91. }, {
  92. token : "constant.language.boolean",
  93. regex : "(?:true|false)\\b"
  94. }, {
  95. token : keywordMapper,
  96. // TODO: Unicode escape sequences
  97. // TODO: Unicode identifiers
  98. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  99. }, {
  100. token : "keyword.operator",
  101. regex : "\\?:|\\?\\.|\\*\\.|<=>|=~|==~|\\.@|\\*\\.@|\\.&|as|in|is|!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  102. }, {
  103. token : "lparen",
  104. regex : "[[({]"
  105. }, {
  106. token : "rparen",
  107. regex : "[\\])}]"
  108. }, {
  109. token : "text",
  110. regex : "\\s+"
  111. }
  112. ],
  113. "comment" : [
  114. {
  115. token : "comment", // closing comment
  116. regex : ".*?\\*\\/",
  117. next : "start"
  118. }, {
  119. token : "comment", // comment spanning whole line
  120. regex : ".+"
  121. }
  122. ],
  123. "qqstring" : [
  124. {
  125. token : "constant.language.escape",
  126. regex : /\\(?:u[0-9A-Fa-f]{4}|.|$)/
  127. }, {
  128. token : "constant.language.escape",
  129. regex : /\$[\w\d]+/
  130. }, {
  131. token : "constant.language.escape",
  132. regex : /\$\{[^"\}]+\}?/
  133. }, {
  134. token : "string",
  135. regex : '"{3,5}',
  136. next : "start"
  137. }, {
  138. token : "string",
  139. regex : '.+?'
  140. }
  141. ],
  142. "qstring" : [
  143. {
  144. token : "constant.language.escape",
  145. regex : /\\(?:u[0-9A-Fa-f]{4}|.|$)/
  146. }, {
  147. token : "string",
  148. regex : "'{3,5}",
  149. next : "start"
  150. }, {
  151. token : "string",
  152. regex : ".+?"
  153. }
  154. ]
  155. };
  156. this.embedRules(DocCommentHighlightRules, "doc-",
  157. [ DocCommentHighlightRules.getEndRule("start") ]);
  158. };
  159. oop.inherits(GroovyHighlightRules, TextHighlightRules);
  160. exports.GroovyHighlightRules = GroovyHighlightRules;
  161. });