gams.js 4.5 KB

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