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