]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/fortran.js
Initial commit.
[flow-web.git] / static / highlight / languages / fortran.js
1 /*! `fortran` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Fortran
8 Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
9 Website: https://en.wikipedia.org/wiki/Fortran
10 Category: scientific
11 */
12
13 /** @type LanguageFn */
14 function fortran(hljs) {
15 const regex = hljs.regex;
16 const PARAMS = {
17 className: 'params',
18 begin: '\\(',
19 end: '\\)'
20 };
21
22 const COMMENT = { variants: [
23 hljs.COMMENT('!', '$', { relevance: 0 }),
24 // allow FORTRAN 77 style comments
25 hljs.COMMENT('^C[ ]', '$', { relevance: 0 }),
26 hljs.COMMENT('^C$', '$', { relevance: 0 })
27 ] };
28
29 // regex in both fortran and irpf90 should match
30 const OPTIONAL_NUMBER_SUFFIX = /(_[a-z_\d]+)?/;
31 const OPTIONAL_NUMBER_EXP = /([de][+-]?\d+)?/;
32 const NUMBER = {
33 className: 'number',
34 variants: [
35 { begin: regex.concat(/\b\d+/, /\.(\d*)/, OPTIONAL_NUMBER_EXP, OPTIONAL_NUMBER_SUFFIX) },
36 { begin: regex.concat(/\b\d+/, OPTIONAL_NUMBER_EXP, OPTIONAL_NUMBER_SUFFIX) },
37 { begin: regex.concat(/\.\d+/, OPTIONAL_NUMBER_EXP, OPTIONAL_NUMBER_SUFFIX) }
38 ],
39 relevance: 0
40 };
41
42 const FUNCTION_DEF = {
43 className: 'function',
44 beginKeywords: 'subroutine function program',
45 illegal: '[${=\\n]',
46 contains: [
47 hljs.UNDERSCORE_TITLE_MODE,
48 PARAMS
49 ]
50 };
51
52 const STRING = {
53 className: 'string',
54 relevance: 0,
55 variants: [
56 hljs.APOS_STRING_MODE,
57 hljs.QUOTE_STRING_MODE
58 ]
59 };
60
61 const KEYWORDS = [
62 "kind",
63 "do",
64 "concurrent",
65 "local",
66 "shared",
67 "while",
68 "private",
69 "call",
70 "intrinsic",
71 "where",
72 "elsewhere",
73 "type",
74 "endtype",
75 "endmodule",
76 "endselect",
77 "endinterface",
78 "end",
79 "enddo",
80 "endif",
81 "if",
82 "forall",
83 "endforall",
84 "only",
85 "contains",
86 "default",
87 "return",
88 "stop",
89 "then",
90 "block",
91 "endblock",
92 "endassociate",
93 "public",
94 "subroutine|10",
95 "function",
96 "program",
97 ".and.",
98 ".or.",
99 ".not.",
100 ".le.",
101 ".eq.",
102 ".ge.",
103 ".gt.",
104 ".lt.",
105 "goto",
106 "save",
107 "else",
108 "use",
109 "module",
110 "select",
111 "case",
112 "access",
113 "blank",
114 "direct",
115 "exist",
116 "file",
117 "fmt",
118 "form",
119 "formatted",
120 "iostat",
121 "name",
122 "named",
123 "nextrec",
124 "number",
125 "opened",
126 "rec",
127 "recl",
128 "sequential",
129 "status",
130 "unformatted",
131 "unit",
132 "continue",
133 "format",
134 "pause",
135 "cycle",
136 "exit",
137 "c_null_char",
138 "c_alert",
139 "c_backspace",
140 "c_form_feed",
141 "flush",
142 "wait",
143 "decimal",
144 "round",
145 "iomsg",
146 "synchronous",
147 "nopass",
148 "non_overridable",
149 "pass",
150 "protected",
151 "volatile",
152 "abstract",
153 "extends",
154 "import",
155 "non_intrinsic",
156 "value",
157 "deferred",
158 "generic",
159 "final",
160 "enumerator",
161 "class",
162 "associate",
163 "bind",
164 "enum",
165 "c_int",
166 "c_short",
167 "c_long",
168 "c_long_long",
169 "c_signed_char",
170 "c_size_t",
171 "c_int8_t",
172 "c_int16_t",
173 "c_int32_t",
174 "c_int64_t",
175 "c_int_least8_t",
176 "c_int_least16_t",
177 "c_int_least32_t",
178 "c_int_least64_t",
179 "c_int_fast8_t",
180 "c_int_fast16_t",
181 "c_int_fast32_t",
182 "c_int_fast64_t",
183 "c_intmax_t",
184 "C_intptr_t",
185 "c_float",
186 "c_double",
187 "c_long_double",
188 "c_float_complex",
189 "c_double_complex",
190 "c_long_double_complex",
191 "c_bool",
192 "c_char",
193 "c_null_ptr",
194 "c_null_funptr",
195 "c_new_line",
196 "c_carriage_return",
197 "c_horizontal_tab",
198 "c_vertical_tab",
199 "iso_c_binding",
200 "c_loc",
201 "c_funloc",
202 "c_associated",
203 "c_f_pointer",
204 "c_ptr",
205 "c_funptr",
206 "iso_fortran_env",
207 "character_storage_size",
208 "error_unit",
209 "file_storage_size",
210 "input_unit",
211 "iostat_end",
212 "iostat_eor",
213 "numeric_storage_size",
214 "output_unit",
215 "c_f_procpointer",
216 "ieee_arithmetic",
217 "ieee_support_underflow_control",
218 "ieee_get_underflow_mode",
219 "ieee_set_underflow_mode",
220 "newunit",
221 "contiguous",
222 "recursive",
223 "pad",
224 "position",
225 "action",
226 "delim",
227 "readwrite",
228 "eor",
229 "advance",
230 "nml",
231 "interface",
232 "procedure",
233 "namelist",
234 "include",
235 "sequence",
236 "elemental",
237 "pure",
238 "impure",
239 "integer",
240 "real",
241 "character",
242 "complex",
243 "logical",
244 "codimension",
245 "dimension",
246 "allocatable|10",
247 "parameter",
248 "external",
249 "implicit|10",
250 "none",
251 "double",
252 "precision",
253 "assign",
254 "intent",
255 "optional",
256 "pointer",
257 "target",
258 "in",
259 "out",
260 "common",
261 "equivalence",
262 "data"
263 ];
264 const LITERALS = [
265 ".False.",
266 ".True."
267 ];
268 const BUILT_INS = [
269 "alog",
270 "alog10",
271 "amax0",
272 "amax1",
273 "amin0",
274 "amin1",
275 "amod",
276 "cabs",
277 "ccos",
278 "cexp",
279 "clog",
280 "csin",
281 "csqrt",
282 "dabs",
283 "dacos",
284 "dasin",
285 "datan",
286 "datan2",
287 "dcos",
288 "dcosh",
289 "ddim",
290 "dexp",
291 "dint",
292 "dlog",
293 "dlog10",
294 "dmax1",
295 "dmin1",
296 "dmod",
297 "dnint",
298 "dsign",
299 "dsin",
300 "dsinh",
301 "dsqrt",
302 "dtan",
303 "dtanh",
304 "float",
305 "iabs",
306 "idim",
307 "idint",
308 "idnint",
309 "ifix",
310 "isign",
311 "max0",
312 "max1",
313 "min0",
314 "min1",
315 "sngl",
316 "algama",
317 "cdabs",
318 "cdcos",
319 "cdexp",
320 "cdlog",
321 "cdsin",
322 "cdsqrt",
323 "cqabs",
324 "cqcos",
325 "cqexp",
326 "cqlog",
327 "cqsin",
328 "cqsqrt",
329 "dcmplx",
330 "dconjg",
331 "derf",
332 "derfc",
333 "dfloat",
334 "dgamma",
335 "dimag",
336 "dlgama",
337 "iqint",
338 "qabs",
339 "qacos",
340 "qasin",
341 "qatan",
342 "qatan2",
343 "qcmplx",
344 "qconjg",
345 "qcos",
346 "qcosh",
347 "qdim",
348 "qerf",
349 "qerfc",
350 "qexp",
351 "qgamma",
352 "qimag",
353 "qlgama",
354 "qlog",
355 "qlog10",
356 "qmax1",
357 "qmin1",
358 "qmod",
359 "qnint",
360 "qsign",
361 "qsin",
362 "qsinh",
363 "qsqrt",
364 "qtan",
365 "qtanh",
366 "abs",
367 "acos",
368 "aimag",
369 "aint",
370 "anint",
371 "asin",
372 "atan",
373 "atan2",
374 "char",
375 "cmplx",
376 "conjg",
377 "cos",
378 "cosh",
379 "exp",
380 "ichar",
381 "index",
382 "int",
383 "log",
384 "log10",
385 "max",
386 "min",
387 "nint",
388 "sign",
389 "sin",
390 "sinh",
391 "sqrt",
392 "tan",
393 "tanh",
394 "print",
395 "write",
396 "dim",
397 "lge",
398 "lgt",
399 "lle",
400 "llt",
401 "mod",
402 "nullify",
403 "allocate",
404 "deallocate",
405 "adjustl",
406 "adjustr",
407 "all",
408 "allocated",
409 "any",
410 "associated",
411 "bit_size",
412 "btest",
413 "ceiling",
414 "count",
415 "cshift",
416 "date_and_time",
417 "digits",
418 "dot_product",
419 "eoshift",
420 "epsilon",
421 "exponent",
422 "floor",
423 "fraction",
424 "huge",
425 "iand",
426 "ibclr",
427 "ibits",
428 "ibset",
429 "ieor",
430 "ior",
431 "ishft",
432 "ishftc",
433 "lbound",
434 "len_trim",
435 "matmul",
436 "maxexponent",
437 "maxloc",
438 "maxval",
439 "merge",
440 "minexponent",
441 "minloc",
442 "minval",
443 "modulo",
444 "mvbits",
445 "nearest",
446 "pack",
447 "present",
448 "product",
449 "radix",
450 "random_number",
451 "random_seed",
452 "range",
453 "repeat",
454 "reshape",
455 "rrspacing",
456 "scale",
457 "scan",
458 "selected_int_kind",
459 "selected_real_kind",
460 "set_exponent",
461 "shape",
462 "size",
463 "spacing",
464 "spread",
465 "sum",
466 "system_clock",
467 "tiny",
468 "transpose",
469 "trim",
470 "ubound",
471 "unpack",
472 "verify",
473 "achar",
474 "iachar",
475 "transfer",
476 "dble",
477 "entry",
478 "dprod",
479 "cpu_time",
480 "command_argument_count",
481 "get_command",
482 "get_command_argument",
483 "get_environment_variable",
484 "is_iostat_end",
485 "ieee_arithmetic",
486 "ieee_support_underflow_control",
487 "ieee_get_underflow_mode",
488 "ieee_set_underflow_mode",
489 "is_iostat_eor",
490 "move_alloc",
491 "new_line",
492 "selected_char_kind",
493 "same_type_as",
494 "extends_type_of",
495 "acosh",
496 "asinh",
497 "atanh",
498 "bessel_j0",
499 "bessel_j1",
500 "bessel_jn",
501 "bessel_y0",
502 "bessel_y1",
503 "bessel_yn",
504 "erf",
505 "erfc",
506 "erfc_scaled",
507 "gamma",
508 "log_gamma",
509 "hypot",
510 "norm2",
511 "atomic_define",
512 "atomic_ref",
513 "execute_command_line",
514 "leadz",
515 "trailz",
516 "storage_size",
517 "merge_bits",
518 "bge",
519 "bgt",
520 "ble",
521 "blt",
522 "dshiftl",
523 "dshiftr",
524 "findloc",
525 "iall",
526 "iany",
527 "iparity",
528 "image_index",
529 "lcobound",
530 "ucobound",
531 "maskl",
532 "maskr",
533 "num_images",
534 "parity",
535 "popcnt",
536 "poppar",
537 "shifta",
538 "shiftl",
539 "shiftr",
540 "this_image",
541 "sync",
542 "change",
543 "team",
544 "co_broadcast",
545 "co_max",
546 "co_min",
547 "co_sum",
548 "co_reduce"
549 ];
550 return {
551 name: 'Fortran',
552 case_insensitive: true,
553 aliases: [
554 'f90',
555 'f95'
556 ],
557 keywords: {
558 $pattern: /\b[a-z][a-z0-9_]+\b|\.[a-z][a-z0-9_]+\./,
559 keyword: KEYWORDS,
560 literal: LITERALS,
561 built_in: BUILT_INS
562 },
563 illegal: /\/\*/,
564 contains: [
565 STRING,
566 FUNCTION_DEF,
567 // allow `C = value` for assignments so they aren't misdetected
568 // as Fortran 77 style comments
569 {
570 begin: /^C\s*=(?!=)/,
571 relevance: 0
572 },
573 COMMENT,
574 NUMBER
575 ]
576 };
577 }
578
579 return fortran;
580
581 })();
582
583 hljs.registerLanguage('fortran', hljsGrammar);
584 })();