UNPKG

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