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