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

375 lines
6.8 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: LiveScript
Author: Taneli Vatanen <taneli.vatanen@gmail.com>
Contributors: Jen Evers-Corvina <jen@sevvie.net>
Origin: coffeescript.js
Description: LiveScript is a programming language that transcompiles to JavaScript. For info about language see http://livescript.net/
Website: https://livescript.net
Category: scripting
*/
function livescript(hljs) {
const LIVESCRIPT_BUILT_INS = [
'npm',
'print'
];
const LIVESCRIPT_LITERALS = [
'yes',
'no',
'on',
'off',
'it',
'that',
'void'
];
const LIVESCRIPT_KEYWORDS = [
'then',
'unless',
'until',
'loop',
'of',
'by',
'when',
'and',
'or',
'is',
'isnt',
'not',
'it',
'that',
'otherwise',
'from',
'to',
'til',
'fallthrough',
'case',
'enum',
'native',
'list',
'map',
'__hasProp',
'__extends',
'__slice',
'__bind',
'__indexOf'
];
const KEYWORDS$1 = {
keyword: KEYWORDS.concat(LIVESCRIPT_KEYWORDS),
literal: LITERALS.concat(LIVESCRIPT_LITERALS),
built_in: BUILT_INS.concat(LIVESCRIPT_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$_]|[0-9A-Za-z$_])*';
const TITLE = hljs.inherit(hljs.TITLE_MODE, {
begin: JS_IDENT_RE
});
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 SUBST_SIMPLE = {
2023-12-18 13:12:25 +08:00
className: 'subst',
2024-01-16 21:26:16 +08:00
begin: /#[A-Za-z$_]/,
end: /(?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*/,
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,
{
className: 'number',
begin: '(\\b0[xX][a-fA-F0-9_]+)|(\\b\\d(\\d|_\\d)*(\\.(\\d(\\d|_\\d)*)?)?(_*[eE]([-+]\\d(_\\d|\\d)*)?)?[_a-z]*)',
relevance: 0,
2024-01-16 21:26:16 +08:00
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,
SUBST_SIMPLE
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: /"/,
end: /"/,
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST,
SUBST_SIMPLE
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: /\\/,
end: /(\s|$)/,
2023-12-18 13:12:25 +08:00
excludeEnd: true
}
]
},
{
className: 'regexp',
variants: [
{
2024-01-16 21:26:16 +08:00
begin: '//',
end: '//[gim]*',
contains: [
SUBST,
hljs.HASH_COMMENT_MODE
]
2023-12-18 13:12:25 +08:00
},
{
// 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: /\/(?![ *])(\\.|[^\\\n])*?\/[gim]*(?=\W)/
2023-12-18 13:12:25 +08:00
}
]
},
{
begin: '@' + JS_IDENT_RE
},
{
2024-01-16 21:26:16 +08:00
begin: '``',
end: '``',
excludeBegin: true,
excludeEnd: true,
2023-12-18 13:12:25 +08:00
subLanguage: 'javascript'
}
];
SUBST.contains = EXPRESSIONS;
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: '\\(',
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)
}
]
};
2024-01-16 21:26:16 +08:00
const SYMBOLS = {
begin: '(#=>|=>|\\|>>|-?->|!->)'
};
2023-12-18 13:12:25 +08:00
return {
2024-01-16 21:26:16 +08:00
name: 'LiveScript',
2023-12-18 13:12:25 +08:00
aliases: ['ls'],
2024-01-16 21:26:16 +08:00
keywords: KEYWORDS$1,
2023-12-18 13:12:25 +08:00
illegal: /\/\*/,
contains: EXPRESSIONS.concat([
hljs.COMMENT('\\/\\*', '\\*\\/'),
hljs.HASH_COMMENT_MODE,
2024-01-16 21:26:16 +08:00
SYMBOLS, // relevance booster
2023-12-18 13:12:25 +08:00
{
className: 'function',
2024-01-16 21:26:16 +08:00
contains: [
TITLE,
PARAMS
],
2023-12-18 13:12:25 +08:00
returnBegin: true,
variants: [
{
2024-01-16 21:26:16 +08:00
begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B->\\*?',
end: '->\\*?'
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?!?(\\(.*\\)\\s*)?\\B[-~]{1,2}>\\*?',
end: '[-~]{1,2}>\\*?'
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B!?[-~]{1,2}>\\*?',
end: '!?[-~]{1,2}>\\*?'
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 = livescript;