Debian Codegraph @

codemirror-legacy-modes/mode/fortran.js

raw
1 function words(array) {
2 var keys = {};
3 for (var i = 0; i < array.length; ++i) {
4 keys[array[i]] = true;
5 }
6 return keys;
7 }
8
9 var keywords = words([
10 "abstract", "accept", "allocatable", "allocate",
11 "array", "assign", "asynchronous", "backspace",
12 "bind", "block", "byte", "call", "case",
13 "class", "close", "common", "contains",
14 "continue", "cycle", "data", "deallocate",
15 "decode", "deferred", "dimension", "do",
16 "elemental", "else", "encode", "end",
17 "endif", "entry", "enumerator", "equivalence",
18 "exit", "external", "extrinsic", "final",
19 "forall", "format", "function", "generic",
20 "go", "goto", "if", "implicit", "import", "include",
21 "inquire", "intent", "interface", "intrinsic",
22 "module", "namelist", "non_intrinsic",
23 "non_overridable", "none", "nopass",
24 "nullify", "open", "optional", "options",
25 "parameter", "pass", "pause", "pointer",
26 "print", "private", "program", "protected",
27 "public", "pure", "read", "recursive", "result",
28 "return", "rewind", "save", "select", "sequence",
29 "stop", "subroutine", "target", "then", "to", "type",
30 "use", "value", "volatile", "where", "while",
31 "write"]);
32 var builtins = words(["abort", "abs", "access", "achar", "acos",
33 "adjustl", "adjustr", "aimag", "aint", "alarm",
34 "all", "allocated", "alog", "amax", "amin",
35 "amod", "and", "anint", "any", "asin",
36 "associated", "atan", "besj", "besjn", "besy",
37 "besyn", "bit_size", "btest", "cabs", "ccos",
38 "ceiling", "cexp", "char", "chdir", "chmod",
39 "clog", "cmplx", "command_argument_count",
40 "complex", "conjg", "cos", "cosh", "count",
41 "cpu_time", "cshift", "csin", "csqrt", "ctime",
42 "c_funloc", "c_loc", "c_associated", "c_null_ptr",
43 "c_null_funptr", "c_f_pointer", "c_null_char",
44 "c_alert", "c_backspace", "c_form_feed",
45 "c_new_line", "c_carriage_return",
46 "c_horizontal_tab", "c_vertical_tab", "dabs",
47 "dacos", "dasin", "datan", "date_and_time",
48 "dbesj", "dbesj", "dbesjn", "dbesy", "dbesy",
49 "dbesyn", "dble", "dcos", "dcosh", "ddim", "derf",
50 "derfc", "dexp", "digits", "dim", "dint", "dlog",
51 "dlog", "dmax", "dmin", "dmod", "dnint",
52 "dot_product", "dprod", "dsign", "dsinh",
53 "dsin", "dsqrt", "dtanh", "dtan", "dtime",
54 "eoshift", "epsilon", "erf", "erfc", "etime",
55 "exit", "exp", "exponent", "extends_type_of",
56 "fdate", "fget", "fgetc", "float", "floor",
57 "flush", "fnum", "fputc", "fput", "fraction",
58 "fseek", "fstat", "ftell", "gerror", "getarg",
59 "get_command", "get_command_argument",
60 "get_environment_variable", "getcwd",
61 "getenv", "getgid", "getlog", "getpid",
62 "getuid", "gmtime", "hostnm", "huge", "iabs",
63 "iachar", "iand", "iargc", "ibclr", "ibits",
64 "ibset", "ichar", "idate", "idim", "idint",
65 "idnint", "ieor", "ierrno", "ifix", "imag",
66 "imagpart", "index", "int", "ior", "irand",
67 "isatty", "ishft", "ishftc", "isign",
68 "iso_c_binding", "is_iostat_end", "is_iostat_eor",
69 "itime", "kill", "kind", "lbound", "len", "len_trim",
70 "lge", "lgt", "link", "lle", "llt", "lnblnk", "loc",
71 "log", "logical", "long", "lshift", "lstat", "ltime",
72 "matmul", "max", "maxexponent", "maxloc", "maxval",
73 "mclock", "merge", "move_alloc", "min", "minexponent",
74 "minloc", "minval", "mod", "modulo", "mvbits",
75 "nearest", "new_line", "nint", "not", "or", "pack",
76 "perror", "precision", "present", "product", "radix",
77 "rand", "random_number", "random_seed", "range",
78 "real", "realpart", "rename", "repeat", "reshape",
79 "rrspacing", "rshift", "same_type_as", "scale",
80 "scan", "second", "selected_int_kind",
81 "selected_real_kind", "set_exponent", "shape",
82 "short", "sign", "signal", "sinh", "sin", "sleep",
83 "sngl", "spacing", "spread", "sqrt", "srand", "stat",
84 "sum", "symlnk", "system", "system_clock", "tan",
85 "tanh", "time", "tiny", "transfer", "transpose",
86 "trim", "ttynam", "ubound", "umask", "unlink",
87 "unpack", "verify", "xor", "zabs", "zcos", "zexp",
88 "zlog", "zsin", "zsqrt"]);
89
90 var dataTypes = words(["c_bool", "c_char", "c_double", "c_double_complex",
91 "c_float", "c_float_complex", "c_funptr", "c_int",
92 "c_int16_t", "c_int32_t", "c_int64_t", "c_int8_t",
93 "c_int_fast16_t", "c_int_fast32_t", "c_int_fast64_t",
94 "c_int_fast8_t", "c_int_least16_t", "c_int_least32_t",
95 "c_int_least64_t", "c_int_least8_t", "c_intmax_t",
96 "c_intptr_t", "c_long", "c_long_double",
97 "c_long_double_complex", "c_long_long", "c_ptr",
98 "c_short", "c_signed_char", "c_size_t", "character",
99 "complex", "double", "integer", "logical", "real"]);
100 var isOperatorChar = /[+\-*&=<>\/\:]/;
101 var litOperator = /^\.(and|or|eq|lt|le|gt|ge|ne|not|eqv|neqv)\./i;
102
103 function tokenBase(stream, state) {
104
105 if (stream.match(litOperator)){
106 return 'operator';
107 }
108
109 var ch = stream.next();
110 if (ch == "!") {
111 stream.skipToEnd();
112 return "comment";
113 }
114 if (ch == '"' || ch == "'") {
115 state.tokenize = tokenString(ch);
116 return state.tokenize(stream, state);
117 }
118 if (/[\[\]\(\),]/.test(ch)) {
119 return null;
120 }
121 if (/\d/.test(ch)) {
122 stream.eatWhile(/[\w\.]/);
123 return "number";
124 }
125 if (isOperatorChar.test(ch)) {
126 stream.eatWhile(isOperatorChar);
127 return "operator";
128 }
129 stream.eatWhile(/[\w\$_]/);
130 var word = stream.current().toLowerCase();
131
132 if (keywords.hasOwnProperty(word)){
133 return 'keyword';
134 }
135 if (builtins.hasOwnProperty(word) || dataTypes.hasOwnProperty(word)) {
136 return 'builtin';
137 }
138 return "variable";
139 }
140
141 function tokenString(quote) {
142 return function(stream, state) {
143 var escaped = false, next, end = false;
144 while ((next = stream.next()) != null) {
145 if (next == quote && !escaped) {
146 end = true;
147 break;
148 }
149 escaped = !escaped && next == "\\";
150 }
151 if (end || !escaped) state.tokenize = null;
152 return "string";
153 };
154 }
155
156 // Interface
157
158 export const fortran = {
159 name: "fortran",
160 startState: function() {
161 return {tokenize: null};
162 },
163
164 token: function(stream, state) {
165 if (stream.eatSpace()) return null;
166 var style = (state.tokenize || tokenBase)(stream, state);
167 if (style == "comment" || style == "meta") return style;
168 return style;
169 }
170 };
171