source: node_modules/highlight.js/lib/languages/gams.js@ e48199a

main
Last change on this file since e48199a was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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