gams.js 4.8 KB

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