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

357 lines
6.4 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
const KEYWORDS = [
"as", // for exports
"in",
"of",
"if",
"for",
"while",
"finally",
"var",
"new",
"function",
"do",
"return",
"void",
"else",
"break",
"catch",
"instanceof",
"with",
"throw",
"case",
"default",
"try",
"switch",
"continue",
"typeof",
"delete",
"let",
"yield",
"const",
"class",
// JS handles these with a special rule
// "get",
// "set",
"debugger",
"async",
"await",
"static",
"import",
"from",
"export",
"extends"
];
const LITERALS = [
"true",
"false",
"null",
"undefined",
"NaN",
"Infinity"
];
const TYPES = [
"Intl",
"DataView",
"Number",
"Math",
"Date",
"String",
"RegExp",
"Object",
"Function",
"Boolean",
"Error",
"Symbol",
"Set",
"Map",
"WeakSet",
"WeakMap",
"Proxy",
"Reflect",
"JSON",
"Promise",
"Float64Array",
"Int16Array",
"Int32Array",
"Int8Array",
"Uint16Array",
"Uint32Array",
"Float32Array",
"Array",
"Uint8Array",
"Uint8ClampedArray",
"ArrayBuffer",
"BigInt64Array",
"BigUint64Array",
"BigInt"
];
const ERROR_TYPES = [
"EvalError",
"InternalError",
"RangeError",
"ReferenceError",
"SyntaxError",
"TypeError",
"URIError"
];
const BUILT_IN_GLOBALS = [
"setInterval",
"setTimeout",
"clearInterval",
"clearTimeout",
"require",
"exports",
"eval",
"isFinite",
"isNaN",
"parseFloat",
"parseInt",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"escape",
"unescape"
];
const BUILT_IN_VARIABLES = [
"arguments",
"this",
"super",
"console",
"window",
"document",
"localStorage",
"module",
"global" // Node.js
];
const BUILT_INS = [].concat(
BUILT_IN_GLOBALS,
BUILT_IN_VARIABLES,
TYPES,
ERROR_TYPES
);
/*
Language: CoffeeScript
Author: Dmytrii Nagirniak <dnagir@gmail.com>
Contributors: Oleg Efimov <efimovov@gmail.com>, Cédric Néhémie <cedric.nehemie@gmail.com>
Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
Category: common, scripting
Website: https://coffeescript.org
*/
/** @type LanguageFn */
function coffeescript(hljs) {
const COFFEE_BUILT_INS = [
'npm',
'print'
];
const COFFEE_LITERALS = [
'yes',
'no',
'on',
'off'
];
const COFFEE_KEYWORDS = [
'then',
'unless',
'until',
'loop',
'by',
'when',
'and',
'or',
'is',
'isnt',
'not'
];
const NOT_VALID_KEYWORDS = [
"var",
"const",
"let",
"function",
"static"
];
const excluding = (list) =>
(kw) => !list.includes(kw);
const KEYWORDS$1 = {
keyword: KEYWORDS.concat(COFFEE_KEYWORDS).filter(excluding(NOT_VALID_KEYWORDS)),
literal: LITERALS.concat(COFFEE_LITERALS),
built_in: BUILT_INS.concat(COFFEE_BUILT_INS)
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
const SUBST = {
2023-12-18 13:12:25 +08:00
className: 'subst',
2024-01-16 21:26:16 +08:00
begin: /#\{/,
end: /\}/,
keywords: KEYWORDS$1
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const EXPRESSIONS = [
2023-12-18 13:12:25 +08:00
hljs.BINARY_NUMBER_MODE,
2024-01-16 21:26:16 +08:00
hljs.inherit(hljs.C_NUMBER_MODE, {
starts: {
end: '(\\s*/)?',
relevance: 0
}
}), // a number tries to eat the following slash to prevent treating it as a regexp
2023-12-18 13:12:25 +08:00
{
className: 'string',
variants: [
{
2024-01-16 21:26:16 +08:00
begin: /'''/,
end: /'''/,
2023-12-18 13:12:25 +08:00
contains: [hljs.BACKSLASH_ESCAPE]
},
{
2024-01-16 21:26:16 +08:00
begin: /'/,
end: /'/,
2023-12-18 13:12:25 +08:00
contains: [hljs.BACKSLASH_ESCAPE]
},
{
2024-01-16 21:26:16 +08:00
begin: /"""/,
end: /"""/,
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: /"/,
end: /"/,
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST
]
2023-12-18 13:12:25 +08:00
}
]
},
{
className: 'regexp',
variants: [
{
2024-01-16 21:26:16 +08:00
begin: '///',
end: '///',
contains: [
SUBST,
hljs.HASH_COMMENT_MODE
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: '//[gim]{0,3}(?=\\W)',
2023-12-18 13:12:25 +08:00
relevance: 0
},
{
// regex can't start with space to parse x / 2 / 3 as two divisions
// regex can't start with *, and it supports an "illegal" in the main mode
2024-01-16 21:26:16 +08:00
begin: /\/(?![ *]).*?(?![\\]).\/[gim]{0,3}(?=\W)/
2023-12-18 13:12:25 +08:00
}
]
},
{
begin: '@' + JS_IDENT_RE // relevance booster
},
{
subLanguage: 'javascript',
2024-01-16 21:26:16 +08:00
excludeBegin: true,
excludeEnd: true,
2023-12-18 13:12:25 +08:00
variants: [
{
2024-01-16 21:26:16 +08:00
begin: '```',
end: '```'
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: '`',
end: '`'
2023-12-18 13:12:25 +08:00
}
]
}
];
SUBST.contains = EXPRESSIONS;
2024-01-16 21:26:16 +08:00
const TITLE = hljs.inherit(hljs.TITLE_MODE, {
begin: JS_IDENT_RE
});
const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
const PARAMS = {
2023-12-18 13:12:25 +08:00
className: 'params',
2024-01-16 21:26:16 +08:00
begin: '\\([^\\(]',
returnBegin: true,
2023-12-18 13:12:25 +08:00
/* We need another contained nameless mode to not have every nested
pair of parens to be called "params" */
contains: [{
2024-01-16 21:26:16 +08:00
begin: /\(/,
end: /\)/,
keywords: KEYWORDS$1,
2023-12-18 13:12:25 +08:00
contains: ['self'].concat(EXPRESSIONS)
}]
};
return {
2024-01-16 21:26:16 +08:00
name: 'CoffeeScript',
aliases: [
'coffee',
'cson',
'iced'
],
keywords: KEYWORDS$1,
2023-12-18 13:12:25 +08:00
illegal: /\/\*/,
contains: EXPRESSIONS.concat([
hljs.COMMENT('###', '###'),
hljs.HASH_COMMENT_MODE,
{
className: 'function',
2024-01-16 21:26:16 +08:00
begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
end: '[-=]>',
2023-12-18 13:12:25 +08:00
returnBegin: true,
2024-01-16 21:26:16 +08:00
contains: [
TITLE,
PARAMS
]
2023-12-18 13:12:25 +08:00
},
{
// anonymous function start
begin: /[:\(,=]\s*/,
relevance: 0,
2024-01-16 21:26:16 +08:00
contains: [{
className: 'function',
begin: POSSIBLE_PARAMS_RE,
end: '[-=]>',
returnBegin: true,
contains: [PARAMS]
}]
2023-12-18 13:12:25 +08:00
},
{
className: 'class',
beginKeywords: 'class',
end: '$',
illegal: /[:="\[\]]/,
contains: [
{
beginKeywords: 'extends',
endsWithParent: true,
illegal: /[:="\[\]]/,
contains: [TITLE]
},
TITLE
]
},
{
2024-01-16 21:26:16 +08:00
begin: JS_IDENT_RE + ':',
end: ':',
returnBegin: true,
returnEnd: true,
2023-12-18 13:12:25 +08:00
relevance: 0
}
])
};
2024-01-16 21:26:16 +08:00
}
module.exports = coffeescript;