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

200 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
/*
Language: Dart
Requires: markdown.js
Author: Maxim Dikun <dikmax@gmail.com>
Description: Dart a modern, object-oriented language developed by Google. For more information see https://www.dartlang.org/
Website: https://dart.dev
Category: scripting
*/
/** @type LanguageFn */
function dart(hljs) {
const SUBST = {
2023-12-18 13:12:25 +08:00
className: 'subst',
2024-01-16 21:26:16 +08:00
variants: [{
begin: '\\$[A-Za-z0-9_]+'
}]
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const BRACED_SUBST = {
2023-12-18 13:12:25 +08:00
className: 'subst',
2024-01-16 21:26:16 +08:00
variants: [{
begin: /\$\{/,
end: /\}/
}],
keywords: 'true false null this is new super'
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const STRING = {
2023-12-18 13:12:25 +08:00
className: 'string',
variants: [
{
2024-01-16 21:26:16 +08:00
begin: 'r\'\'\'',
end: '\'\'\''
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: 'r"""',
end: '"""'
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: 'r\'',
end: '\'',
2023-12-18 13:12:25 +08:00
illegal: '\\n'
},
{
2024-01-16 21:26:16 +08:00
begin: 'r"',
end: '"',
2023-12-18 13:12:25 +08:00
illegal: '\\n'
},
{
2024-01-16 21:26:16 +08:00
begin: '\'\'\'',
end: '\'\'\'',
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST,
BRACED_SUBST
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: '"""',
end: '"""',
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST,
BRACED_SUBST
]
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
illegal: '\\n',
2024-01-16 21:26:16 +08:00
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST,
BRACED_SUBST
]
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
illegal: '\\n',
2024-01-16 21:26:16 +08:00
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST,
BRACED_SUBST
]
2023-12-18 13:12:25 +08:00
}
]
};
BRACED_SUBST.contains = [
2024-01-16 21:26:16 +08:00
hljs.C_NUMBER_MODE,
STRING
];
const BUILT_IN_TYPES = [
// dart:core
'Comparable',
'DateTime',
'Duration',
'Function',
'Iterable',
'Iterator',
'List',
'Map',
'Match',
'Object',
'Pattern',
'RegExp',
'Set',
'Stopwatch',
'String',
'StringBuffer',
'StringSink',
'Symbol',
'Type',
'Uri',
'bool',
'double',
'int',
'num',
// dart:html
'Element',
'ElementList'
2023-12-18 13:12:25 +08:00
];
2024-01-16 21:26:16 +08:00
const NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`);
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
const KEYWORDS = {
keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' +
'dynamic else enum export extends extension external factory false final finally for Function get hide if ' +
'implements import in inferface is late library mixin new null on operator part required rethrow return set ' +
'show static super switch sync this throw true try typedef var void while with yield',
2023-12-18 13:12:25 +08:00
built_in:
2024-01-16 21:26:16 +08:00
BUILT_IN_TYPES
.concat(NULLABLE_BUILT_IN_TYPES)
.concat([
// dart:core
'Never',
'Null',
'dynamic',
'print',
// dart:html
'document',
'querySelector',
'querySelectorAll',
'window'
]),
$pattern: /[A-Za-z][A-Za-z0-9_]*\??/
2023-12-18 13:12:25 +08:00
};
return {
2024-01-16 21:26:16 +08:00
name: 'Dart',
2023-12-18 13:12:25 +08:00
keywords: KEYWORDS,
contains: [
STRING,
hljs.COMMENT(
2024-01-16 21:26:16 +08:00
/\/\*\*(?!\/)/,
/\*\//,
2023-12-18 13:12:25 +08:00
{
2024-01-16 21:26:16 +08:00
subLanguage: 'markdown',
relevance: 0
2023-12-18 13:12:25 +08:00
}
),
hljs.COMMENT(
2024-01-16 21:26:16 +08:00
/\/{3,} ?/,
/$/, {
contains: [{
subLanguage: 'markdown',
begin: '.',
end: '$',
relevance: 0
}]
2023-12-18 13:12:25 +08:00
}
),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
{
className: 'class',
2024-01-16 21:26:16 +08:00
beginKeywords: 'class interface',
end: /\{/,
excludeEnd: true,
2023-12-18 13:12:25 +08:00
contains: [
{
beginKeywords: 'extends implements'
},
hljs.UNDERSCORE_TITLE_MODE
]
},
hljs.C_NUMBER_MODE,
{
2024-01-16 21:26:16 +08:00
className: 'meta',
begin: '@[A-Za-z]+'
2023-12-18 13:12:25 +08:00
},
{
begin: '=>' // No markup, just a relevance booster
}
]
2024-01-16 21:26:16 +08:00
};
}
module.exports = dart;