-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
c93c066
commit 5d992fc
Showing
13 changed files
with
247 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.