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

104 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
/**
* @param {string} value
* @returns {RegExp}
* */
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
/**
* @param {RegExp | string } re
* @returns {string}
*/
function source(re) {
if (!re) return null;
if (typeof re === "string") return re;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
return re.source;
}
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
/**
* @param {...(RegExp | string) } args
* @returns {string}
*/
function concat(...args) {
const joined = args.map((x) => source(x)).join("");
return joined;
}
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
/*
Language: Augmented Backus-Naur Form
Author: Alex McKibben <alex@nullscope.net>
Website: https://tools.ietf.org/html/rfc5234
Audit: 2020
*/
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
/** @type LanguageFn */
function abnf(hljs) {
const regexes = {
ruleDeclaration: /^[a-zA-Z][a-zA-Z0-9-]*/,
unexpectedChars: /[!@#$^&',?+~`|:]/
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
const keywords = [
"ALPHA",
"BIT",
"CHAR",
"CR",
"CRLF",
"CTL",
"DIGIT",
"DQUOTE",
"HEXDIG",
"HTAB",
"LF",
"LWSP",
"OCTET",
"SP",
"VCHAR",
"WSP"
];
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
const commentMode = hljs.COMMENT(/;/, /$/);
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
const terminalBinaryMode = {
className: "symbol",
begin: /%b[0-1]+(-[0-1]+|(\.[0-1]+)+){0,1}/
};
const terminalDecimalMode = {
className: "symbol",
begin: /%d[0-9]+(-[0-9]+|(\.[0-9]+)+){0,1}/
};
const terminalHexadecimalMode = {
className: "symbol",
begin: /%x[0-9A-F]+(-[0-9A-F]+|(\.[0-9A-F]+)+){0,1}/
};
const caseSensitivityIndicatorMode = {
className: "symbol",
begin: /%[si]/
};
const ruleDeclarationMode = {
className: "attribute",
begin: concat(regexes.ruleDeclaration, /(?=\s*=)/)
};
return {
name: 'Augmented Backus-Naur Form',
illegal: regexes.unexpectedChars,
keywords: keywords,
contains: [
ruleDeclarationMode,
commentMode,
terminalBinaryMode,
terminalDecimalMode,
terminalHexadecimalMode,
caseSensitivityIndicatorMode,
hljs.QUOTE_STRING_MODE,
hljs.NUMBER_MODE
]
};
}
module.exports = abnf;