1
0

gams.js 4.7 KB

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