diff options
| author | Jean-Abou-Samra <37271310+Jean-Abou-Samra@users.noreply.github.com> | 2021-12-28 18:08:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-28 18:08:01 +0100 |
| commit | 7dea301f7f3baa2c5a585a90ab8d8c30332ef562 (patch) | |
| tree | 10a590e58b0497d2d085c94c1aca62fc464791bf /pygments | |
| parent | 7ec67ea2af7f32d1d864f804bd5c17e8f89fbe21 (diff) | |
| download | pygments-git-7dea301f7f3baa2c5a585a90ab8d8c30332ef562.tar.gz | |
Some LilyPond updates (#2001)
- Add pitch language names to builtins. They are not highlighted
specially in the default style, but can be in a custom style.
- Refactor matching of builtins in order to avoid confusion between
dim chord modifier and \dim dynamic command.
- Support grob subproperties.
- Add segno repeat type.
- While at it, update builtins for latest version.
Diffstat (limited to 'pygments')
| -rw-r--r-- | pygments/lexers/_lilypond_builtins.py | 98 | ||||
| -rw-r--r-- | pygments/lexers/lilypond.py | 86 |
2 files changed, 127 insertions, 57 deletions
diff --git a/pygments/lexers/_lilypond_builtins.py b/pygments/lexers/_lilypond_builtins.py index 37ba2b7c..c096273a 100644 --- a/pygments/lexers/_lilypond_builtins.py +++ b/pygments/lexers/_lilypond_builtins.py @@ -138,6 +138,7 @@ scales = [ repeat_types = [ "percent", + "segno", "unfold", "volta", ] @@ -157,6 +158,25 @@ chord_modifiers = [ "maj", ] +pitch_language_names = [ + "arabic", + "catalan", + "català", + "deutsch", + "english", + "espanol", + "español", + "français", + "italiano", + "nederlands", + "norsk", + "portugues", + "português", + "suomi", + "svenska", + "vlaams", +] + pitches = [ "R", "a", @@ -869,6 +889,7 @@ music_functions = [ "change", "chordRepeats", "clef", + "codaMark", "compoundMeter", "compressMMRests", "crossStaff", @@ -963,6 +984,8 @@ music_functions = [ "revertTimeSignatureSettings", "rightHandFinger", "scaleDurations", + "sectionLabel", + "segnoMark", "set", "settingsFrom", "shape", @@ -971,7 +994,6 @@ music_functions = [ "skip", "slashedGrace", "slurDashPattern", - "spacingTweaks", "storePredefinedDiagram", "stringTuning", "styledNoteHeads", @@ -1327,6 +1349,7 @@ markup_commands = [ "center-column", "char", "circle", + "coda", "column", "column-lines", "combine", @@ -1437,6 +1460,7 @@ markup_commands = [ "scale", "score", "score-lines", + "segno", "semiflat", "semisharp", "sesquiflat", @@ -1472,6 +1496,7 @@ markup_commands = [ "undertie", "unless", "upright", + "varcoda", "vcenter", "verbatim-file", "vspace", @@ -1523,6 +1548,7 @@ grobs = [ "ClefModifier", "ClusterSpanner", "ClusterSpannerBeacon", + "CodaMark", "CombineTextScript", "ControlPoint", "ControlPolygon", @@ -1599,6 +1625,8 @@ grobs = [ "Script", "ScriptColumn", "ScriptRow", + "SectionLabel", + "SegnoMark", "Slur", "SostenutoPedal", "SostenutoPedalLineSpanner", @@ -1699,6 +1727,8 @@ translators = [ "Beam_collision_engraver", "Beam_engraver", "Beam_performer", + "Beat_engraver", + "Beat_performer", "Bend_engraver", "Bend_spanner_engraver", "Break_align_engraver", @@ -1759,6 +1789,7 @@ translators = [ "Lyric_engraver", "Lyric_performer", "Mark_engraver", + "Mark_tracking_translator", "Measure_counter_engraver", "Measure_grouping_engraver", "Measure_spanner_engraver", @@ -1840,6 +1871,7 @@ scheme_functions = [ "*location*", "*parser*", "Alteration_glyph_engraver", + "Beat_performer", "Bend_spanner_engraver", "Centered_bar_number_align_engraver", "Duration_line_engraver", @@ -2047,6 +2079,7 @@ scheme_functions = [ "clipped-systems-stencils", "close-enough?", "close-port-rename", + "coda-markup", "collect-book-music-for-book", "collect-bookpart-for-book", "collect-music-aux", @@ -2246,7 +2279,10 @@ scheme_functions = [ "forced-configuration", "format", "format-bass-figure", + "format-coda-mark", "format-compound-time", + "format-dal-segno-text", + "format-dal-segno-text-brief", "format-mark-alphabet", "format-mark-barnumbers", "format-mark-box-alphabet", @@ -2261,10 +2297,14 @@ scheme_functions = [ "format-mark-letters", "format-mark-numbers", "format-metronome-markup", + "format-segno-mark", + "format-segno-mark-considering-bar-lines", + "format-sign-with-number", "format-time-element", "format-time-fraction", "format-time-list", "format-time-numerator", + "format-varcoda-mark", "fraction->moment", "fraction-markup", "fraction?", @@ -2292,6 +2332,7 @@ scheme_functions = [ "generate-oboe-family-entry", "generate-preview-stencil", "generate-saxophone-family-entry", + "generate-system-stencils", "generate-tin-whistle-family-entry", "get-bound-note-heads", "get-chord-shape", @@ -2304,7 +2345,6 @@ scheme_functions = [ "get-numeric-from-key", "get-outfile-name", "get-postscript-bbox", - "get-property-where-defined", "get-quarter-diffs", "get-setting", "get-slope-offset", @@ -2322,7 +2362,6 @@ scheme_functions = [ "glyph-flag", "grace-spacing::calc-shortest-duration", "gray-colorize", - "grob-elts::X-extent", "grob-interpret-markup", "grob-list?", "grob-transformer", @@ -2410,7 +2449,6 @@ scheme_functions = [ "key-signature-interface::alteration-positions", "key?", "keyword->make-markup", - "laissez-vibrer::print", "large-markup", "larger-markup", "layout-blot-diameter", @@ -2533,6 +2571,8 @@ scheme_functions = [ "ly:breathing-sign::finalis", "ly:breathing-sign::offset-callback", "ly:broadcast", + "ly:cairo-output-stencil", + "ly:cairo-output-stencils", "ly:calculated-sequential-music::length", "ly:calculated-sequential-music::start", "ly:camel-case->lisp-identifier", @@ -2563,6 +2603,7 @@ scheme_functions = [ "ly:context-mod-apply!", "ly:context-mod?", "ly:context-name", + "ly:context-output-def", "ly:context-parent", "ly:context-property", "ly:context-property-where-defined", @@ -2721,6 +2762,9 @@ scheme_functions = [ "ly:horizontal-bracket-text::calc-direction", "ly:horizontal-bracket-text::print", "ly:horizontal-bracket::print", + "ly:horizontal-line-spanner::calc-left-bound-info", + "ly:horizontal-line-spanner::calc-left-bound-info-and-text", + "ly:horizontal-line-spanner::calc-right-bound-info", "ly:in-event-class?", "ly:inch", "ly:input-both-locations", @@ -2852,6 +2896,7 @@ scheme_functions = [ "ly:note-collision-interface::calc-positioning-done", "ly:note-column-accidentals", "ly:note-column-dot-column", + "ly:note-column::calc-main-extent", "ly:note-head::calc-stem-attachment", "ly:note-head::calc-tab-stem-attachment", "ly:note-head::include-ledger-line-height", @@ -2872,7 +2917,6 @@ scheme_functions = [ "ly:otf-glyph-count", "ly:otf-glyph-list", "ly:ottava-bracket::print", - "ly:output-cairo", "ly:output-def-clone", "ly:output-def-lookup", "ly:output-def-parent", @@ -2881,7 +2925,6 @@ scheme_functions = [ "ly:output-def?", "ly:output-description", "ly:output-find-context-def", - "ly:output-formats", "ly:outputter-close", "ly:outputter-dump-stencil", "ly:outputter-dump-string", @@ -3046,7 +3089,6 @@ scheme_functions = [ "ly:slur::print", "ly:slur::pure-height", "ly:slur::pure-outside-slur-callback", - "ly:slur::vertical-skylines", "ly:smob-protects", "ly:solve-spring-rod-problem", "ly:source-file?", @@ -3220,6 +3262,7 @@ scheme_functions = [ "make-circle-markup", "make-circle-stencil", "make-clef-set", + "make-coda-markup", "make-colon-bar-line", "make-color-handler", "make-column-lines-markup-list", @@ -3386,6 +3429,7 @@ scheme_functions = [ "make-score-lines-markup-list", "make-score-markup", "make-segno-bar-line", + "make-segno-markup", "make-semiflat-markup", "make-semisharp-markup", "make-semitone->pitch", @@ -3446,6 +3490,7 @@ scheme_functions = [ "make-unfolded-set", "make-unless-markup", "make-upright-markup", + "make-varcoda-markup", "make-vcenter-markup", "make-verbatim-file-markup", "make-voice-props-override", @@ -3513,7 +3558,6 @@ scheme_functions = [ "mmrest-of-length", "modern-straight-flag", "modified-font-metric-font-scaling", - "module-export-all!", "modulo-bar-number-visible", "moment", "moment->fraction", @@ -3553,7 +3597,6 @@ scheme_functions = [ "not-first-broken-spanner?", "not-last-broken-spanner?", "note-by-number-markup", - "note-column::main-extent", "note-events", "note-head::brew-ez-stencil", "note-head::calc-duration-log", @@ -3787,6 +3830,7 @@ scheme_functions = [ "script-or-side-position-cross-staff", "search-executable", "seconds->moment", + "segno-markup", "select-head-glyph", "select-option", "self-alignment-interface::self-aligned-on-breakable", @@ -3832,7 +3876,6 @@ scheme_functions = [ "slashed-digit-internal", "slashed-digit-markup", "slashify", - "slur::draw-tab-slur", "small-markup", "smallCaps-markup", "smaller-markup", @@ -3966,6 +4009,7 @@ scheme_functions = [ "upper-key-stencil", "upright-markup", "value-for-spanner-piece", + "varcoda-markup", "variable-column-circle-stencil", "vcenter-markup", "vector-extend", @@ -3998,6 +4042,7 @@ scheme_functions = [ "wordwrap-stencils", "wordwrap-string-internal-markup-list", "wordwrap-string-markup", + "write-lilypond-book-aux-files", "write-me", "write-performances-midis", "write-system-signature", @@ -4026,12 +4071,14 @@ context_properties = [ "barAlways", "barCheckLastFail", "barCheckSynchronize", + "barExtraVelocity", "barNumberFormatter", "barNumberVisibility", "baseMoment", "beamExceptions", "beamHalfMeasure", "beamMelismaBusy", + "beatExtraVelocity", "beatStructure", "busyGrobs", "centerBarNumbers", @@ -4048,6 +4095,8 @@ context_properties = [ "clefTransposition", "clefTranspositionFormatter", "clefTranspositionStyle", + "codaMarkCount", + "codaMarkFormatter", "completionBusy", "completionFactor", "completionUnit", @@ -4064,20 +4113,22 @@ context_properties = [ "cueClefTranspositionStyle", "currentBarNumber", "currentCommandColumn", + "currentMarkEvent", "currentMusicalColumn", + "dalSegnoTextFormatter", "decrescendoSpanner", "decrescendoText", "defaultBarType", "defaultStrings", - "doubleRepeatSegnoType", - "doubleRepeatType", + "doubleRepeatBarType", + "doubleRepeatSegnoBarType", "doubleSlurs", "drumPitchTable", "drumStyleTable", "dynamicAbsoluteVolumeFunction", "endAtSkip", - "endRepeatSegnoType", - "endRepeatType", + "endRepeatBarType", + "endRepeatSegnoBarType", "explicitClefVisibility", "explicitCueClefVisibility", "explicitKeySignatureVisibility", @@ -4089,8 +4140,8 @@ context_properties = [ "figuredBassPlusDirection", "finalizations", "fineBarType", - "fineSegnoType", - "fineStartRepeatSegnoType", + "fineSegnoBarType", + "fineStartRepeatSegnoBarType", "fineText", "fingeringOrientations", "firstClef", @@ -4151,6 +4202,7 @@ context_properties = [ "midiMinimumVolume", "midiPanPosition", "midiReverbLevel", + "midiSkipOffset", "minimumFret", "minimumPageTurnLength", "minimumRepeatLengthForPageTurn", @@ -4192,7 +4244,10 @@ context_properties = [ "scriptDefinitions", "searchForVoice", "sectionBarType", - "segnoType", + "segnoBarType", + "segnoMarkCount", + "segnoMarkFormatter", + "segnoStyle", "shapeNoteStyles", "shortInstrumentName", "shortVocalName", @@ -4207,8 +4262,8 @@ context_properties = [ "stanza", "startAtNoteColumn", "startAtSkip", - "startRepeatSegnoType", - "startRepeatType", + "startRepeatBarType", + "startRepeatSegnoBarType", "stavesFound", "stemLeftBeamCount", "stemRightBeamCount", @@ -4239,7 +4294,7 @@ context_properties = [ "tupletFullLength", "tupletFullLengthNote", "tupletSpannerDuration", - "underlyingRepeatType", + "underlyingRepeatBarType", "useBassFigureExtenders", "vocalName", "voltaSpannerDuration", @@ -4476,6 +4531,7 @@ grob_properties = [ "line-thickness", "linea", "long-text", + "main-extent", "make-dead-when", "max-beam-connect", "max-symbol-separation", @@ -4500,7 +4556,6 @@ grob_properties = [ "neutral-direction", "neutral-position", "next", - "no-alignment", "no-ledgers", "no-stem-extend", "non-break-align-symbols", @@ -4595,7 +4650,6 @@ grob_properties = [ "side-axis", "side-relative-direction", "side-support-elements", - "simple-Y", "size", "skip-quanting", "skyline-horizontal-padding", diff --git a/pygments/lexers/lilypond.py b/pygments/lexers/lilypond.py index ca38f311..9705cbad 100644 --- a/pygments/lexers/lilypond.py +++ b/pygments/lexers/lilypond.py @@ -10,13 +10,14 @@ import re -from pygments.lexer import inherit, words +from pygments.lexer import default, inherit, words from pygments.lexers.lisp import SchemeLexer from pygments.lexers._lilypond_builtins import ( - keywords, clefs, scales, repeat_types, units, chord_modifiers, pitches, - music_functions, dynamics, articulations, music_commands, markup_commands, - grobs, translators, contexts, context_properties, grob_properties, - scheme_functions, paper_variables, header_variables + keywords, pitch_language_names, clefs, scales, repeat_types, units, + chord_modifiers, pitches, music_functions, dynamics, articulations, + music_commands, markup_commands, grobs, translators, contexts, + context_properties, grob_properties, scheme_functions, paper_variables, + header_variables ) from pygments.token import Token @@ -24,18 +25,15 @@ __all__ = ["LilyPondLexer"] NAME_END_RE = r"(?=\d|[^\w\-]|[\-_][\W\d])" -def builtin_words_with_prefix(names, prefix): - return words(names, prefix, suffix=NAME_END_RE) - -def builtin_backslashed_words(names): - return builtin_words_with_prefix(names, prefix=r"[\-_^]?\\") - -def builtin_words(names): - # Backslashes are always allowed. This is because you can often - # find a context where the form with the backslash will do something - # useful, for example: - # \layout { \context { \Score ... } } - return builtin_words_with_prefix(names, prefix=r"[\-_^]?\\?") +def builtin_words(names, backslash, suffix=NAME_END_RE): + prefix = r"[\-_^]?" + if backslash == "mandatory": + prefix += r"\\" + elif backslash == "optional": + prefix += r"\\?" + else: + assert backslash == "disallowed" + return words(names, prefix, suffix) class LilyPondLexer(SchemeLexer): """ @@ -135,24 +133,32 @@ class LilyPondLexer(SchemeLexer): (r"[\-_^]?\\?\d+", Token.Name.Builtin.Articulation), # Builtins. - (builtin_backslashed_words(keywords), Token.Keyword), - (builtin_words(clefs), Token.Name.Builtin.Clef), - (builtin_backslashed_words(scales), Token.Name.Builtin.Scale), - (builtin_words(repeat_types), Token.Name.Builtin.RepeatType), - (builtin_backslashed_words(units), Token.Number), - (builtin_words(chord_modifiers), Token.ChordModifier), - (builtin_backslashed_words(music_functions), Token.Name.Builtin.MusicFunction), - (builtin_backslashed_words(dynamics), Token.Name.Builtin.Dynamic), - (builtin_backslashed_words(articulations), Token.Name.Builtin.Articulation), - (builtin_backslashed_words(music_commands), Token.Name.Builtin.MusicCommand), - (builtin_backslashed_words(markup_commands), Token.Name.Builtin.MarkupCommand), - (builtin_words(grobs), Token.Name.Builtin.Grob), - (builtin_words(translators), Token.Name.Builtin.Translator), - (builtin_words(contexts), Token.Name.Builtin.Context), - (builtin_words(context_properties), Token.Name.Builtin.ContextProperty), - (builtin_words(grob_properties), Token.Name.Builtin.GrobProperty), - (builtin_words(paper_variables), Token.Name.Builtin.PaperVariable), - (builtin_words(header_variables), Token.Name.Builtin.HeaderVariable), + (builtin_words(keywords, "mandatory"), Token.Keyword), + (builtin_words(pitch_language_names, "disallowed"), Token.Name.PitchLanguage), + (builtin_words(clefs, "disallowed"), Token.Name.Builtin.Clef), + (builtin_words(scales, "mandatory"), Token.Name.Builtin.Scale), + (builtin_words(repeat_types, "disallowed"), Token.Name.Builtin.RepeatType), + (builtin_words(units, "mandatory"), Token.Number), + (builtin_words(chord_modifiers, "disallowed"), Token.ChordModifier), + (builtin_words(music_functions, "mandatory"), Token.Name.Builtin.MusicFunction), + (builtin_words(dynamics, "mandatory"), Token.Name.Builtin.Dynamic), + # Those like slurs that don't take a backslash are covered above. + (builtin_words(articulations, "mandatory"), Token.Name.Builtin.Articulation), + (builtin_words(music_commands, "mandatory"), Token.Name.Builtin.MusicCommand), + (builtin_words(markup_commands, "mandatory"), Token.Name.Builtin.MarkupCommand), + (builtin_words(grobs, "disallowed"), Token.Name.Builtin.Grob), + (builtin_words(translators, "disallowed"), Token.Name.Builtin.Translator), + # Optional backslash because of \layout { \context { \Score ... } }. + (builtin_words(contexts, "optional"), Token.Name.Builtin.Context), + (builtin_words(context_properties, "disallowed"), Token.Name.Builtin.ContextProperty), + (builtin_words(grob_properties, "disallowed"), + Token.Name.Builtin.GrobProperty, + "maybe-subproperties"), + # Optional backslashes here because output definitions are wrappers + # around modules. Concretely, you can do, e.g., + # \paper { oddHeaderMarkup = \evenHeaderMarkup } + (builtin_words(paper_variables, "optional"), Token.Name.Builtin.PaperVariable), + (builtin_words(header_variables, "optional"), Token.Name.Builtin.HeaderVariable), # Other backslashed-escaped names (like dereferencing a # music variable), possibly with a direction specifier. @@ -177,4 +183,14 @@ class LilyPondLexer(SchemeLexer): (r"#\{", Token.Punctuation, ("#pop", "root")), inherit, ], + # Grob subproperties are undeclared and it would be tedious + # to maintain them by hand. Instead, this state allows recognizing + # everything that looks like a-known-property.foo.bar-baz as + # one single property name. + "maybe-subproperties": [ + (r"\.", Token.Punctuation), + (r"\s+", Token.Whitespace), + (r"([^\W\d])+" + NAME_END_RE, Token.Name.Builtin.GrobProperty), + default("#pop"), + ] } |
