aaf660b90ac538fc99a895fa3834507c.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. ace.define("ace/mode/clojure_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var ClojureHighlightRules = function () {
  5. var builtinFunctions = ('* *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* ' +
  6. '*command-line-args* *compile-files* *compile-path* *e *err* *file* ' +
  7. '*flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* ' +
  8. '*print-dup* *print-length* *print-level* *print-meta* *print-readably* ' +
  9. '*read-eval* *source-path* *use-context-classloader* ' +
  10. '*warn-on-reflection* + - -> ->> .. / < <= = ' +
  11. '== > &gt; >= &gt;= accessor aclone ' +
  12. 'add-classpath add-watch agent agent-errors aget alength alias all-ns ' +
  13. 'alter alter-meta! alter-var-root amap ancestors and apply areduce ' +
  14. 'array-map aset aset-boolean aset-byte aset-char aset-double aset-float ' +
  15. 'aset-int aset-long aset-short assert assoc assoc! assoc-in associative? ' +
  16. 'atom await await-for await1 bases bean bigdec bigint binding bit-and ' +
  17. 'bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left ' +
  18. 'bit-shift-right bit-test bit-xor boolean boolean-array booleans ' +
  19. 'bound-fn bound-fn* butlast byte byte-array bytes cast char char-array ' +
  20. 'char-escape-string char-name-string char? chars chunk chunk-append ' +
  21. 'chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? ' +
  22. 'class class? clear-agent-errors clojure-version coll? comment commute ' +
  23. 'comp comparator compare compare-and-set! compile complement concat cond ' +
  24. 'condp conj conj! cons constantly construct-proxy contains? count ' +
  25. 'counted? create-ns create-struct cycle dec decimal? declare definline ' +
  26. 'defmacro defmethod defmulti defn defn- defonce defstruct delay delay? ' +
  27. 'deliver deref derive descendants destructure disj disj! dissoc dissoc! ' +
  28. 'distinct distinct? doall doc dorun doseq dosync dotimes doto double ' +
  29. 'double-array doubles drop drop-last drop-while empty empty? ensure ' +
  30. 'enumeration-seq eval even? every? false? ffirst file-seq filter find ' +
  31. 'find-doc find-ns find-var first float float-array float? floats flush ' +
  32. 'fn fn? fnext for force format future future-call future-cancel ' +
  33. 'future-cancelled? future-done? future? gen-class gen-interface gensym ' +
  34. 'get get-in get-method get-proxy-class get-thread-bindings get-validator ' +
  35. 'hash hash-map hash-set identical? identity if-let if-not ifn? import ' +
  36. 'in-ns inc init-proxy instance? int int-array integer? interleave intern ' +
  37. 'interpose into into-array ints io! isa? iterate iterator-seq juxt key ' +
  38. 'keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list ' +
  39. 'list* list? load load-file load-reader load-string loaded-libs locking ' +
  40. 'long long-array longs loop macroexpand macroexpand-1 make-array ' +
  41. 'make-hierarchy map map? mapcat max max-key memfn memoize merge ' +
  42. 'merge-with meta method-sig methods min min-key mod name namespace neg? ' +
  43. 'newline next nfirst nil? nnext not not-any? not-empty not-every? not= ' +
  44. 'ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ' +
  45. 'ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? ' +
  46. 'or parents partial partition pcalls peek persistent! pmap pop pop! ' +
  47. 'pop-thread-bindings pos? pr pr-str prefer-method prefers ' +
  48. 'primitives-classnames print print-ctor print-doc print-dup print-method ' +
  49. 'print-namespace-doc print-simple print-special-doc print-str printf ' +
  50. 'println println-str prn prn-str promise proxy proxy-call-with-super ' +
  51. 'proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot ' +
  52. 'rand rand-int range ratio? rational? rationalize re-find re-groups ' +
  53. 're-matcher re-matches re-pattern re-seq read read-line read-string ' +
  54. 'reduce ref ref-history-count ref-max-history ref-min-history ref-set ' +
  55. 'refer refer-clojure release-pending-sends rem remove remove-method ' +
  56. 'remove-ns remove-watch repeat repeatedly replace replicate require ' +
  57. 'reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq ' +
  58. 'rsubseq second select-keys send send-off seq seq? seque sequence ' +
  59. 'sequential? set set-validator! set? short short-array shorts ' +
  60. 'shutdown-agents slurp some sort sort-by sorted-map sorted-map-by ' +
  61. 'sorted-set sorted-set-by sorted? special-form-anchor special-symbol? ' +
  62. 'split-at split-with str stream? string? struct struct-map subs subseq ' +
  63. 'subvec supers swap! symbol symbol? sync syntax-symbol-anchor take ' +
  64. 'take-last take-nth take-while test the-ns time to-array to-array-2d ' +
  65. 'trampoline transient tree-seq true? type unchecked-add unchecked-dec ' +
  66. 'unchecked-divide unchecked-inc unchecked-multiply unchecked-negate ' +
  67. 'unchecked-remainder unchecked-subtract underive unquote ' +
  68. 'unquote-splicing update-in update-proxy use val vals var-get var-set ' +
  69. 'var? vary-meta vec vector vector? when when-first when-let when-not ' +
  70. 'while with-bindings with-bindings* with-in-str with-loading-context ' +
  71. 'with-local-vars with-meta with-open with-out-str with-precision xml-seq ' +
  72. 'zero? zipmap');
  73. var keywords = ('throw try var ' +
  74. 'def do fn if let loop monitor-enter monitor-exit new quote recur set!');
  75. var buildinConstants = ("true false nil");
  76. var keywordMapper = this.createKeywordMapper({
  77. "keyword": keywords,
  78. "constant.language": buildinConstants,
  79. "support.function": builtinFunctions
  80. }, "identifier", false, " ");
  81. this.$rules = {
  82. "start": [
  83. {
  84. token: "comment",
  85. regex: ";.*$"
  86. }, {
  87. token: "keyword", //parens
  88. regex: "[\\(|\\)]"
  89. }, {
  90. token: "keyword", //lists
  91. regex: "[\\'\\(]"
  92. }, {
  93. token: "keyword", //vectors
  94. regex: "[\\[|\\]]"
  95. }, {
  96. token: "string.regexp", //Regular Expressions
  97. regex: '#"',
  98. next: "regex"
  99. }, {
  100. token: "keyword", //sets and maps
  101. regex: "[\\{|\\}|\\#\\{|\\#\\}]"
  102. }, {
  103. token: "keyword", // ampersands
  104. regex: '[\\&]'
  105. }, {
  106. token: "keyword", // metadata
  107. regex: '[\\#\\^\\{]'
  108. }, {
  109. token: "keyword", // anonymous fn syntactic sugar
  110. regex: '[\\%]'
  111. }, {
  112. token: "keyword", // deref reader macro
  113. regex: '[@]'
  114. }, {
  115. token: "constant.numeric", // hex
  116. regex: "0[xX][0-9a-fA-F]+\\b"
  117. }, {
  118. token: "constant.numeric", // float
  119. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  120. }, {
  121. token: "constant.language",
  122. regex: '[!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+||=|!=|<=|>=|<>|<|>|!|&&]'
  123. }, {
  124. token: keywordMapper,
  125. regex: "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b"
  126. }, {
  127. token: "string", // single line
  128. regex: '"',
  129. next: "string"
  130. }, {
  131. token: "constant", // symbol
  132. regex: /:[^()\[\]{}'"\^%`,;\s]+/
  133. }
  134. ],
  135. "string": [
  136. {
  137. token: "constant.language.escape",
  138. regex: "\\\\.|\\\\$"
  139. }, {
  140. token: "string",
  141. regex: '"',
  142. next: "start"
  143. }, {
  144. defaultToken: "string"
  145. }
  146. ],
  147. "regex": [
  148. {
  149. token: "regexp.keyword.operator",
  150. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  151. }, {
  152. token: "string.regexp",
  153. regex: '"',
  154. next: "start"
  155. }, {
  156. token: "constant.language.escape",
  157. regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
  158. }, {
  159. token: "constant.language.delimiter",
  160. regex: /\|/
  161. }, {
  162. token: "constant.language.escape",
  163. regex: /\[\^?/,
  164. next: "regex_character_class"
  165. }, {
  166. defaultToken: "string.regexp"
  167. }
  168. ],
  169. "regex_character_class": [
  170. {
  171. token: "regexp.charclass.keyword.operator",
  172. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  173. }, {
  174. token: "constant.language.escape",
  175. regex: "]",
  176. next: "regex"
  177. }, {
  178. token: "constant.language.escape",
  179. regex: "-"
  180. }, {
  181. defaultToken: "string.regexp.charachterclass"
  182. }
  183. ]
  184. };
  185. };
  186. oop.inherits(ClojureHighlightRules, TextHighlightRules);
  187. exports.ClojureHighlightRules = ClojureHighlightRules;
  188. });
  189. ace.define("ace/mode/matching_parens_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  190. var Range = require("../range").Range;
  191. var MatchingParensOutdent = function () { };
  192. (function () {
  193. this.checkOutdent = function (line, input) {
  194. if (!/^\s+$/.test(line))
  195. return false;
  196. return /^\s*\)/.test(input);
  197. };
  198. this.autoOutdent = function (doc, row) {
  199. var line = doc.getLine(row);
  200. var match = line.match(/^(\s*\))/);
  201. if (!match)
  202. return 0;
  203. var column = match[1].length;
  204. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  205. if (!openBracePos || openBracePos.row == row)
  206. return 0;
  207. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  208. doc.replace(new Range(row, 0, row, column - 1), indent);
  209. };
  210. this.$getIndent = function (line) {
  211. var match = line.match(/^(\s+)/);
  212. if (match) {
  213. return match[1];
  214. }
  215. return "";
  216. };
  217. }).call(MatchingParensOutdent.prototype);
  218. exports.MatchingParensOutdent = MatchingParensOutdent;
  219. });
  220. ace.define("ace/mode/clojure",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/clojure_highlight_rules","ace/mode/matching_parens_outdent"], function(require, exports, module){"use strict";
  221. var oop = require("../lib/oop");
  222. var TextMode = require("./text").Mode;
  223. var ClojureHighlightRules = require("./clojure_highlight_rules").ClojureHighlightRules;
  224. var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensOutdent;
  225. var Mode = function () {
  226. this.HighlightRules = ClojureHighlightRules;
  227. this.$outdent = new MatchingParensOutdent();
  228. this.$behaviour = this.$defaultBehaviour;
  229. };
  230. oop.inherits(Mode, TextMode);
  231. (function () {
  232. this.lineCommentStart = ";";
  233. this.minorIndentFunctions = ["defn", "defn-", "defmacro", "def", "deftest", "testing"];
  234. this.$toIndent = function (str) {
  235. return str.split('').map(function (ch) {
  236. if (/\s/.exec(ch)) {
  237. return ch;
  238. }
  239. else {
  240. return ' ';
  241. }
  242. }).join('');
  243. };
  244. this.$calculateIndent = function (line, tab) {
  245. var baseIndent = this.$getIndent(line);
  246. var delta = 0;
  247. var isParen, ch;
  248. for (var i = line.length - 1; i >= 0; i--) {
  249. ch = line[i];
  250. if (ch === '(') {
  251. delta--;
  252. isParen = true;
  253. }
  254. else if (ch === '(' || ch === '[' || ch === '{') {
  255. delta--;
  256. isParen = false;
  257. }
  258. else if (ch === ')' || ch === ']' || ch === '}') {
  259. delta++;
  260. }
  261. if (delta < 0) {
  262. break;
  263. }
  264. }
  265. if (delta < 0 && isParen) {
  266. i += 1;
  267. var iBefore = i;
  268. var fn = '';
  269. while (true) {
  270. ch = line[i];
  271. if (ch === ' ' || ch === '\t') {
  272. if (this.minorIndentFunctions.indexOf(fn) !== -1) {
  273. return this.$toIndent(line.substring(0, iBefore - 1) + tab);
  274. }
  275. else {
  276. return this.$toIndent(line.substring(0, i + 1));
  277. }
  278. }
  279. else if (ch === undefined) {
  280. return this.$toIndent(line.substring(0, iBefore - 1) + tab);
  281. }
  282. fn += line[i];
  283. i++;
  284. }
  285. }
  286. else if (delta < 0 && !isParen) {
  287. return this.$toIndent(line.substring(0, i + 1));
  288. }
  289. else if (delta > 0) {
  290. baseIndent = baseIndent.substring(0, baseIndent.length - tab.length);
  291. return baseIndent;
  292. }
  293. else {
  294. return baseIndent;
  295. }
  296. };
  297. this.getNextLineIndent = function (state, line, tab) {
  298. return this.$calculateIndent(line, tab);
  299. };
  300. this.checkOutdent = function (state, line, input) {
  301. return this.$outdent.checkOutdent(line, input);
  302. };
  303. this.autoOutdent = function (state, doc, row) {
  304. this.$outdent.autoOutdent(doc, row);
  305. };
  306. this.$id = "ace/mode/clojure";
  307. this.snippetFileId = "ace/snippets/clojure";
  308. }).call(Mode.prototype);
  309. exports.Mode = Mode;
  310. }); (function() {
  311. ace.require(["ace/mode/clojure"], function(m) {
  312. if (typeof module == "object" && typeof exports == "object" && module) {
  313. module.exports = m;
  314. }
  315. });
  316. })();