ebnf.js 989 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. */
  6. /** @type LanguageFn */
  7. function ebnf(hljs) {
  8. const commentMode = hljs.COMMENT(/\(\*/, /\*\)/);
  9. const nonTerminalMode = {
  10. className: "attribute",
  11. begin: /^[ ]*[a-zA-Z]+([\s_-]+[a-zA-Z]+)*/
  12. };
  13. const specialSequenceMode = {
  14. className: "meta",
  15. begin: /\?.*\?/
  16. };
  17. const ruleBodyMode = {
  18. begin: /=/,
  19. end: /[.;]/,
  20. contains: [
  21. commentMode,
  22. specialSequenceMode,
  23. {
  24. // terminals
  25. className: 'string',
  26. variants: [
  27. hljs.APOS_STRING_MODE,
  28. hljs.QUOTE_STRING_MODE,
  29. {
  30. begin: '`',
  31. end: '`'
  32. }
  33. ]
  34. }
  35. ]
  36. };
  37. return {
  38. name: 'Extended Backus-Naur Form',
  39. illegal: /\S/,
  40. contains: [
  41. commentMode,
  42. nonTerminalMode,
  43. ruleBodyMode
  44. ]
  45. };
  46. }
  47. module.exports = ebnf;