clojure_highlight_rules.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("../lib/oop");
  33. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  34. var ClojureHighlightRules = function() {
  35. var builtinFunctions = (
  36. '* *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* ' +
  37. '*command-line-args* *compile-files* *compile-path* *e *err* *file* ' +
  38. '*flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* ' +
  39. '*print-dup* *print-length* *print-level* *print-meta* *print-readably* ' +
  40. '*read-eval* *source-path* *use-context-classloader* ' +
  41. '*warn-on-reflection* + - -> ->> .. / < <= = ' +
  42. '== > &gt; >= &gt;= accessor aclone ' +
  43. 'add-classpath add-watch agent agent-errors aget alength alias all-ns ' +
  44. 'alter alter-meta! alter-var-root amap ancestors and apply areduce ' +
  45. 'array-map aset aset-boolean aset-byte aset-char aset-double aset-float ' +
  46. 'aset-int aset-long aset-short assert assoc assoc! assoc-in associative? ' +
  47. 'atom await await-for await1 bases bean bigdec bigint binding bit-and ' +
  48. 'bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left ' +
  49. 'bit-shift-right bit-test bit-xor boolean boolean-array booleans ' +
  50. 'bound-fn bound-fn* butlast byte byte-array bytes cast char char-array ' +
  51. 'char-escape-string char-name-string char? chars chunk chunk-append ' +
  52. 'chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? ' +
  53. 'class class? clear-agent-errors clojure-version coll? comment commute ' +
  54. 'comp comparator compare compare-and-set! compile complement concat cond ' +
  55. 'condp conj conj! cons constantly construct-proxy contains? count ' +
  56. 'counted? create-ns create-struct cycle dec decimal? declare definline ' +
  57. 'defmacro defmethod defmulti defn defn- defonce defstruct delay delay? ' +
  58. 'deliver deref derive descendants destructure disj disj! dissoc dissoc! ' +
  59. 'distinct distinct? doall doc dorun doseq dosync dotimes doto double ' +
  60. 'double-array doubles drop drop-last drop-while empty empty? ensure ' +
  61. 'enumeration-seq eval even? every? false? ffirst file-seq filter find ' +
  62. 'find-doc find-ns find-var first float float-array float? floats flush ' +
  63. 'fn fn? fnext for force format future future-call future-cancel ' +
  64. 'future-cancelled? future-done? future? gen-class gen-interface gensym ' +
  65. 'get get-in get-method get-proxy-class get-thread-bindings get-validator ' +
  66. 'hash hash-map hash-set identical? identity if-let if-not ifn? import ' +
  67. 'in-ns inc init-proxy instance? int int-array integer? interleave intern ' +
  68. 'interpose into into-array ints io! isa? iterate iterator-seq juxt key ' +
  69. 'keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list ' +
  70. 'list* list? load load-file load-reader load-string loaded-libs locking ' +
  71. 'long long-array longs loop macroexpand macroexpand-1 make-array ' +
  72. 'make-hierarchy map map? mapcat max max-key memfn memoize merge ' +
  73. 'merge-with meta method-sig methods min min-key mod name namespace neg? ' +
  74. 'newline next nfirst nil? nnext not not-any? not-empty not-every? not= ' +
  75. 'ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ' +
  76. 'ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? ' +
  77. 'or parents partial partition pcalls peek persistent! pmap pop pop! ' +
  78. 'pop-thread-bindings pos? pr pr-str prefer-method prefers ' +
  79. 'primitives-classnames print print-ctor print-doc print-dup print-method ' +
  80. 'print-namespace-doc print-simple print-special-doc print-str printf ' +
  81. 'println println-str prn prn-str promise proxy proxy-call-with-super ' +
  82. 'proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot ' +
  83. 'rand rand-int range ratio? rational? rationalize re-find re-groups ' +
  84. 're-matcher re-matches re-pattern re-seq read read-line read-string ' +
  85. 'reduce ref ref-history-count ref-max-history ref-min-history ref-set ' +
  86. 'refer refer-clojure release-pending-sends rem remove remove-method ' +
  87. 'remove-ns remove-watch repeat repeatedly replace replicate require ' +
  88. 'reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq ' +
  89. 'rsubseq second select-keys send send-off seq seq? seque sequence ' +
  90. 'sequential? set set-validator! set? short short-array shorts ' +
  91. 'shutdown-agents slurp some sort sort-by sorted-map sorted-map-by ' +
  92. 'sorted-set sorted-set-by sorted? special-form-anchor special-symbol? ' +
  93. 'split-at split-with str stream? string? struct struct-map subs subseq ' +
  94. 'subvec supers swap! symbol symbol? sync syntax-symbol-anchor take ' +
  95. 'take-last take-nth take-while test the-ns time to-array to-array-2d ' +
  96. 'trampoline transient tree-seq true? type unchecked-add unchecked-dec ' +
  97. 'unchecked-divide unchecked-inc unchecked-multiply unchecked-negate ' +
  98. 'unchecked-remainder unchecked-subtract underive unquote ' +
  99. 'unquote-splicing update-in update-proxy use val vals var-get var-set ' +
  100. 'var? vary-meta vec vector vector? when when-first when-let when-not ' +
  101. 'while with-bindings with-bindings* with-in-str with-loading-context ' +
  102. 'with-local-vars with-meta with-open with-out-str with-precision xml-seq ' +
  103. 'zero? zipmap'
  104. );
  105. var keywords = ('throw try var ' +
  106. 'def do fn if let loop monitor-enter monitor-exit new quote recur set!'
  107. );
  108. var buildinConstants = ("true false nil");
  109. var keywordMapper = this.createKeywordMapper({
  110. "keyword": keywords,
  111. "constant.language": buildinConstants,
  112. "support.function": builtinFunctions
  113. }, "identifier", false, " ");
  114. // regexp must not have capturing parentheses. Use (?:) instead.
  115. // regexps are ordered -> the first match is used
  116. this.$rules = {
  117. "start" : [
  118. {
  119. token : "comment",
  120. regex : ";.*$"
  121. }, {
  122. token : "keyword", //parens
  123. regex : "[\\(|\\)]"
  124. }, {
  125. token : "keyword", //lists
  126. regex : "[\\'\\(]"
  127. }, {
  128. token : "keyword", //vectors
  129. regex : "[\\[|\\]]"
  130. }, {
  131. token : "keyword", //sets and maps
  132. regex : "[\\{|\\}|\\#\\{|\\#\\}]"
  133. }, {
  134. token : "keyword", // ampersands
  135. regex : '[\\&]'
  136. }, {
  137. token : "keyword", // metadata
  138. regex : '[\\#\\^\\{]'
  139. }, {
  140. token : "keyword", // anonymous fn syntactic sugar
  141. regex : '[\\%]'
  142. }, {
  143. token : "keyword", // deref reader macro
  144. regex : '[@]'
  145. }, {
  146. token : "constant.numeric", // hex
  147. regex : "0[xX][0-9a-fA-F]+\\b"
  148. }, {
  149. token : "constant.numeric", // float
  150. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  151. }, {
  152. token : "constant.language",
  153. regex : '[!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+||=|!=|<=|>=|<>|<|>|!|&&]'
  154. }, {
  155. token : keywordMapper,
  156. regex : "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b"
  157. }, {
  158. token : "string", // single line
  159. regex : '"',
  160. next: "string"
  161. }, {
  162. token : "constant", // symbol
  163. regex : /:[^()\[\]{}'"\^%`,;\s]+/
  164. }, {
  165. token : "string.regexp", //Regular Expressions
  166. regex : '/#"(?:\\.|(?:\\\")|[^\""\n])*"/g'
  167. }
  168. ],
  169. "string" : [
  170. {
  171. token : "constant.language.escape",
  172. regex : "\\\\.|\\\\$"
  173. }, {
  174. token : "string",
  175. regex : '[^"\\\\]+'
  176. }, {
  177. token : "string",
  178. regex : '"',
  179. next : "start"
  180. }
  181. ]
  182. };
  183. };
  184. oop.inherits(ClojureHighlightRules, TextHighlightRules);
  185. exports.ClojureHighlightRules = ClojureHighlightRules;
  186. });