123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- // CodeMirror, copyright (c) by Marijn Haverbeke and others
- // Distributed under an MIT license: https://codemirror.net/LICENSE
- ;(function (mod) {
- if (typeof exports == 'object' && typeof module == 'object')
- // CommonJS
- mod(require('../../lib/codemirror'))
- else if (typeof define == 'function' && define.amd)
- // AMD
- define(['../../lib/codemirror'], mod)
- // Plain browser env
- else mod(CodeMirror)
- })(function (CodeMirror) {
- 'use strict'
- CodeMirror.defineMode('fortran', function () {
- function words(array) {
- var keys = {}
- for (var i = 0; i < array.length; ++i) {
- keys[array[i]] = true
- }
- return keys
- }
- var keywords = words([
- 'abstract',
- 'accept',
- 'allocatable',
- 'allocate',
- 'array',
- 'assign',
- 'asynchronous',
- 'backspace',
- 'bind',
- 'block',
- 'byte',
- 'call',
- 'case',
- 'class',
- 'close',
- 'common',
- 'contains',
- 'continue',
- 'cycle',
- 'data',
- 'deallocate',
- 'decode',
- 'deferred',
- 'dimension',
- 'do',
- 'elemental',
- 'else',
- 'encode',
- 'end',
- 'endif',
- 'entry',
- 'enumerator',
- 'equivalence',
- 'exit',
- 'external',
- 'extrinsic',
- 'final',
- 'forall',
- 'format',
- 'function',
- 'generic',
- 'go',
- 'goto',
- 'if',
- 'implicit',
- 'import',
- 'include',
- 'inquire',
- 'intent',
- 'interface',
- 'intrinsic',
- 'module',
- 'namelist',
- 'non_intrinsic',
- 'non_overridable',
- 'none',
- 'nopass',
- 'nullify',
- 'open',
- 'optional',
- 'options',
- 'parameter',
- 'pass',
- 'pause',
- 'pointer',
- 'print',
- 'private',
- 'program',
- 'protected',
- 'public',
- 'pure',
- 'read',
- 'recursive',
- 'result',
- 'return',
- 'rewind',
- 'save',
- 'select',
- 'sequence',
- 'stop',
- 'subroutine',
- 'target',
- 'then',
- 'to',
- 'type',
- 'use',
- 'value',
- 'volatile',
- 'where',
- 'while',
- 'write',
- ])
- var builtins = words([
- 'abort',
- 'abs',
- 'access',
- 'achar',
- 'acos',
- 'adjustl',
- 'adjustr',
- 'aimag',
- 'aint',
- 'alarm',
- 'all',
- 'allocated',
- 'alog',
- 'amax',
- 'amin',
- 'amod',
- 'and',
- 'anint',
- 'any',
- 'asin',
- 'associated',
- 'atan',
- 'besj',
- 'besjn',
- 'besy',
- 'besyn',
- 'bit_size',
- 'btest',
- 'cabs',
- 'ccos',
- 'ceiling',
- 'cexp',
- 'char',
- 'chdir',
- 'chmod',
- 'clog',
- 'cmplx',
- 'command_argument_count',
- 'complex',
- 'conjg',
- 'cos',
- 'cosh',
- 'count',
- 'cpu_time',
- 'cshift',
- 'csin',
- 'csqrt',
- 'ctime',
- 'c_funloc',
- 'c_loc',
- 'c_associated',
- 'c_null_ptr',
- 'c_null_funptr',
- 'c_f_pointer',
- 'c_null_char',
- 'c_alert',
- 'c_backspace',
- 'c_form_feed',
- 'c_new_line',
- 'c_carriage_return',
- 'c_horizontal_tab',
- 'c_vertical_tab',
- 'dabs',
- 'dacos',
- 'dasin',
- 'datan',
- 'date_and_time',
- 'dbesj',
- 'dbesj',
- 'dbesjn',
- 'dbesy',
- 'dbesy',
- 'dbesyn',
- 'dble',
- 'dcos',
- 'dcosh',
- 'ddim',
- 'derf',
- 'derfc',
- 'dexp',
- 'digits',
- 'dim',
- 'dint',
- 'dlog',
- 'dlog',
- 'dmax',
- 'dmin',
- 'dmod',
- 'dnint',
- 'dot_product',
- 'dprod',
- 'dsign',
- 'dsinh',
- 'dsin',
- 'dsqrt',
- 'dtanh',
- 'dtan',
- 'dtime',
- 'eoshift',
- 'epsilon',
- 'erf',
- 'erfc',
- 'etime',
- 'exit',
- 'exp',
- 'exponent',
- 'extends_type_of',
- 'fdate',
- 'fget',
- 'fgetc',
- 'float',
- 'floor',
- 'flush',
- 'fnum',
- 'fputc',
- 'fput',
- 'fraction',
- 'fseek',
- 'fstat',
- 'ftell',
- 'gerror',
- 'getarg',
- 'get_command',
- 'get_command_argument',
- 'get_environment_variable',
- 'getcwd',
- 'getenv',
- 'getgid',
- 'getlog',
- 'getpid',
- 'getuid',
- 'gmtime',
- 'hostnm',
- 'huge',
- 'iabs',
- 'iachar',
- 'iand',
- 'iargc',
- 'ibclr',
- 'ibits',
- 'ibset',
- 'ichar',
- 'idate',
- 'idim',
- 'idint',
- 'idnint',
- 'ieor',
- 'ierrno',
- 'ifix',
- 'imag',
- 'imagpart',
- 'index',
- 'int',
- 'ior',
- 'irand',
- 'isatty',
- 'ishft',
- 'ishftc',
- 'isign',
- 'iso_c_binding',
- 'is_iostat_end',
- 'is_iostat_eor',
- 'itime',
- 'kill',
- 'kind',
- 'lbound',
- 'len',
- 'len_trim',
- 'lge',
- 'lgt',
- 'link',
- 'lle',
- 'llt',
- 'lnblnk',
- 'loc',
- 'log',
- 'logical',
- 'long',
- 'lshift',
- 'lstat',
- 'ltime',
- 'matmul',
- 'max',
- 'maxexponent',
- 'maxloc',
- 'maxval',
- 'mclock',
- 'merge',
- 'move_alloc',
- 'min',
- 'minexponent',
- 'minloc',
- 'minval',
- 'mod',
- 'modulo',
- 'mvbits',
- 'nearest',
- 'new_line',
- 'nint',
- 'not',
- 'or',
- 'pack',
- 'perror',
- 'precision',
- 'present',
- 'product',
- 'radix',
- 'rand',
- 'random_number',
- 'random_seed',
- 'range',
- 'real',
- 'realpart',
- 'rename',
- 'repeat',
- 'reshape',
- 'rrspacing',
- 'rshift',
- 'same_type_as',
- 'scale',
- 'scan',
- 'second',
- 'selected_int_kind',
- 'selected_real_kind',
- 'set_exponent',
- 'shape',
- 'short',
- 'sign',
- 'signal',
- 'sinh',
- 'sin',
- 'sleep',
- 'sngl',
- 'spacing',
- 'spread',
- 'sqrt',
- 'srand',
- 'stat',
- 'sum',
- 'symlnk',
- 'system',
- 'system_clock',
- 'tan',
- 'tanh',
- 'time',
- 'tiny',
- 'transfer',
- 'transpose',
- 'trim',
- 'ttynam',
- 'ubound',
- 'umask',
- 'unlink',
- 'unpack',
- 'verify',
- 'xor',
- 'zabs',
- 'zcos',
- 'zexp',
- 'zlog',
- 'zsin',
- 'zsqrt',
- ])
- var dataTypes = words([
- 'c_bool',
- 'c_char',
- 'c_double',
- 'c_double_complex',
- 'c_float',
- 'c_float_complex',
- 'c_funptr',
- 'c_int',
- 'c_int16_t',
- 'c_int32_t',
- 'c_int64_t',
- 'c_int8_t',
- 'c_int_fast16_t',
- 'c_int_fast32_t',
- 'c_int_fast64_t',
- 'c_int_fast8_t',
- 'c_int_least16_t',
- 'c_int_least32_t',
- 'c_int_least64_t',
- 'c_int_least8_t',
- 'c_intmax_t',
- 'c_intptr_t',
- 'c_long',
- 'c_long_double',
- 'c_long_double_complex',
- 'c_long_long',
- 'c_ptr',
- 'c_short',
- 'c_signed_char',
- 'c_size_t',
- 'character',
- 'complex',
- 'double',
- 'integer',
- 'logical',
- 'real',
- ])
- var isOperatorChar = /[+\-*&=<>\/\:]/
- var litOperator = /^\.(and|or|eq|lt|le|gt|ge|ne|not|eqv|neqv)\./i
- function tokenBase(stream, state) {
- if (stream.match(litOperator)) {
- return 'operator'
- }
- var ch = stream.next()
- if (ch == '!') {
- stream.skipToEnd()
- return 'comment'
- }
- if (ch == '"' || ch == "'") {
- state.tokenize = tokenString(ch)
- return state.tokenize(stream, state)
- }
- if (/[\[\]\(\),]/.test(ch)) {
- return null
- }
- if (/\d/.test(ch)) {
- stream.eatWhile(/[\w\.]/)
- return 'number'
- }
- if (isOperatorChar.test(ch)) {
- stream.eatWhile(isOperatorChar)
- return 'operator'
- }
- stream.eatWhile(/[\w\$_]/)
- var word = stream.current().toLowerCase()
- if (keywords.hasOwnProperty(word)) {
- return 'keyword'
- }
- if (builtins.hasOwnProperty(word) || dataTypes.hasOwnProperty(word)) {
- return 'builtin'
- }
- return 'variable'
- }
- function tokenString(quote) {
- return function (stream, state) {
- var escaped = false,
- next,
- end = false
- while ((next = stream.next()) != null) {
- if (next == quote && !escaped) {
- end = true
- break
- }
- escaped = !escaped && next == '\\'
- }
- if (end || !escaped) state.tokenize = null
- return 'string'
- }
- }
- // Interface
- return {
- startState: function () {
- return { tokenize: null }
- },
- token: function (stream, state) {
- if (stream.eatSpace()) return null
- var style = (state.tokenize || tokenBase)(stream, state)
- if (style == 'comment' || style == 'meta') return style
- return style
- },
- }
- })
- CodeMirror.defineMIME('text/x-fortran', 'fortran')
- })
|