]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/julia.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / julia.js
1 /*! `julia` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: Julia
7 Description: Julia is a high-level, high-performance, dynamic programming language.
8 Author: Kenta Sato <bicycle1885@gmail.com>
9 Contributors: Alex Arslan <ararslan@comcast.net>, Fredrik Ekre <ekrefredrik@gmail.com>
10 Website: https://julialang.org
11 Category: scientific
12 */
13
14 function julia(hljs) {
15 // Since there are numerous special names in Julia, it is too much trouble
16 // to maintain them by hand. Hence these names (i.e. keywords, literals and
17 // built-ins) are automatically generated from Julia 1.5.2 itself through
18 // the following scripts for each.
19
20 // ref: https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names
21 const VARIABLE_NAME_RE = '[A-Za-z_\\u00A1-\\uFFFF][A-Za-z_0-9\\u00A1-\\uFFFF]*';
22
23 // # keyword generator, multi-word keywords handled manually below (Julia 1.5.2)
24 // import REPL.REPLCompletions
25 // res = String["in", "isa", "where"]
26 // for kw in collect(x.keyword for x in REPLCompletions.complete_keyword(""))
27 // if !(contains(kw, " ") || kw == "struct")
28 // push!(res, kw)
29 // end
30 // end
31 // sort!(unique!(res))
32 // foreach(x -> println("\'", x, "\',"), res)
33 const KEYWORD_LIST = [
34 'baremodule',
35 'begin',
36 'break',
37 'catch',
38 'ccall',
39 'const',
40 'continue',
41 'do',
42 'else',
43 'elseif',
44 'end',
45 'export',
46 'false',
47 'finally',
48 'for',
49 'function',
50 'global',
51 'if',
52 'import',
53 'in',
54 'isa',
55 'let',
56 'local',
57 'macro',
58 'module',
59 'quote',
60 'return',
61 'true',
62 'try',
63 'using',
64 'where',
65 'while',
66 ];
67
68 // # literal generator (Julia 1.5.2)
69 // import REPL.REPLCompletions
70 // res = String["true", "false"]
71 // for compl in filter!(x -> isa(x, REPLCompletions.ModuleCompletion) && (x.parent === Base || x.parent === Core),
72 // REPLCompletions.completions("", 0)[1])
73 // try
74 // v = eval(Symbol(compl.mod))
75 // if !(v isa Function || v isa Type || v isa TypeVar || v isa Module || v isa Colon)
76 // push!(res, compl.mod)
77 // end
78 // catch e
79 // end
80 // end
81 // sort!(unique!(res))
82 // foreach(x -> println("\'", x, "\',"), res)
83 const LITERAL_LIST = [
84 'ARGS',
85 'C_NULL',
86 'DEPOT_PATH',
87 'ENDIAN_BOM',
88 'ENV',
89 'Inf',
90 'Inf16',
91 'Inf32',
92 'Inf64',
93 'InsertionSort',
94 'LOAD_PATH',
95 'MergeSort',
96 'NaN',
97 'NaN16',
98 'NaN32',
99 'NaN64',
100 'PROGRAM_FILE',
101 'QuickSort',
102 'RoundDown',
103 'RoundFromZero',
104 'RoundNearest',
105 'RoundNearestTiesAway',
106 'RoundNearestTiesUp',
107 'RoundToZero',
108 'RoundUp',
109 'VERSION|0',
110 'devnull',
111 'false',
112 'im',
113 'missing',
114 'nothing',
115 'pi',
116 'stderr',
117 'stdin',
118 'stdout',
119 'true',
120 'undef',
121 'π',
122 'ℯ',
123 ];
124
125 // # built_in generator (Julia 1.5.2)
126 // import REPL.REPLCompletions
127 // res = String[]
128 // for compl in filter!(x -> isa(x, REPLCompletions.ModuleCompletion) && (x.parent === Base || x.parent === Core),
129 // REPLCompletions.completions("", 0)[1])
130 // try
131 // v = eval(Symbol(compl.mod))
132 // if (v isa Type || v isa TypeVar) && (compl.mod != "=>")
133 // push!(res, compl.mod)
134 // end
135 // catch e
136 // end
137 // end
138 // sort!(unique!(res))
139 // foreach(x -> println("\'", x, "\',"), res)
140 const BUILT_IN_LIST = [
141 'AbstractArray',
142 'AbstractChannel',
143 'AbstractChar',
144 'AbstractDict',
145 'AbstractDisplay',
146 'AbstractFloat',
147 'AbstractIrrational',
148 'AbstractMatrix',
149 'AbstractRange',
150 'AbstractSet',
151 'AbstractString',
152 'AbstractUnitRange',
153 'AbstractVecOrMat',
154 'AbstractVector',
155 'Any',
156 'ArgumentError',
157 'Array',
158 'AssertionError',
159 'BigFloat',
160 'BigInt',
161 'BitArray',
162 'BitMatrix',
163 'BitSet',
164 'BitVector',
165 'Bool',
166 'BoundsError',
167 'CapturedException',
168 'CartesianIndex',
169 'CartesianIndices',
170 'Cchar',
171 'Cdouble',
172 'Cfloat',
173 'Channel',
174 'Char',
175 'Cint',
176 'Cintmax_t',
177 'Clong',
178 'Clonglong',
179 'Cmd',
180 'Colon',
181 'Complex',
182 'ComplexF16',
183 'ComplexF32',
184 'ComplexF64',
185 'CompositeException',
186 'Condition',
187 'Cptrdiff_t',
188 'Cshort',
189 'Csize_t',
190 'Cssize_t',
191 'Cstring',
192 'Cuchar',
193 'Cuint',
194 'Cuintmax_t',
195 'Culong',
196 'Culonglong',
197 'Cushort',
198 'Cvoid',
199 'Cwchar_t',
200 'Cwstring',
201 'DataType',
202 'DenseArray',
203 'DenseMatrix',
204 'DenseVecOrMat',
205 'DenseVector',
206 'Dict',
207 'DimensionMismatch',
208 'Dims',
209 'DivideError',
210 'DomainError',
211 'EOFError',
212 'Enum',
213 'ErrorException',
214 'Exception',
215 'ExponentialBackOff',
216 'Expr',
217 'Float16',
218 'Float32',
219 'Float64',
220 'Function',
221 'GlobalRef',
222 'HTML',
223 'IO',
224 'IOBuffer',
225 'IOContext',
226 'IOStream',
227 'IdDict',
228 'IndexCartesian',
229 'IndexLinear',
230 'IndexStyle',
231 'InexactError',
232 'InitError',
233 'Int',
234 'Int128',
235 'Int16',
236 'Int32',
237 'Int64',
238 'Int8',
239 'Integer',
240 'InterruptException',
241 'InvalidStateException',
242 'Irrational',
243 'KeyError',
244 'LinRange',
245 'LineNumberNode',
246 'LinearIndices',
247 'LoadError',
248 'MIME',
249 'Matrix',
250 'Method',
251 'MethodError',
252 'Missing',
253 'MissingException',
254 'Module',
255 'NTuple',
256 'NamedTuple',
257 'Nothing',
258 'Number',
259 'OrdinalRange',
260 'OutOfMemoryError',
261 'OverflowError',
262 'Pair',
263 'PartialQuickSort',
264 'PermutedDimsArray',
265 'Pipe',
266 'ProcessFailedException',
267 'Ptr',
268 'QuoteNode',
269 'Rational',
270 'RawFD',
271 'ReadOnlyMemoryError',
272 'Real',
273 'ReentrantLock',
274 'Ref',
275 'Regex',
276 'RegexMatch',
277 'RoundingMode',
278 'SegmentationFault',
279 'Set',
280 'Signed',
281 'Some',
282 'StackOverflowError',
283 'StepRange',
284 'StepRangeLen',
285 'StridedArray',
286 'StridedMatrix',
287 'StridedVecOrMat',
288 'StridedVector',
289 'String',
290 'StringIndexError',
291 'SubArray',
292 'SubString',
293 'SubstitutionString',
294 'Symbol',
295 'SystemError',
296 'Task',
297 'TaskFailedException',
298 'Text',
299 'TextDisplay',
300 'Timer',
301 'Tuple',
302 'Type',
303 'TypeError',
304 'TypeVar',
305 'UInt',
306 'UInt128',
307 'UInt16',
308 'UInt32',
309 'UInt64',
310 'UInt8',
311 'UndefInitializer',
312 'UndefKeywordError',
313 'UndefRefError',
314 'UndefVarError',
315 'Union',
316 'UnionAll',
317 'UnitRange',
318 'Unsigned',
319 'Val',
320 'Vararg',
321 'VecElement',
322 'VecOrMat',
323 'Vector',
324 'VersionNumber',
325 'WeakKeyDict',
326 'WeakRef',
327 ];
328
329 const KEYWORDS = {
330 $pattern: VARIABLE_NAME_RE,
331 keyword: KEYWORD_LIST,
332 literal: LITERAL_LIST,
333 built_in: BUILT_IN_LIST,
334 };
335
336 // placeholder for recursive self-reference
337 const DEFAULT = {
338 keywords: KEYWORDS,
339 illegal: /<\//
340 };
341
342 // ref: https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/
343 const NUMBER = {
344 className: 'number',
345 // supported numeric literals:
346 // * binary literal (e.g. 0x10)
347 // * octal literal (e.g. 0o76543210)
348 // * hexadecimal literal (e.g. 0xfedcba876543210)
349 // * hexadecimal floating point literal (e.g. 0x1p0, 0x1.2p2)
350 // * decimal literal (e.g. 9876543210, 100_000_000)
351 // * floating pointe literal (e.g. 1.2, 1.2f, .2, 1., 1.2e10, 1.2e-10)
352 begin: /(\b0x[\d_]*(\.[\d_]*)?|0x\.\d[\d_]*)p[-+]?\d+|\b0[box][a-fA-F0-9][a-fA-F0-9_]*|(\b\d[\d_]*(\.[\d_]*)?|\.\d[\d_]*)([eEfF][-+]?\d+)?/,
353 relevance: 0
354 };
355
356 const CHAR = {
357 className: 'string',
358 begin: /'(.|\\[xXuU][a-zA-Z0-9]+)'/
359 };
360
361 const INTERPOLATION = {
362 className: 'subst',
363 begin: /\$\(/,
364 end: /\)/,
365 keywords: KEYWORDS
366 };
367
368 const INTERPOLATED_VARIABLE = {
369 className: 'variable',
370 begin: '\\$' + VARIABLE_NAME_RE
371 };
372
373 // TODO: neatly escape normal code in string literal
374 const STRING = {
375 className: 'string',
376 contains: [
377 hljs.BACKSLASH_ESCAPE,
378 INTERPOLATION,
379 INTERPOLATED_VARIABLE
380 ],
381 variants: [
382 {
383 begin: /\w*"""/,
384 end: /"""\w*/,
385 relevance: 10
386 },
387 {
388 begin: /\w*"/,
389 end: /"\w*/
390 }
391 ]
392 };
393
394 const COMMAND = {
395 className: 'string',
396 contains: [
397 hljs.BACKSLASH_ESCAPE,
398 INTERPOLATION,
399 INTERPOLATED_VARIABLE
400 ],
401 begin: '`',
402 end: '`'
403 };
404
405 const MACROCALL = {
406 className: 'meta',
407 begin: '@' + VARIABLE_NAME_RE
408 };
409
410 const COMMENT = {
411 className: 'comment',
412 variants: [
413 {
414 begin: '#=',
415 end: '=#',
416 relevance: 10
417 },
418 {
419 begin: '#',
420 end: '$'
421 }
422 ]
423 };
424
425 DEFAULT.name = 'Julia';
426 DEFAULT.contains = [
427 NUMBER,
428 CHAR,
429 STRING,
430 COMMAND,
431 MACROCALL,
432 COMMENT,
433 hljs.HASH_COMMENT_MODE,
434 {
435 className: 'keyword',
436 begin:
437 '\\b(((abstract|primitive)\\s+)type|(mutable\\s+)?struct)\\b'
438 },
439 { begin: /<:/ } // relevance booster
440 ];
441 INTERPOLATION.contains = DEFAULT.contains;
442
443 return DEFAULT;
444 }
445
446 return julia;
447
448 })();
449 ;
450 export default hljsGrammar;