1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function clojure(hljs) {
|
11 | const SYMBOLSTART = 'a-zA-Z_\\-!.?+*=<>&#\'';
|
12 | const SYMBOL_RE = '[' + SYMBOLSTART + '][' + SYMBOLSTART + '0-9/;:]*';
|
13 | const globals = 'def defonce defprotocol defstruct defmulti defmethod defn- defn defmacro deftype defrecord';
|
14 | const keywords = {
|
15 | $pattern: SYMBOL_RE,
|
16 | built_in:
|
17 |
|
18 | globals + ' ' +
|
19 | 'cond apply if-not if-let if not not= =|0 <|0 >|0 <=|0 >=|0 ==|0 +|0 /|0 *|0 -|0 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 | const SIMPLE_NUMBER_RE = '[-+]?\\d+(\\.\\d+)?';
|
49 |
|
50 | const SYMBOL = {
|
51 | begin: SYMBOL_RE,
|
52 | relevance: 0
|
53 | };
|
54 | const NUMBER = {
|
55 | className: 'number',
|
56 | begin: SIMPLE_NUMBER_RE,
|
57 | relevance: 0
|
58 | };
|
59 | const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {
|
60 | illegal: null
|
61 | });
|
62 | const COMMENT = hljs.COMMENT(
|
63 | ';',
|
64 | '$',
|
65 | {
|
66 | relevance: 0
|
67 | }
|
68 | );
|
69 | const LITERAL = {
|
70 | className: 'literal',
|
71 | begin: /\b(true|false|nil)\b/
|
72 | };
|
73 | const COLLECTION = {
|
74 | begin: '[\\[\\{]',
|
75 | end: '[\\]\\}]',
|
76 | relevance: 0
|
77 | };
|
78 | const HINT = {
|
79 | className: 'comment',
|
80 | begin: '\\^' + SYMBOL_RE
|
81 | };
|
82 | const HINT_COL = hljs.COMMENT('\\^\\{', '\\}');
|
83 | const KEY = {
|
84 | className: 'symbol',
|
85 | begin: '[:]{1,2}' + SYMBOL_RE
|
86 | };
|
87 | const LIST = {
|
88 | begin: '\\(',
|
89 | end: '\\)'
|
90 | };
|
91 | const BODY = {
|
92 | endsWithParent: true,
|
93 | relevance: 0
|
94 | };
|
95 | const NAME = {
|
96 | keywords: keywords,
|
97 | className: 'name',
|
98 | begin: SYMBOL_RE,
|
99 | relevance: 0,
|
100 | starts: BODY
|
101 | };
|
102 | const DEFAULT_CONTAINS = [
|
103 | LIST,
|
104 | STRING,
|
105 | HINT,
|
106 | HINT_COL,
|
107 | COMMENT,
|
108 | KEY,
|
109 | COLLECTION,
|
110 | NUMBER,
|
111 | LITERAL,
|
112 | SYMBOL
|
113 | ];
|
114 |
|
115 | const GLOBAL = {
|
116 | beginKeywords: globals,
|
117 | keywords: {
|
118 | $pattern: SYMBOL_RE,
|
119 | keyword: globals
|
120 | },
|
121 | end: '(\\[|#|\\d|"|:|\\{|\\)|\\(|$)',
|
122 | contains: [
|
123 | {
|
124 | className: 'title',
|
125 | begin: SYMBOL_RE,
|
126 | relevance: 0,
|
127 | excludeEnd: true,
|
128 |
|
129 | endsParent: true
|
130 | }
|
131 | ].concat(DEFAULT_CONTAINS)
|
132 | };
|
133 |
|
134 | LIST.contains = [
|
135 | hljs.COMMENT('comment', ''),
|
136 | GLOBAL,
|
137 | NAME,
|
138 | BODY
|
139 | ];
|
140 | BODY.contains = DEFAULT_CONTAINS;
|
141 | COLLECTION.contains = DEFAULT_CONTAINS;
|
142 | HINT_COL.contains = [ COLLECTION ];
|
143 |
|
144 | return {
|
145 | name: 'Clojure',
|
146 | aliases: [ 'clj', 'edn' ],
|
147 | illegal: /\S/,
|
148 | contains: [
|
149 | LIST,
|
150 | STRING,
|
151 | HINT,
|
152 | HINT_COL,
|
153 | COMMENT,
|
154 | KEY,
|
155 | COLLECTION,
|
156 | NUMBER,
|
157 | LITERAL
|
158 | ]
|
159 | };
|
160 | }
|
161 |
|
162 | export { clojure as default };
|