abnf.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. begin: regexes.ruleDeclaration + '\\s*=',
  43. returnBegin: true,
  44. end: /=/,
  45. relevance: 0,
  46. contains: [{className: "attribute", begin: regexes.ruleDeclaration}]
  47. };
  48. return {
  49. illegal: regexes.unexpectedChars,
  50. keywords: keywords.join(" "),
  51. contains: [
  52. ruleDeclarationMode,
  53. commentMode,
  54. terminalBinaryMode,
  55. terminalDecimalMode,
  56. terminalHexadecimalMode,
  57. caseSensitivityIndicatorMode,
  58. hljs.QUOTE_STRING_MODE,
  59. hljs.NUMBER_MODE
  60. ]
  61. };
  62. };