Skip to content

Commit

Permalink
Added basic support for LilyPond (#1967)
Browse files Browse the repository at this point in the history
This adds very basic support for LilyPond. 
More advanced features weren't implemented because the author (me) has no idea about music.
  • Loading branch information
RunDevelopment committed Jul 20, 2019
1 parent c93c066 commit 5d992fc
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@
"require": "css",
"owner": "Golmote"
},
"lilypond": {
"title": "LilyPond",
"require": "scheme",
"alias": "ly",
"owner": "RunDevelopment"
},
"liquid": {
"title": "Liquid",
"owner": "cinhtau"
Expand Down
69 changes: 69 additions & 0 deletions components/prism-lilypond.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(function (Prism) {

var schemeExpression = /\((?:[^();"#\\]|\\[\s\S]|;.*|"(?:[^"\\]|\\.)*"|#(?:\{(?:(?!#\})[\s\S])*#\}|[^{])|<expr>)*\)/.source;
// allow for up to pow(2, recursivenessLog2) many levels of recursive brace expressions
// For some reason, this can't be 4
var recursivenessLog2 = 5;
for (var i = 0; i < recursivenessLog2; i++) {
schemeExpression = schemeExpression.replace(/<expr>/g, schemeExpression);
}
schemeExpression = schemeExpression.replace(/<expr>/g, /[^\s\S]/.source);


var lilypond = Prism.languages.lilypond = {
'comment': /%(?:(?!\{).*|\{[\s\S]*?%\})/,
'embedded-scheme': {
pattern: RegExp(/(^|[=\s])#(?:"(?:[^"\\]|\\.)*"|[^\s()"]*(?:[^\s()]|<expr>))/.source.replace(/<expr>/g, schemeExpression), 'm'),
lookbehind: true,
greedy: true,
inside: {
'scheme': {
pattern: /^(#)[\s\S]+$/,
lookbehind: true,
alias: 'language-scheme',
inside: {
'embedded-lilypond': {
pattern: /#\{[\s\S]*?#\}/,
greedy: true,
inside: {
'punctuation': /^#\{|#\}$/,
'lilypond': {
pattern: /[\s\S]+/,
alias: 'language-lilypond',
inside: null // see below
}
}
},
rest: Prism.languages.scheme
}
},
'punctuation': /#/
}
},
'string': {
pattern: /"(?:[^"\\]|\\.)*"/,
greedy: true
},
'class-name': {
pattern: /(\\new\s+)[\w-]+/,
lookbehind: true
},
'keyword': {
pattern: /\\[a-z][-\w]*/i,
inside: {
'punctuation': /^\\/
}
},
'operator': /[=|]|<<|>>/,
'punctuation': {
pattern: /(^|[a-z\d])(?:'+|,+|[_^]?-[_^]?(?:[-+^!>._]|(?=\d))|[_^]\.?|[.!])|[{}()[\]<>^~]|\\[()[\]<>\\!]|--|__/,
lookbehind: true
},
'number': /\b\d+(?:\/\d+)?\b/
};

lilypond['embedded-scheme'].inside['scheme'].inside['embedded-lilypond'].inside['lilypond'].inside = lilypond;

Prism.languages.ly = lilypond;

}(Prism));
1 change: 1 addition & 0 deletions components/prism-lilypond.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"json5": "json",
"kotlin": "clike",
"less": "css",
"lilypond": "scheme",
"markdown": "markup",
"markup-templating": "markup",
"n4js": "javascript",
Expand Down Expand Up @@ -139,6 +140,7 @@
"hs": "haskell",
"tex": "latex",
"context": "latex",
"ly": "lilypond",
"emacs": "lisp",
"elisp": "lisp",
"emacs-lisp": "lisp",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"latex": "LaTeX",
"tex": "TeX",
"context": "ConTeXt",
"lilypond": "LilyPond",
"ly": "LilyPond",
"emacs": "Lisp",
"elisp": "Lisp",
"emacs-lisp": "Lisp",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/languages/lilypond/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% single line

%{
multiple lines
%}

----------------------------------------------------

[
["comment", "% single line"],
["comment", "%{\nmultiple lines\n%}"]
]

----------------------------------------------------

Checks for comments.
86 changes: 86 additions & 0 deletions tests/languages/lilypond/embedded-scheme_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#(define foo)

#(define-music-function (parser location notes) (ly:music?) #{
% Yes! You can embed LilyPond in Scheme.
\override Score.Stem.beamlet-max-length-proportion = #'(0.5 . 0.5)
#})

##t

#"s t r i n g"

----------------------------------------------------

[
["embedded-scheme", [
["punctuation", "#"],
["scheme", [
["punctuation", "("],
["keyword", "define"],
" foo",
["punctuation", ")"]
]]
]],

["embedded-scheme", [
["punctuation", "#"],
["scheme", [
["punctuation", "("],
["function", "define-music-function"],
["punctuation", "("],
["function", "parser"],
" location notes",
["punctuation", ")"],
["punctuation", "("],
["function", "ly:music?"],
["punctuation", ")"],
["embedded-lilypond", [
["punctuation", "#{"],
["lilypond", [
["comment", "% Yes! You can embed LilyPond in Scheme."],
["keyword", [
["punctuation", "\\"],
"override"
]],
" Score",
["punctuation", "."],
"Stem",
["punctuation", "."],
"beamlet-max-length-proportion ",
["operator", "="],
["embedded-scheme", [
["punctuation", "#"],
["scheme", [
["punctuation", "'"],
["punctuation", "("],
["number", "0.5"],
" . ",
["number", "0.5"],
["punctuation", ")"]
]]
]]
]],
["punctuation", "#}"]
]],
["punctuation", ")"]
]]
]],

["embedded-scheme", [
["punctuation", "#"],
["scheme", [
["boolean", "#t"]
]]
]],

["embedded-scheme", [
["punctuation", "#"],
["scheme", [
["string", "\"s t r i n g\""]
]]
]]
]

----------------------------------------------------

Checks for Scheme code embedded in LilyPond.
35 changes: 35 additions & 0 deletions tests/languages/lilypond/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
\new \set
\center-column
5\mm
h\fermata

----------------------------------------------------

[
["keyword", [
["punctuation", "\\"],
"new"
]],
["keyword", [
["punctuation", "\\"],
"set"
]],
["keyword", [
["punctuation", "\\"],
"center-column"
]],
["number", "5"],
["keyword", [
["punctuation", "\\"],
"mm"
]],
"\nh",
["keyword", [
["punctuation", "\\"],
"fermata"
]]
]

----------------------------------------------------

Checks for keywords.
13 changes: 13 additions & 0 deletions tests/languages/lilypond/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
123
6/8

----------------------------------------------------

[
["number", "123"],
["number", "6/8"]
]

----------------------------------------------------

Checks for numbers.
Loading

0 comments on commit 5d992fc

Please sign in to comment.