gams.js 5.1 KB

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