clojure.js 4.4 KB

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