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