| 1 |
%% Autogenerate a list of LilyPond keywords |
| 2 |
|
| 3 |
\version "2.25.29" |
| 4 |
|
| 5 |
#(use-modules (ice-9 receive) |
| 6 |
(ice-9 regex)) |
| 7 |
|
| 8 |
#(define port (open-output-file "../pygments/lexers/_lilypond_builtins.py")) |
| 9 |
|
| 10 |
#(define output-preamble |
| 11 |
"\"\"\" |
| 12 |
pygments.lexers._lilypond_builtins |
| 13 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 14 |
|
| 15 |
LilyPond builtins. |
| 16 |
|
| 17 |
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS. |
| 18 |
:license: BSD, see LICENSE for details. |
| 19 |
\"\"\" |
| 20 |
|
| 21 |
# Contents generated by the script `lilypond-builtins-generator.ly` |
| 22 |
# found in the `external/` directory of the source tree. |
| 23 |
|
| 24 |
") |
| 25 |
|
| 26 |
#(format port "~a" output-preamble) |
| 27 |
|
| 28 |
#(define (dump-py-list name vals) |
| 29 |
(let* ((string-vals |
| 30 |
(map symbol->string vals)) |
| 31 |
(fixed-vals |
| 32 |
(filter-map |
| 33 |
(lambda (str) |
| 34 |
; To avoid conflicts with Scheme builtins, |
| 35 |
; a leading backslash is prepended to \<, |
| 36 |
; \= and a few others. The lexer finds it |
| 37 |
; itself, so remove it here. |
| 38 |
(cond |
| 39 |
((equal? str "\\\\") |
| 40 |
#f) |
| 41 |
((string-startswith str "\\") |
| 42 |
(string-drop str 1)) |
| 43 |
(else |
| 44 |
str))) |
| 45 |
string-vals)) |
| 46 |
(sorted-vals ; reproducibility |
| 47 |
; Avoid duplicates (e.g., identical pitches |
| 48 |
; in different languages) |
| 49 |
(uniq-list |
| 50 |
(sort fixed-vals string<?))) |
| 51 |
(formatted-vals |
| 52 |
(map |
| 53 |
(lambda (val) |
| 54 |
(format #f " \"~a\"," val name)) |
| 55 |
sorted-vals)) |
| 56 |
(joint-vals |
| 57 |
(string-join formatted-vals "\n"))) |
| 58 |
(format port |
| 59 |
"~a = [ |
| 60 |
~a |
| 61 |
] |
| 62 |
|
| 63 |
" |
| 64 |
name |
| 65 |
joint-vals))) |
| 66 |
|
| 67 |
|
| 68 |
%% KEYWORDS |
| 69 |
|
| 70 |
#(define keywords |
| 71 |
'( |
| 72 |
; Lexical modes. |
| 73 |
notemode |
| 74 |
lyricmode |
| 75 |
lyricsto |
| 76 |
addlyrics |
| 77 |
chordmode |
| 78 |
chords |
| 79 |
figuremode |
| 80 |
figures |
| 81 |
drummode |
| 82 |
drums |
| 83 |
; Output definitions. |
| 84 |
header |
| 85 |
layout |
| 86 |
midi |
| 87 |
paper |
| 88 |
; Context definitions. |
| 89 |
;; \context is also used in music. We take it as |
| 90 |
;; a keyword in both cases. |
| 91 |
context |
| 92 |
with |
| 93 |
name |
| 94 |
type |
| 95 |
accepts |
| 96 |
denies |
| 97 |
alias |
| 98 |
defaultchild |
| 99 |
consists |
| 100 |
remove |
| 101 |
description |
| 102 |
;; Not strictly a keyword, but can be viewed so. |
| 103 |
inherit-acceptability |
| 104 |
; Blocks. |
| 105 |
book |
| 106 |
bookpart |
| 107 |
score |
| 108 |
; Other. |
| 109 |
new |
| 110 |
etc |
| 111 |
include |
| 112 |
language |
| 113 |
version)) |
| 114 |
|
| 115 |
#(dump-py-list 'keywords keywords) |
| 116 |
|
| 117 |
%% CLEFS |
| 118 |
|
| 119 |
#(define all-clefs |
| 120 |
(map string->symbol (map car (filter pair? supported-clefs)))) |
| 121 |
|
| 122 |
#(dump-py-list 'clefs all-clefs) |
| 123 |
|
| 124 |
%% SCALES |
| 125 |
|
| 126 |
#(define all-scales |
| 127 |
'(major |
| 128 |
minor |
| 129 |
ionian |
| 130 |
locrian |
| 131 |
aeolian |
| 132 |
mixolydian |
| 133 |
lydian |
| 134 |
phrygian |
| 135 |
dorian)) |
| 136 |
|
| 137 |
#(dump-py-list 'scales all-scales) |
| 138 |
|
| 139 |
%% REPEAT TYPES |
| 140 |
|
| 141 |
#(define all-repeat-types |
| 142 |
'(volta percent tremolo unfold segno)) |
| 143 |
|
| 144 |
#(dump-py-list 'repeat_types all-repeat-types) |
| 145 |
|
| 146 |
%% UNITS |
| 147 |
|
| 148 |
#(define all-units |
| 149 |
'(mm cm in pt staff-space)) |
| 150 |
|
| 151 |
#(dump-py-list 'units all-units) |
| 152 |
|
| 153 |
%% CHORD MODIFIERS |
| 154 |
|
| 155 |
#(define all-chord-modifiers |
| 156 |
'(m dim aug maj)) |
| 157 |
|
| 158 |
#(dump-py-list 'chord_modifiers all-chord-modifiers) |
| 159 |
|
| 160 |
%% PITCHES |
| 161 |
|
| 162 |
#(define all-pitch-language-names |
| 163 |
(map car language-pitch-names)) |
| 164 |
|
| 165 |
#(dump-py-list 'pitch_language_names all-pitch-language-names) |
| 166 |
|
| 167 |
#(define all-pitch-names |
| 168 |
(append |
| 169 |
; We highlight rests just like pitches. |
| 170 |
'(r R) |
| 171 |
(map car (append-map cdr language-pitch-names)) |
| 172 |
; Drum note names. |
| 173 |
(map car drumPitchNames))) |
| 174 |
|
| 175 |
#(dump-py-list 'pitches all-pitch-names) |
| 176 |
|
| 177 |
%% MUSIC FUNCTIONS AND SHORTCUTS |
| 178 |
|
| 179 |
% View these as music functions. |
| 180 |
#(define extra-music-functions |
| 181 |
'(set |
| 182 |
unset |
| 183 |
override |
| 184 |
revert |
| 185 |
tweak |
| 186 |
once |
| 187 |
undo |
| 188 |
temporary |
| 189 |
repeat |
| 190 |
alternative |
| 191 |
tempo |
| 192 |
change)) |
| 193 |
|
| 194 |
#(let* ((module (current-module)) |
| 195 |
(module-alist (ly:module->alist module)) |
| 196 |
(all-music-functions |
| 197 |
(filter |
| 198 |
(lambda (entry) |
| 199 |
(ly:music-function? (cdr entry))) |
| 200 |
module-alist)) |
| 201 |
(all-predefined-music-objects |
| 202 |
(filter |
| 203 |
(lambda (entry) |
| 204 |
(ly:music? (cdr entry))) |
| 205 |
module-alist))) |
| 206 |
(receive (articulations non-articulations) |
| 207 |
(partition |
| 208 |
(lambda (entry) |
| 209 |
(ly:event? (cdr entry))) |
| 210 |
all-predefined-music-objects) |
| 211 |
(receive (dynamics non-dynamic-articulations) |
| 212 |
(partition |
| 213 |
(lambda (entry) |
| 214 |
(any |
| 215 |
(lambda (type) |
| 216 |
(music-is-of-type? (cdr entry) |
| 217 |
type)) |
| 218 |
'(dynamic-event crescendo-event decrescendo-event))) |
| 219 |
articulations) |
| 220 |
(dump-py-list 'music_functions |
| 221 |
(append extra-music-functions |
| 222 |
(map car all-music-functions))) |
| 223 |
(dump-py-list 'dynamics (map car dynamics)) |
| 224 |
(dump-py-list 'articulations (map car non-dynamic-articulations)) |
| 225 |
(dump-py-list 'music_commands (map car non-articulations))))) |
| 226 |
|
| 227 |
%% MARKUP COMMANDS |
| 228 |
|
| 229 |
#(let* ((markup-name-regexp |
| 230 |
(make-regexp "(.*)-markup(-list)?")) |
| 231 |
(modules |
| 232 |
(cons (current-module) |
| 233 |
(map resolve-module '((lily) (lily accreg))))) |
| 234 |
(alist |
| 235 |
(apply append |
| 236 |
(map ly:module->alist modules))) |
| 237 |
(markup-commands |
| 238 |
(filter |
| 239 |
(lambda (entry) |
| 240 |
(or (markup-function? (cdr entry)) |
| 241 |
(markup-list-function? (cdr entry)))) |
| 242 |
alist)) |
| 243 |
(markup-command-names |
| 244 |
(map |
| 245 |
(lambda (entry) |
| 246 |
(let* ((string-name (symbol->string (car entry))) |
| 247 |
(match (regexp-exec markup-name-regexp string-name))) |
| 248 |
(string->symbol (match:substring match 1)))) |
| 249 |
markup-commands)) |
| 250 |
(markup-words |
| 251 |
(append '(markup markuplist) |
| 252 |
markup-command-names))) |
| 253 |
(dump-py-list 'markup_commands markup-words)) |
| 254 |
|
| 255 |
%% GROBS |
| 256 |
|
| 257 |
#(let ((grob-names (map car all-grob-descriptions))) |
| 258 |
(dump-py-list 'grobs grob-names)) |
| 259 |
|
| 260 |
%% CONTEXTS |
| 261 |
|
| 262 |
#(let* ((layout-module |
| 263 |
(ly:output-def-scope $defaultlayout)) |
| 264 |
(layout-alist |
| 265 |
(ly:module->alist layout-module)) |
| 266 |
(all-context-defs |
| 267 |
(filter |
| 268 |
(lambda (entry) |
| 269 |
(ly:context-def? (cdr entry))) |
| 270 |
layout-alist)) |
| 271 |
(context-def-names |
| 272 |
(map car all-context-defs)) |
| 273 |
;; Timing is added dynamically |
| 274 |
(context-def-names (cons 'Timing context-def-names))) |
| 275 |
(dump-py-list 'contexts context-def-names)) |
| 276 |
|
| 277 |
%% TRANSLATORS |
| 278 |
|
| 279 |
#(let* ((all-translators |
| 280 |
(ly:get-all-translators)) |
| 281 |
(translator-names |
| 282 |
(map ly:translator-name all-translators))) |
| 283 |
(dump-py-list 'translators translator-names)) |
| 284 |
|
| 285 |
%% SCHEME FUNCTIONS |
| 286 |
|
| 287 |
#(let* ((module (resolve-module '(lily))) |
| 288 |
(module-alist (ly:module->alist module)) |
| 289 |
(all-functions |
| 290 |
(filter |
| 291 |
(lambda (entry) |
| 292 |
(or (procedure? (cdr entry)) |
| 293 |
(macro? (cdr entry)))) |
| 294 |
module-alist)) |
| 295 |
(all-function-names |
| 296 |
(map car all-functions))) |
| 297 |
(dump-py-list 'scheme_functions all-function-names)) |
| 298 |
|
| 299 |
%% PROPERTIES |
| 300 |
|
| 301 |
#(dump-py-list 'context_properties all-translation-properties) |
| 302 |
#(dump-py-list 'grob_properties all-backend-properties) |
| 303 |
|
| 304 |
%% PAPER VARIABLES |
| 305 |
|
| 306 |
#(ly:load "define-paper-variables") |
| 307 |
#(define all-paper-variables |
| 308 |
(append (map (lambda(x) (car x)) |
| 309 |
all-paper-variable-descriptions) |
| 310 |
;; Let's view these four as `\paper` variables. |
| 311 |
'(basic-distance |
| 312 |
minimum-distance |
| 313 |
padding |
| 314 |
stretchability))) |
| 315 |
|
| 316 |
#(dump-py-list 'paper_variables all-paper-variables) |
| 317 |
|
| 318 |
%% HEADER VARIABLES |
| 319 |
|
| 320 |
% Reference: https://lilypond.org/doc/v2.25/Documentation/notation/creating-titles-headers-and-footers#default-layout-of-bookpart-and-score-titles |
| 321 |
#(define all-header-variables |
| 322 |
'(dedication |
| 323 |
title |
| 324 |
subtitle |
| 325 |
subsubtitle |
| 326 |
instrument |
| 327 |
poet |
| 328 |
composer |
| 329 |
meter |
| 330 |
arranger |
| 331 |
tagline |
| 332 |
copyright |
| 333 |
piece |
| 334 |
opus |
| 335 |
;; The following are used in LSR snippets and regression tests. |
| 336 |
lsrtags |
| 337 |
doctitle |
| 338 |
texidoc |
| 339 |
;; Metadata variables. |
| 340 |
pdfauthor |
| 341 |
pdftitle |
| 342 |
pdfsubject |
| 343 |
pdfkeywords |
| 344 |
pdfmodDate |
| 345 |
pdfcreationDate |
| 346 |
pdfsubtitle |
| 347 |
pdfcomposer |
| 348 |
pdfarranger |
| 349 |
pdfpoet |
| 350 |
pdfcopyright)) |
| 351 |
|
| 352 |
#(dump-py-list 'header_variables all-header-variables) |
| 353 |
|
| 354 |
|
| 355 |
#(close-port port) |