prism-lilypond.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. (function (Prism) {
  2. var schemeExpression = /\((?:[^();"#\\]|\\[\s\S]|;.*(?!.)|"(?:[^"\\]|\\.)*"|#(?:\{(?:(?!#\})[\s\S])*#\}|[^{])|<expr>)*\)/.source;
  3. // allow for up to pow(2, recursivenessLog2) many levels of recursive brace expressions
  4. // For some reason, this can't be 4
  5. var recursivenessLog2 = 5;
  6. for (var i = 0; i < recursivenessLog2; i++) {
  7. schemeExpression = schemeExpression.replace(/<expr>/g, function () { return schemeExpression; });
  8. }
  9. schemeExpression = schemeExpression.replace(/<expr>/g, /[^\s\S]/.source);
  10. var lilypond = Prism.languages.lilypond = {
  11. 'comment': /%(?:(?!\{).*|\{[\s\S]*?%\})/,
  12. 'embedded-scheme': {
  13. pattern: RegExp(/(^|[=\s])#(?:"(?:[^"\\]|\\.)*"|[^\s()"]*(?:[^\s()]|<expr>))/.source.replace(/<expr>/g, function () { return schemeExpression; }), 'm'),
  14. lookbehind: true,
  15. greedy: true,
  16. inside: {
  17. 'scheme': {
  18. pattern: /^(#)[\s\S]+$/,
  19. lookbehind: true,
  20. alias: 'language-scheme',
  21. inside: {
  22. 'embedded-lilypond': {
  23. pattern: /#\{[\s\S]*?#\}/,
  24. greedy: true,
  25. inside: {
  26. 'punctuation': /^#\{|#\}$/,
  27. 'lilypond': {
  28. pattern: /[\s\S]+/,
  29. alias: 'language-lilypond',
  30. inside: null // see below
  31. }
  32. }
  33. },
  34. rest: Prism.languages.scheme
  35. }
  36. },
  37. 'punctuation': /#/
  38. }
  39. },
  40. 'string': {
  41. pattern: /"(?:[^"\\]|\\.)*"/,
  42. greedy: true
  43. },
  44. 'class-name': {
  45. pattern: /(\\new\s+)[\w-]+/,
  46. lookbehind: true
  47. },
  48. 'keyword': {
  49. pattern: /\\[a-z][-\w]*/i,
  50. inside: {
  51. 'punctuation': /^\\/
  52. }
  53. },
  54. 'operator': /[=|]|<<|>>/,
  55. 'punctuation': {
  56. pattern: /(^|[a-z\d])(?:'+|,+|[_^]?-[_^]?(?:[-+^!>._]|(?=\d))|[_^]\.?|[.!])|[{}()[\]<>^~]|\\[()[\]<>\\!]|--|__/,
  57. lookbehind: true
  58. },
  59. 'number': /\b\d+(?:\/\d+)?\b/
  60. };
  61. lilypond['embedded-scheme'].inside['scheme'].inside['embedded-lilypond'].inside['lilypond'].inside = lilypond;
  62. Prism.languages.ly = lilypond;
  63. }(Prism));