clojure.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Language: Clojure
  3. Description: Clojure syntax (based on lisp.js)
  4. Author: mfornos
  5. Category: lisp
  6. */
  7. function(hljs) {
  8. var keywords = {
  9. 'builtin-name':
  10. // Clojure keywords
  11. 'def defonce cond apply if-not if-let if not not= = < > <= >= == + / * - rem '+
  12. 'quot neg? pos? delay? symbol? keyword? true? false? integer? empty? coll? list? '+
  13. 'set? ifn? fn? associative? sequential? sorted? counted? reversible? number? decimal? '+
  14. 'class? distinct? isa? float? rational? reduced? ratio? odd? even? char? seq? vector? '+
  15. 'string? map? nil? contains? zero? instance? not-every? not-any? libspec? -> ->> .. . '+
  16. 'inc compare do dotimes mapcat take remove take-while drop letfn drop-last take-last '+
  17. 'drop-while while intern condp case reduced cycle split-at split-with repeat replicate '+
  18. 'iterate range merge zipmap declare line-seq sort comparator sort-by dorun doall nthnext '+
  19. 'nthrest partition eval doseq await await-for let agent atom send send-off release-pending-sends '+
  20. 'add-watch mapv filterv remove-watch agent-error restart-agent set-error-handler error-handler '+
  21. 'set-error-mode! error-mode shutdown-agents quote var fn loop recur throw try monitor-enter '+
  22. 'monitor-exit defmacro defn defn- macroexpand macroexpand-1 for dosync and or '+
  23. 'when when-not when-let comp juxt partial sequence memoize constantly complement identity assert '+
  24. 'peek pop doto proxy defstruct first rest cons defprotocol cast coll deftype defrecord last butlast '+
  25. 'sigs reify second ffirst fnext nfirst nnext defmulti defmethod meta with-meta ns in-ns create-ns import '+
  26. 'refer keys select-keys vals key val rseq name namespace promise into transient persistent! conj! '+
  27. 'assoc! dissoc! pop! disj! use class type num float double short byte boolean bigint biginteger '+
  28. 'bigdec print-method print-dup throw-if printf format load compile get-in update-in pr pr-on newline '+
  29. 'flush read slurp read-line subvec with-open memfn time re-find re-groups rand-int rand mod locking '+
  30. 'assert-valid-fdecl alias resolve ref deref refset swap! reset! set-validator! compare-and-set! alter-meta! '+
  31. 'reset-meta! commute get-validator alter ref-set ref-history-count ref-min-history ref-max-history ensure sync io! '+
  32. 'new next conj set! to-array future future-call into-array aset gen-class reduce map filter find empty '+
  33. 'hash-map hash-set sorted-map sorted-map-by sorted-set sorted-set-by vec vector seq flatten reverse assoc dissoc list '+
  34. 'disj get union difference intersection extend extend-type extend-protocol int nth delay count concat chunk chunk-buffer '+
  35. 'chunk-append chunk-first chunk-rest max min dec unchecked-inc-int unchecked-inc unchecked-dec-inc unchecked-dec unchecked-negate '+
  36. 'unchecked-add-int unchecked-add unchecked-subtract-int unchecked-subtract chunk-next chunk-cons chunked-seq? prn vary-meta '+
  37. 'lazy-seq spread list* str find-keyword keyword symbol gensym force rationalize'
  38. };
  39. var SYMBOLSTART = 'a-zA-Z_\\-!.?+*=<>&#\'';
  40. var SYMBOL_RE = '[' + SYMBOLSTART + '][' + SYMBOLSTART + '0-9/;:]*';
  41. var SIMPLE_NUMBER_RE = '[-+]?\\d+(\\.\\d+)?';
  42. var SYMBOL = {
  43. begin: SYMBOL_RE,
  44. relevance: 0
  45. };
  46. var NUMBER = {
  47. className: 'number', begin: SIMPLE_NUMBER_RE,
  48. relevance: 0
  49. };
  50. var STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null});
  51. var COMMENT = hljs.COMMENT(
  52. ';',
  53. '$',
  54. {
  55. relevance: 0
  56. }
  57. );
  58. var LITERAL = {
  59. className: 'literal',
  60. begin: /\b(true|false|nil)\b/
  61. };
  62. var COLLECTION = {
  63. begin: '[\\[\\{]', end: '[\\]\\}]'
  64. };
  65. var HINT = {
  66. className: 'comment',
  67. begin: '\\^' + SYMBOL_RE
  68. };
  69. var HINT_COL = hljs.COMMENT('\\^\\{', '\\}');
  70. var KEY = {
  71. className: 'symbol',
  72. begin: '[:]{1,2}' + SYMBOL_RE
  73. };
  74. var LIST = {
  75. begin: '\\(', end: '\\)'
  76. };
  77. var BODY = {
  78. endsWithParent: true,
  79. relevance: 0
  80. };
  81. var NAME = {
  82. keywords: keywords,
  83. lexemes: SYMBOL_RE,
  84. className: 'name', begin: SYMBOL_RE,
  85. starts: BODY
  86. };
  87. var DEFAULT_CONTAINS = [LIST, STRING, HINT, HINT_COL, COMMENT, KEY, COLLECTION, NUMBER, LITERAL, SYMBOL];
  88. LIST.contains = [hljs.COMMENT('comment', ''), NAME, BODY];
  89. BODY.contains = DEFAULT_CONTAINS;
  90. COLLECTION.contains = DEFAULT_CONTAINS;
  91. return {
  92. aliases: ['clj'],
  93. illegal: /\S/,
  94. contains: [LIST, STRING, HINT, HINT_COL, COMMENT, KEY, COLLECTION, NUMBER, LITERAL]
  95. }
  96. }