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