ebnf.js 1011 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Language: Extended Backus-Naur Form
  3. Author: Alex McKibben <alex@nullscope.net>
  4. Website: https://en.wikipedia.org/wiki/Extended_Backus–Naur_form
  5. Category: syntax
  6. */
  7. /** @type LanguageFn */
  8. function ebnf(hljs) {
  9. const commentMode = hljs.COMMENT(/\(\*/, /\*\)/);
  10. const nonTerminalMode = {
  11. className: "attribute",
  12. begin: /^[ ]*[a-zA-Z]+([\s_-]+[a-zA-Z]+)*/
  13. };
  14. const specialSequenceMode = {
  15. className: "meta",
  16. begin: /\?.*\?/
  17. };
  18. const ruleBodyMode = {
  19. begin: /=/,
  20. end: /[.;]/,
  21. contains: [
  22. commentMode,
  23. specialSequenceMode,
  24. {
  25. // terminals
  26. className: 'string',
  27. variants: [
  28. hljs.APOS_STRING_MODE,
  29. hljs.QUOTE_STRING_MODE,
  30. {
  31. begin: '`',
  32. end: '`'
  33. }
  34. ]
  35. }
  36. ]
  37. };
  38. return {
  39. name: 'Extended Backus-Naur Form',
  40. illegal: /\S/,
  41. contains: [
  42. commentMode,
  43. nonTerminalMode,
  44. ruleBodyMode
  45. ]
  46. };
  47. }
  48. export { ebnf as default };