abnf.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. module.exports = function(hljs) {
  2. var regexes = {
  3. ruleDeclaration: "^[a-zA-Z][a-zA-Z0-9-]*",
  4. unexpectedChars: "[!@#$^&',?+~`|:]"
  5. };
  6. var keywords = [
  7. "ALPHA",
  8. "BIT",
  9. "CHAR",
  10. "CR",
  11. "CRLF",
  12. "CTL",
  13. "DIGIT",
  14. "DQUOTE",
  15. "HEXDIG",
  16. "HTAB",
  17. "LF",
  18. "LWSP",
  19. "OCTET",
  20. "SP",
  21. "VCHAR",
  22. "WSP"
  23. ];
  24. var commentMode = hljs.COMMENT(";", "$");
  25. var terminalBinaryMode = {
  26. className: "symbol",
  27. begin: /%b[0-1]+(-[0-1]+|(\.[0-1]+)+){0,1}/
  28. };
  29. var terminalDecimalMode = {
  30. className: "symbol",
  31. begin: /%d[0-9]+(-[0-9]+|(\.[0-9]+)+){0,1}/
  32. };
  33. var terminalHexadecimalMode = {
  34. className: "symbol",
  35. begin: /%x[0-9A-F]+(-[0-9A-F]+|(\.[0-9A-F]+)+){0,1}/,
  36. };
  37. var caseSensitivityIndicatorMode = {
  38. className: "symbol",
  39. begin: /%[si]/
  40. };
  41. var ruleDeclarationMode = {
  42. className: "attribute",
  43. begin: regexes.ruleDeclaration + '(?=\\s*=)',
  44. };
  45. return {
  46. illegal: regexes.unexpectedChars,
  47. keywords: keywords.join(" "),
  48. contains: [
  49. ruleDeclarationMode,
  50. commentMode,
  51. terminalBinaryMode,
  52. terminalDecimalMode,
  53. terminalHexadecimalMode,
  54. caseSensitivityIndicatorMode,
  55. hljs.QUOTE_STRING_MODE,
  56. hljs.NUMBER_MODE
  57. ]
  58. };
  59. };