Skip to content

Commit 5d992fc

Browse files
Added basic support for LilyPond (#1967)
This adds very basic support for LilyPond. More advanced features weren't implemented because the author (me) has no idea about music.
1 parent c93c066 commit 5d992fc

File tree

13 files changed

+247
-3
lines changed

13 files changed

+247
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@
507507
"require": "css",
508508
"owner": "Golmote"
509509
},
510+
"lilypond": {
511+
"title": "LilyPond",
512+
"require": "scheme",
513+
"alias": "ly",
514+
"owner": "RunDevelopment"
515+
},
510516
"liquid": {
511517
"title": "Liquid",
512518
"owner": "cinhtau"

components/prism-lilypond.js

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

components/prism-lilypond.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/autoloader/prism-autoloader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"json5": "json",
5656
"kotlin": "clike",
5757
"less": "css",
58+
"lilypond": "scheme",
5859
"markdown": "markup",
5960
"markup-templating": "markup",
6061
"n4js": "javascript",
@@ -139,6 +140,7 @@
139140
"hs": "haskell",
140141
"tex": "latex",
141142
"context": "latex",
143+
"ly": "lilypond",
142144
"emacs": "lisp",
143145
"elisp": "lisp",
144146
"emacs-lisp": "lisp",

plugins/autoloader/prism-autoloader.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
"latex": "LaTeX",
7878
"tex": "TeX",
7979
"context": "ConTeXt",
80+
"lilypond": "LilyPond",
81+
"ly": "LilyPond",
8082
"emacs": "Lisp",
8183
"elisp": "Lisp",
8284
"emacs-lisp": "Lisp",

plugins/show-language/prism-show-language.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
% single line
2+
3+
%{
4+
multiple lines
5+
%}
6+
7+
----------------------------------------------------
8+
9+
[
10+
["comment", "% single line"],
11+
["comment", "%{\nmultiple lines\n%}"]
12+
]
13+
14+
----------------------------------------------------
15+
16+
Checks for comments.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#(define foo)
2+
3+
#(define-music-function (parser location notes) (ly:music?) #{
4+
% Yes! You can embed LilyPond in Scheme.
5+
\override Score.Stem.beamlet-max-length-proportion = #'(0.5 . 0.5)
6+
#})
7+
8+
##t
9+
10+
#"s t r i n g"
11+
12+
----------------------------------------------------
13+
14+
[
15+
["embedded-scheme", [
16+
["punctuation", "#"],
17+
["scheme", [
18+
["punctuation", "("],
19+
["keyword", "define"],
20+
" foo",
21+
["punctuation", ")"]
22+
]]
23+
]],
24+
25+
["embedded-scheme", [
26+
["punctuation", "#"],
27+
["scheme", [
28+
["punctuation", "("],
29+
["function", "define-music-function"],
30+
["punctuation", "("],
31+
["function", "parser"],
32+
" location notes",
33+
["punctuation", ")"],
34+
["punctuation", "("],
35+
["function", "ly:music?"],
36+
["punctuation", ")"],
37+
["embedded-lilypond", [
38+
["punctuation", "#{"],
39+
["lilypond", [
40+
["comment", "% Yes! You can embed LilyPond in Scheme."],
41+
["keyword", [
42+
["punctuation", "\\"],
43+
"override"
44+
]],
45+
" Score",
46+
["punctuation", "."],
47+
"Stem",
48+
["punctuation", "."],
49+
"beamlet-max-length-proportion ",
50+
["operator", "="],
51+
["embedded-scheme", [
52+
["punctuation", "#"],
53+
["scheme", [
54+
["punctuation", "'"],
55+
["punctuation", "("],
56+
["number", "0.5"],
57+
" . ",
58+
["number", "0.5"],
59+
["punctuation", ")"]
60+
]]
61+
]]
62+
]],
63+
["punctuation", "#}"]
64+
]],
65+
["punctuation", ")"]
66+
]]
67+
]],
68+
69+
["embedded-scheme", [
70+
["punctuation", "#"],
71+
["scheme", [
72+
["boolean", "#t"]
73+
]]
74+
]],
75+
76+
["embedded-scheme", [
77+
["punctuation", "#"],
78+
["scheme", [
79+
["string", "\"s t r i n g\""]
80+
]]
81+
]]
82+
]
83+
84+
----------------------------------------------------
85+
86+
Checks for Scheme code embedded in LilyPond.

0 commit comments

Comments
 (0)