abnf.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Language: Augmented Backus-Naur Form
  3. Author: Alex McKibben <alex@nullscope.net>
  4. Website: https://tools.ietf.org/html/rfc5234
  5. Category: syntax
  6. Audit: 2020
  7. */
  8. /** @type LanguageFn */
  9. function abnf(hljs) {
  10. const regex = hljs.regex;
  11. const IDENT = /^[a-zA-Z][a-zA-Z0-9-]*/;
  12. const KEYWORDS = [
  13. "ALPHA",
  14. "BIT",
  15. "CHAR",
  16. "CR",
  17. "CRLF",
  18. "CTL",
  19. "DIGIT",
  20. "DQUOTE",
  21. "HEXDIG",
  22. "HTAB",
  23. "LF",
  24. "LWSP",
  25. "OCTET",
  26. "SP",
  27. "VCHAR",
  28. "WSP"
  29. ];
  30. const COMMENT = hljs.COMMENT(/;/, /$/);
  31. const TERMINAL_BINARY = {
  32. scope: "symbol",
  33. match: /%b[0-1]+(-[0-1]+|(\.[0-1]+)+)?/
  34. };
  35. const TERMINAL_DECIMAL = {
  36. scope: "symbol",
  37. match: /%d[0-9]+(-[0-9]+|(\.[0-9]+)+)?/
  38. };
  39. const TERMINAL_HEXADECIMAL = {
  40. scope: "symbol",
  41. match: /%x[0-9A-F]+(-[0-9A-F]+|(\.[0-9A-F]+)+)?/
  42. };
  43. const CASE_SENSITIVITY = {
  44. scope: "symbol",
  45. match: /%[si](?=".*")/
  46. };
  47. const RULE_DECLARATION = {
  48. scope: "attribute",
  49. match: regex.concat(IDENT, /(?=\s*=)/)
  50. };
  51. const ASSIGNMENT = {
  52. scope: "operator",
  53. match: /=\/?/
  54. };
  55. return {
  56. name: 'Augmented Backus-Naur Form',
  57. illegal: /[!@#$^&',?+~`|:]/,
  58. keywords: KEYWORDS,
  59. contains: [
  60. ASSIGNMENT,
  61. RULE_DECLARATION,
  62. COMMENT,
  63. TERMINAL_BINARY,
  64. TERMINAL_DECIMAL,
  65. TERMINAL_HEXADECIMAL,
  66. CASE_SENSITIVITY,
  67. hljs.QUOTE_STRING_MODE,
  68. hljs.NUMBER_MODE
  69. ]
  70. };
  71. }
  72. export { abnf as default };