(function (Prism) {
const NON_ID = '\\s\\\\/(){}\\[\\]"#;=';
const IDENT_BODY = `[^${NON_ID}]`;
const IDENT =
'(?:' +
`[+\\-]?\\.(?:[^${NON_ID}0-9]${IDENT_BODY}*)?` +
'|' +
`[+\\-](?:[^${NON_ID}0-9.]${IDENT_BODY}*)?` +
'|' +
`[^${NON_ID}0-9+\\-.]${IDENT_BODY}*` +
')';
const QUOTED = '"(?:\\\\[\\s\\S]|[^"\\\\\\r\\n])*"';
const STRINGY = `(?:${QUOTED}|${IDENT})`;
Prism.languages.kdl = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
greedy: true,
},
'slashdash': {
pattern: /\/-/,
alias: 'comment',
},
'raw-string': {
pattern: /(#+)"""[\s\S]*?"""\1|(#+)"[\s\S]*?"\2|r(#*)"""[\s\S]*?"""\3|r(#*)"[\s\S]*?"\4/,
greedy: true,
alias: 'string',
},
'property': {
pattern: RegExp(`${STRINGY}(?=\\s*=[^=])`),
greedy: true,
alias: 'attr-name',
},
'string': {
pattern: /"""[\s\S]*?"""|"(?:\\[\s\S]|[^"\\\r\n])*"/,
greedy: true,
},
'type-annotation': {
pattern: RegExp(`\\(\\s*${STRINGY}\\s*\\)`),
inside: {
'class-name': RegExp(STRINGY),
'punctuation': /[()]/,
},
},
'keyword': /#(?:true|false|null|-inf|inf|nan)\b|\b(?:true|false|null)\b/,
'number': /[+-]?(?:0x[\da-fA-F][\da-fA-F_]*|0o[0-7][0-7_]*|0b[01][01_]*|\d[\d_]*(?:\.\d[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)/,
'tag': {
pattern: RegExp(`(^[\\t ]*|[{;)][\\t ]*)${STRINGY}`, 'm'),
lookbehind: true,
greedy: true,
},
'punctuation': /[{};=\\]/,
};
})(Prism);