]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/clojure.js
Initial commit.
[flow-web.git] / static / highlight / languages / clojure.js
1 /*! `clojure` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Clojure
8 Description: Clojure syntax (based on lisp.js)
9 Author: mfornos
10 Website: https://clojure.org
11 Category: lisp
12 */
13
14 /** @type LanguageFn */
15 function clojure(hljs) {
16 const SYMBOLSTART = 'a-zA-Z_\\-!.?+*=<>&\'';
17 const SYMBOL_RE = '[#]?[' + SYMBOLSTART + '][' + SYMBOLSTART + '0-9/;:$#]*';
18 const globals = 'def defonce defprotocol defstruct defmulti defmethod defn- defn defmacro deftype defrecord';
19 const keywords = {
20 $pattern: SYMBOL_RE,
21 built_in:
22 // Clojure keywords
23 globals + ' '
24 + 'cond apply if-not if-let if not not= =|0 <|0 >|0 <=|0 >=|0 ==|0 +|0 /|0 *|0 -|0 rem '
25 + 'quot neg? pos? delay? symbol? keyword? true? false? integer? empty? coll? list? '
26 + 'set? ifn? fn? associative? sequential? sorted? counted? reversible? number? decimal? '
27 + 'class? distinct? isa? float? rational? reduced? ratio? odd? even? char? seq? vector? '
28 + 'string? map? nil? contains? zero? instance? not-every? not-any? libspec? -> ->> .. . '
29 + 'inc compare do dotimes mapcat take remove take-while drop letfn drop-last take-last '
30 + 'drop-while while intern condp case reduced cycle split-at split-with repeat replicate '
31 + 'iterate range merge zipmap declare line-seq sort comparator sort-by dorun doall nthnext '
32 + 'nthrest partition eval doseq await await-for let agent atom send send-off release-pending-sends '
33 + 'add-watch mapv filterv remove-watch agent-error restart-agent set-error-handler error-handler '
34 + 'set-error-mode! error-mode shutdown-agents quote var fn loop recur throw try monitor-enter '
35 + 'monitor-exit macroexpand macroexpand-1 for dosync and or '
36 + 'when when-not when-let comp juxt partial sequence memoize constantly complement identity assert '
37 + 'peek pop doto proxy first rest cons cast coll last butlast '
38 + 'sigs reify second ffirst fnext nfirst nnext meta with-meta ns in-ns create-ns import '
39 + 'refer keys select-keys vals key val rseq name namespace promise into transient persistent! conj! '
40 + 'assoc! dissoc! pop! disj! use class type num float double short byte boolean bigint biginteger '
41 + 'bigdec print-method print-dup throw-if printf format load compile get-in update-in pr pr-on newline '
42 + 'flush read slurp read-line subvec with-open memfn time re-find re-groups rand-int rand mod locking '
43 + 'assert-valid-fdecl alias resolve ref deref refset swap! reset! set-validator! compare-and-set! alter-meta! '
44 + 'reset-meta! commute get-validator alter ref-set ref-history-count ref-min-history ref-max-history ensure sync io! '
45 + 'new next conj set! to-array future future-call into-array aset gen-class reduce map filter find empty '
46 + 'hash-map hash-set sorted-map sorted-map-by sorted-set sorted-set-by vec vector seq flatten reverse assoc dissoc list '
47 + 'disj get union difference intersection extend extend-type extend-protocol int nth delay count concat chunk chunk-buffer '
48 + 'chunk-append chunk-first chunk-rest max min dec unchecked-inc-int unchecked-inc unchecked-dec-inc unchecked-dec unchecked-negate '
49 + 'unchecked-add-int unchecked-add unchecked-subtract-int unchecked-subtract chunk-next chunk-cons chunked-seq? prn vary-meta '
50 + 'lazy-seq spread list* str find-keyword keyword symbol gensym force rationalize'
51 };
52
53 const SYMBOL = {
54 begin: SYMBOL_RE,
55 relevance: 0
56 };
57 const NUMBER = {
58 scope: 'number',
59 relevance: 0,
60 variants: [
61 { match: /[-+]?0[xX][0-9a-fA-F]+N?/ }, // hexadecimal // 0x2a
62 { match: /[-+]?0[0-7]+N?/ }, // octal // 052
63 { match: /[-+]?[1-9][0-9]?[rR][0-9a-zA-Z]+N?/ }, // variable radix from 2 to 36 // 2r101010, 8r52, 36r16
64 { match: /[-+]?[0-9]+\/[0-9]+N?/ }, // ratio // 1/2
65 { match: /[-+]?[0-9]+((\.[0-9]*([eE][+-]?[0-9]+)?M?)|([eE][+-]?[0-9]+M?|M))/ }, // float // 0.42 4.2E-1M 42E1 42M
66 { match: /[-+]?([1-9][0-9]*|0)N?/ }, // int (don't match leading 0) // 42 42N
67 ]
68 };
69 const CHARACTER = {
70 scope: 'character',
71 variants: [
72 { match: /\\o[0-3]?[0-7]{1,2}/ }, // Unicode Octal 0 - 377
73 { match: /\\u[0-9a-fA-F]{4}/ }, // Unicode Hex 0000 - FFFF
74 { match: /\\(newline|space|tab|formfeed|backspace|return)/ }, // special characters
75 {
76 match: /\\\S/,
77 relevance: 0
78 } // any non-whitespace char
79 ]
80 };
81 const REGEX = {
82 scope: 'regex',
83 begin: /#"/,
84 end: /"/,
85 contains: [ hljs.BACKSLASH_ESCAPE ]
86 };
87 const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null });
88 const COMMA = {
89 scope: 'punctuation',
90 match: /,/,
91 relevance: 0
92 };
93 const COMMENT = hljs.COMMENT(
94 ';',
95 '$',
96 { relevance: 0 }
97 );
98 const LITERAL = {
99 className: 'literal',
100 begin: /\b(true|false|nil)\b/
101 };
102 const COLLECTION = {
103 begin: "\\[|(#::?" + SYMBOL_RE + ")?\\{",
104 end: '[\\]\\}]',
105 relevance: 0
106 };
107 const KEY = {
108 className: 'symbol',
109 begin: '[:]{1,2}' + SYMBOL_RE
110 };
111 const LIST = {
112 begin: '\\(',
113 end: '\\)'
114 };
115 const BODY = {
116 endsWithParent: true,
117 relevance: 0
118 };
119 const NAME = {
120 keywords: keywords,
121 className: 'name',
122 begin: SYMBOL_RE,
123 relevance: 0,
124 starts: BODY
125 };
126 const DEFAULT_CONTAINS = [
127 COMMA,
128 LIST,
129 CHARACTER,
130 REGEX,
131 STRING,
132 COMMENT,
133 KEY,
134 COLLECTION,
135 NUMBER,
136 LITERAL,
137 SYMBOL
138 ];
139
140 const GLOBAL = {
141 beginKeywords: globals,
142 keywords: {
143 $pattern: SYMBOL_RE,
144 keyword: globals
145 },
146 end: '(\\[|#|\\d|"|:|\\{|\\)|\\(|$)',
147 contains: [
148 {
149 className: 'title',
150 begin: SYMBOL_RE,
151 relevance: 0,
152 excludeEnd: true,
153 // we can only have a single title
154 endsParent: true
155 }
156 ].concat(DEFAULT_CONTAINS)
157 };
158
159 LIST.contains = [
160 GLOBAL,
161 NAME,
162 BODY
163 ];
164 BODY.contains = DEFAULT_CONTAINS;
165 COLLECTION.contains = DEFAULT_CONTAINS;
166
167 return {
168 name: 'Clojure',
169 aliases: [
170 'clj',
171 'edn'
172 ],
173 illegal: /\S/,
174 contains: [
175 COMMA,
176 LIST,
177 CHARACTER,
178 REGEX,
179 STRING,
180 COMMENT,
181 KEY,
182 COLLECTION,
183 NUMBER,
184 LITERAL
185 ]
186 };
187 }
188
189 return clojure;
190
191 })();
192
193 hljs.registerLanguage('clojure', hljsGrammar);
194 })();