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