1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/highlight.js/lib/languages/gams.js

209 lines
5.3 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
/**
* @param {string} value
* @returns {RegExp}
* */
/**
* @param {RegExp | string } re
* @returns {string}
*/
function source(re) {
if (!re) return null;
if (typeof re === "string") return re;
return re.source;
}
/**
* @param {RegExp | string } re
* @returns {string}
*/
function anyNumberOfTimes(re) {
return concat('(', re, ')*');
}
/**
* @param {...(RegExp | string) } args
* @returns {string}
*/
function concat(...args) {
const joined = args.map((x) => source(x)).join("");
return joined;
}
/** @type LanguageFn */
function gams(hljs) {
const KEYWORDS = {
keyword:
2023-12-18 13:12:25 +08:00
'abort acronym acronyms alias all and assign binary card diag display ' +
'else eq file files for free ge gt if integer le loop lt maximizing ' +
'minimizing model models ne negative no not option options or ord ' +
'positive prod put putpage puttl repeat sameas semicont semiint smax ' +
'smin solve sos1 sos2 sum system table then until using while xor yes',
2024-01-16 21:26:16 +08:00
literal:
'eps inf na',
built_in:
2023-12-18 13:12:25 +08:00
'abs arccos arcsin arctan arctan2 Beta betaReg binomial ceil centropy ' +
'cos cosh cvPower div div0 eDist entropy errorf execSeed exp fact ' +
'floor frac gamma gammaReg log logBeta logGamma log10 log2 mapVal max ' +
'min mod ncpCM ncpF ncpVUpow ncpVUsin normal pi poly power ' +
'randBinomial randLinear randTriangle round rPower sigmoid sign ' +
'signPower sin sinh slexp sllog10 slrec sqexp sqlog10 sqr sqrec sqrt ' +
'tan tanh trunc uniform uniformInt vcPower bool_and bool_eqv bool_imp ' +
'bool_not bool_or bool_xor ifThen rel_eq rel_ge rel_gt rel_le rel_lt ' +
'rel_ne gday gdow ghour gleap gmillisec gminute gmonth gsecond gyear ' +
'jdate jnow jstart jtime errorLevel execError gamsRelease gamsVersion ' +
'handleCollect handleDelete handleStatus handleSubmit heapFree ' +
'heapLimit heapSize jobHandle jobKill jobStatus jobTerminate ' +
'licenseLevel licenseStatus maxExecError sleep timeClose timeComp ' +
'timeElapsed timeExec timeStart'
};
2024-01-16 21:26:16 +08:00
const PARAMS = {
2023-12-18 13:12:25 +08:00
className: 'params',
2024-01-16 21:26:16 +08:00
begin: /\(/,
end: /\)/,
2023-12-18 13:12:25 +08:00
excludeBegin: true,
2024-01-16 21:26:16 +08:00
excludeEnd: true
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const SYMBOLS = {
2023-12-18 13:12:25 +08:00
className: 'symbol',
variants: [
2024-01-16 21:26:16 +08:00
{
begin: /=[lgenxc]=/
},
{
begin: /\$/
}
2023-12-18 13:12:25 +08:00
]
};
2024-01-16 21:26:16 +08:00
const QSTR = { // One-line quoted comment string
2023-12-18 13:12:25 +08:00
className: 'comment',
variants: [
2024-01-16 21:26:16 +08:00
{
begin: '\'',
end: '\''
},
{
begin: '"',
end: '"'
}
2023-12-18 13:12:25 +08:00
],
illegal: '\\n',
contains: [hljs.BACKSLASH_ESCAPE]
};
2024-01-16 21:26:16 +08:00
const ASSIGNMENT = {
2023-12-18 13:12:25 +08:00
begin: '/',
end: '/',
keywords: KEYWORDS,
contains: [
QSTR,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
2024-01-16 21:26:16 +08:00
hljs.C_NUMBER_MODE
]
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const COMMENT_WORD = /[a-z0-9&#*=?@\\><:,()$[\]_.{}!+%^-]+/;
const DESCTEXT = { // Parameter/set/variable description text
2023-12-18 13:12:25 +08:00
begin: /[a-z][a-z0-9_]*(\([a-z0-9_, ]*\))?[ \t]+/,
excludeBegin: true,
end: '$',
endsWithParent: true,
contains: [
QSTR,
ASSIGNMENT,
{
className: 'comment',
2024-01-16 21:26:16 +08:00
// one comment word, then possibly more
begin: concat(
COMMENT_WORD,
// [ ] because \s would be too broad (matching newlines)
anyNumberOfTimes(concat(/[ ]+/, COMMENT_WORD))
),
2023-12-18 13:12:25 +08:00
relevance: 0
2024-01-16 21:26:16 +08:00
}
]
2023-12-18 13:12:25 +08:00
};
return {
2024-01-16 21:26:16 +08:00
name: 'GAMS',
2023-12-18 13:12:25 +08:00
aliases: ['gms'],
case_insensitive: true,
keywords: KEYWORDS,
contains: [
hljs.COMMENT(/^\$ontext/, /^\$offtext/),
{
className: 'meta',
begin: '^\\$[a-z0-9]+',
end: '$',
returnBegin: true,
contains: [
{
className: 'meta-keyword',
2024-01-16 21:26:16 +08:00
begin: '^\\$[a-z0-9]+'
2023-12-18 13:12:25 +08:00
}
]
},
hljs.COMMENT('^\\*', '$'),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
// Declarations
{
beginKeywords:
'set sets parameter parameters variable variables ' +
'scalar scalars equation equations',
end: ';',
contains: [
hljs.COMMENT('^\\*', '$'),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
ASSIGNMENT,
2024-01-16 21:26:16 +08:00
DESCTEXT
2023-12-18 13:12:25 +08:00
]
},
{ // table environment
beginKeywords: 'table',
end: ';',
returnBegin: true,
contains: [
{ // table header row
beginKeywords: 'table',
end: '$',
2024-01-16 21:26:16 +08:00
contains: [DESCTEXT]
2023-12-18 13:12:25 +08:00
},
hljs.COMMENT('^\\*', '$'),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
2024-01-16 21:26:16 +08:00
hljs.C_NUMBER_MODE
2023-12-18 13:12:25 +08:00
// Table does not contain DESCTEXT or ASSIGNMENT
]
},
// Function definitions
{
className: 'function',
begin: /^[a-z][a-z0-9_,\-+' ()$]+\.{2}/,
returnBegin: true,
contains: [
2024-01-16 21:26:16 +08:00
{ // Function title
className: 'title',
begin: /^[a-z0-9_]+/
},
PARAMS,
SYMBOLS
]
2023-12-18 13:12:25 +08:00
},
hljs.C_NUMBER_MODE,
2024-01-16 21:26:16 +08:00
SYMBOLS
2023-12-18 13:12:25 +08:00
]
};
2024-01-16 21:26:16 +08:00
}
module.exports = gams;