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