gams.js (4898B)
1 /* 2 Language: GAMS 3 Author: Stefan Bechert <stefan.bechert@gmx.net> 4 Contributors: Oleg Efimov <efimovov@gmail.com>, Mikko Kouhia <mikko.kouhia@iki.fi> 5 Description: The General Algebraic Modeling System language 6 Website: https://www.gams.com 7 Category: scientific 8 */ 9 10 function gams (hljs) { 11 var KEYWORDS = { 12 keyword: 13 'abort acronym acronyms alias all and assign binary card diag display ' + 14 'else eq file files for free ge gt if integer le loop lt maximizing ' + 15 'minimizing model models ne negative no not option options or ord ' + 16 'positive prod put putpage puttl repeat sameas semicont semiint smax ' + 17 'smin solve sos1 sos2 sum system table then until using while xor yes', 18 literal: 'eps inf na', 19 built_in: 20 'abs arccos arcsin arctan arctan2 Beta betaReg binomial ceil centropy ' + 21 'cos cosh cvPower div div0 eDist entropy errorf execSeed exp fact ' + 22 'floor frac gamma gammaReg log logBeta logGamma log10 log2 mapVal max ' + 23 'min mod ncpCM ncpF ncpVUpow ncpVUsin normal pi poly power ' + 24 'randBinomial randLinear randTriangle round rPower sigmoid sign ' + 25 'signPower sin sinh slexp sllog10 slrec sqexp sqlog10 sqr sqrec sqrt ' + 26 'tan tanh trunc uniform uniformInt vcPower bool_and bool_eqv bool_imp ' + 27 'bool_not bool_or bool_xor ifThen rel_eq rel_ge rel_gt rel_le rel_lt ' + 28 'rel_ne gday gdow ghour gleap gmillisec gminute gmonth gsecond gyear ' + 29 'jdate jnow jstart jtime errorLevel execError gamsRelease gamsVersion ' + 30 'handleCollect handleDelete handleStatus handleSubmit heapFree ' + 31 'heapLimit heapSize jobHandle jobKill jobStatus jobTerminate ' + 32 'licenseLevel licenseStatus maxExecError sleep timeClose timeComp ' + 33 'timeElapsed timeExec timeStart' 34 }; 35 var PARAMS = { 36 className: 'params', 37 begin: /\(/, end: /\)/, 38 excludeBegin: true, 39 excludeEnd: true, 40 }; 41 var SYMBOLS = { 42 className: 'symbol', 43 variants: [ 44 {begin: /\=[lgenxc]=/}, 45 {begin: /\$/}, 46 ] 47 }; 48 var QSTR = { // One-line quoted comment string 49 className: 'comment', 50 variants: [ 51 {begin: '\'', end: '\''}, 52 {begin: '"', end: '"'}, 53 ], 54 illegal: '\\n', 55 contains: [hljs.BACKSLASH_ESCAPE] 56 }; 57 var ASSIGNMENT = { 58 begin: '/', 59 end: '/', 60 keywords: KEYWORDS, 61 contains: [ 62 QSTR, 63 hljs.C_LINE_COMMENT_MODE, 64 hljs.C_BLOCK_COMMENT_MODE, 65 hljs.QUOTE_STRING_MODE, 66 hljs.APOS_STRING_MODE, 67 hljs.C_NUMBER_MODE, 68 ], 69 }; 70 var DESCTEXT = { // Parameter/set/variable description text 71 begin: /[a-z][a-z0-9_]*(\([a-z0-9_, ]*\))?[ \t]+/, 72 excludeBegin: true, 73 end: '$', 74 endsWithParent: true, 75 contains: [ 76 QSTR, 77 ASSIGNMENT, 78 { 79 className: 'comment', 80 begin: /([ ]*[a-z0-9&#*=?@>\\<:\-,()$\[\]_.{}!+%^]+)+/, 81 relevance: 0 82 }, 83 ], 84 }; 85 86 return { 87 name: 'GAMS', 88 aliases: ['gms'], 89 case_insensitive: true, 90 keywords: KEYWORDS, 91 contains: [ 92 hljs.COMMENT(/^\$ontext/, /^\$offtext/), 93 { 94 className: 'meta', 95 begin: '^\\$[a-z0-9]+', 96 end: '$', 97 returnBegin: true, 98 contains: [ 99 { 100 className: 'meta-keyword', 101 begin: '^\\$[a-z0-9]+', 102 } 103 ] 104 }, 105 hljs.COMMENT('^\\*', '$'), 106 hljs.C_LINE_COMMENT_MODE, 107 hljs.C_BLOCK_COMMENT_MODE, 108 hljs.QUOTE_STRING_MODE, 109 hljs.APOS_STRING_MODE, 110 // Declarations 111 { 112 beginKeywords: 113 'set sets parameter parameters variable variables ' + 114 'scalar scalars equation equations', 115 end: ';', 116 contains: [ 117 hljs.COMMENT('^\\*', '$'), 118 hljs.C_LINE_COMMENT_MODE, 119 hljs.C_BLOCK_COMMENT_MODE, 120 hljs.QUOTE_STRING_MODE, 121 hljs.APOS_STRING_MODE, 122 ASSIGNMENT, 123 DESCTEXT, 124 ] 125 }, 126 { // table environment 127 beginKeywords: 'table', 128 end: ';', 129 returnBegin: true, 130 contains: [ 131 { // table header row 132 beginKeywords: 'table', 133 end: '$', 134 contains: [DESCTEXT], 135 }, 136 hljs.COMMENT('^\\*', '$'), 137 hljs.C_LINE_COMMENT_MODE, 138 hljs.C_BLOCK_COMMENT_MODE, 139 hljs.QUOTE_STRING_MODE, 140 hljs.APOS_STRING_MODE, 141 hljs.C_NUMBER_MODE, 142 // Table does not contain DESCTEXT or ASSIGNMENT 143 ] 144 }, 145 // Function definitions 146 { 147 className: 'function', 148 begin: /^[a-z][a-z0-9_,\-+' ()$]+\.{2}/, 149 returnBegin: true, 150 contains: [ 151 { // Function title 152 className: 'title', 153 begin: /^[a-z0-9_]+/, 154 }, 155 PARAMS, 156 SYMBOLS, 157 ], 158 }, 159 hljs.C_NUMBER_MODE, 160 SYMBOLS, 161 ] 162 }; 163 } 164 165 module.exports = gams;