prism-abnf.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. (function (Prism) {
  2. var coreRules = '(?:ALPHA|BIT|CHAR|CR|CRLF|CTL|DIGIT|DQUOTE|HEXDIG|HTAB|LF|LWSP|OCTET|SP|VCHAR|WSP)';
  3. Prism.languages.abnf = {
  4. 'comment': /;.*/,
  5. 'string': {
  6. pattern: /(?:%[is])?"[^"\n\r]*"/,
  7. greedy: true,
  8. inside: {
  9. 'punctuation': /^%[is]/
  10. }
  11. },
  12. 'range': {
  13. pattern: /%(?:b[01]+-[01]+|d\d+-\d+|x[A-F\d]+-[A-F\d]+)/i,
  14. alias: 'number'
  15. },
  16. 'terminal': {
  17. pattern: /%(?:b[01]+(?:\.[01]+)*|d\d+(?:\.\d+)*|x[A-F\d]+(?:\.[A-F\d]+)*)/i,
  18. alias: 'number'
  19. },
  20. 'repetition': {
  21. pattern: /(^|[^\w-])(?:\d*\*\d*|\d+)/,
  22. lookbehind: true,
  23. alias: 'operator'
  24. },
  25. 'definition': {
  26. pattern: /(^[ \t]*)(?:[a-z][\w-]*|<[^<>\r\n]*>)(?=\s*=)/m,
  27. lookbehind: true,
  28. alias: 'keyword',
  29. inside: {
  30. 'punctuation': /<|>/
  31. }
  32. },
  33. 'core-rule': {
  34. pattern: RegExp('(?:(^|[^<\\w-])' + coreRules + '|<' + coreRules + '>)(?![\\w-])', 'i'),
  35. lookbehind: true,
  36. alias: ['rule', 'constant'],
  37. inside: {
  38. 'punctuation': /<|>/
  39. }
  40. },
  41. 'rule': {
  42. pattern: /(^|[^<\w-])[a-z][\w-]*|<[^<>\r\n]*>/i,
  43. lookbehind: true,
  44. inside: {
  45. 'punctuation': /<|>/
  46. }
  47. },
  48. 'operator': /=\/?|\//,
  49. 'punctuation': /[()\[\]]/
  50. };
  51. }(Prism));