lilypond

Parser for LilyPond syntax.

In this module:

Language

Name (Aliases)

Description

Filename(s)

Mime Type(s)

LilyPond

LilyPond

LilyPond music typesetter

*.ly, *.ily, *.lyi

text/x-lilypond

class LilyPond[source]

Bases: parce.language.Language

root

Toplevel LilyPond document.

classmethod blocks()[source]
book

Book or bookpart.

score

A score block.

header

A header block.

paper

A paper block.

layout

A layout block.

midi

A midi block.

layout_context

Contents of \layout or \midi { \context { } } or \with. { }.

classmethod commands(*, list_target=0)[source]

Yield commands that can occur in all input modes.

If a list_target is given, that lexicon is pushed after a Keyword, to be able to parse symbols, strings, numbers or scheme. This makes sense in e.g. lyrics mode.

classmethod music()[source]

Musical items.

musiclist

A {} or <<>> musical construct.

Derive with the end arg (} or >>).

chord

A < chord > construct.

repeat

repeat mode n.

script

A script abbreviation or fingering digit.

classmethod ifpitch(itemlist=None, else_itemlist=None)[source]

Return a rule item that by default yields Name.Pitch for a pitch, else Name.Symbol.

pitch

A note name, find octave/accidental etc after it.

duration

Zero or more dots after a duration.

duration_scaling

*n/m after a duration.

classmethod inputmode(lexicon)[source]

Yield boilerplate rules for an input mode.

classmethod inputmode_list(lexicon)[source]

Yield boilerplate rules for the contents of an input mode.

lyricmode

Yield contents in lyric mode.

lyricsto

Find the argument of a \lyricsto command.

lyriclist

Lyrics between {}.

Derive with the desired closing delimiter (} or >>).

lyricword

Contents of lyric word, highlight tie and space separately.

drummode

drummode and drums.

drumlist

Drum music between {} or <<>>.

chordmode

chordmode and chords.

chordlist

Chordmode music between {} or <<>>.

chord_modifier

Stuff in chord mode after a :

notemode

Notemode switches back to music e.g. in lyrics.

figuremode

figuremode and figures.

figurelist

figuremode music between {} or <<>>.

figure

Stuff between < and > in figure mode.

figurebracket

Stuff between [ and ] in a bass figure.

classmethod common()[source]

Find comment, string, scheme, the = operator and markup.

classmethod base()[source]

Find comment, string and scheme.

list

A list of numbers, symbols, strings or scheme expressions.

Consumes both . and , as separators.

Jump here:

  • plainly: start_list

  • when a “, # or $ is ahead: start_list

  • from a number followed by , (but don’t consume the ,)

  • from a symbol

start_list

Start a list, this context is never created: all contents go to list.

identifier_ref

bla.bla.bla syntax.

classmethod get_symbol_action(text, default=Name.Symbol)[source]

Return a proper dynamic action for the name of a symbol.

classmethod find_markup()[source]

Find \markup, \markuplines and \markuplist.

markup

Markup without environment. Try to guess the n of arguments.

markuplist

Markup in environment from { until }.

markupscore

\score { } or \score-lines { } in markup.

classmethod get_markup_argument_count(command)[source]

Return the number of arguments of a markup command (without \) expects.

The default implementation returns 1 for unknown commands. You could re-implement this method if you have some special commands to add.

classmethod get_markup_action()[source]

Get the action for a command in markup { }.

classmethod find_scheme(*extra_target)[source]

Find scheme.

classmethod get_scheme_target()[source]

Return the one_arg lexicon for one Scheme expression.

schemelily

LilyPond from scheme.SchemeLily #{ #}.

classmethod find_string(*extra_target)[source]

Find a string.

string

A double-quoted string.

classmethod find_comment(*extra_target)[source]

Find single-line or block comments.

multiline_comment

A multiple line (block) comment.

singleline_comment

A comment till the end of the line.

Example:

Root lexicon LilyPond.root and text:

Text rendered using default theme

\relative c'' {
  \time 7/4
  d2 c4 b2 a | b c4 b( a) g2
}
\addlyrics {
  Join us now and share the soft -- ware
}

Result tree:

<Context LilyPond.root at 0-114 (6 children)>
 ├╴<Token '\\relative' at 0:9 (Name.Builtin)>
 ├╴<Token 'c' at 10:11 (Text.Music.Pitch)>
 ├╴<Context LilyPond.pitch at 11-13 (1 child)>
 │  ╰╴<Token "''" at 11:13 (Text.Music.Pitch.Octave)>
 ├╴<Context LilyPond.musiclist* at 14-58 (21 children)>
 │  ├╴<Token '{' at 14:15 (Delimiter.Bracket.Start)>
 │  ├╴<Token '\\time' at 18:23 (Name.Builtin)>
 │  ├╴<Token '7/4' at 24:27 (Literal.Number.Fraction)>
 │  ├╴<Token 'd' at 30:31 (Text.Music.Pitch)>
 │  ├╴<Token '2' at 31:32 (Literal.Number.Duration)>
 │  ├╴<Token 'c' at 33:34 (Text.Music.Pitch)>
 │  ├╴<Token '4' at 34:35 (Literal.Number.Duration)>
 │  ├╴<Token 'b' at 36:37 (Text.Music.Pitch)>
 │  ├╴<Token '2' at 37:38 (Literal.Number.Duration)>
 │  ├╴<Token 'a' at 39:40 (Text.Music.Pitch)>
 │  ├╴<Token '|' at 41:42 (Delimiter.Separator.PipeSymbol)>
 │  ├╴<Token 'b' at 43:44 (Text.Music.Pitch)>
 │  ├╴<Token 'c' at 45:46 (Text.Music.Pitch)>
 │  ├╴<Token '4' at 46:47 (Literal.Number.Duration)>
 │  ├╴<Token 'b' at 48:49 (Text.Music.Pitch)>
 │  ├╴<Token '(' at 49:50 (Name.Symbol.Spanner.Slur)>
 │  ├╴<Token 'a' at 51:52 (Text.Music.Pitch)>
 │  ├╴<Token ')' at 52:53 (Name.Symbol.Spanner.Slur)>
 │  ├╴<Token 'g' at 54:55 (Text.Music.Pitch)>
 │  ├╴<Token '2' at 55:56 (Literal.Number.Duration)>
 │  ╰╴<Token '}' at 57:58 (Delimiter.Bracket.End)>
 ├╴<Token '\\addlyrics' at 59:69 (Keyword.Lyric)>
 ╰╴<Context LilyPond.lyriclist* at 70-114 (11 children)>
    ├╴<Token '{' at 70:71 (Delimiter.Bracket.Start)>
    ├╴<Token 'Join' at 74:78 (Text.Lyric.LyricText)>
    ├╴<Token 'us' at 79:81 (Text.Lyric.LyricText)>
    ├╴<Token 'now' at 82:85 (Text.Lyric.LyricText)>
    ├╴<Token 'and' at 86:89 (Text.Lyric.LyricText)>
    ├╴<Token 'share' at 90:95 (Text.Lyric.LyricText)>
    ├╴<Token 'the' at 96:99 (Text.Lyric.LyricText)>
    ├╴<Token 'soft' at 100:104 (Text.Lyric.LyricText)>
    ├╴<Token '--' at 105:107 (Delimiter.Lyric.LyricHyphen)>
    ├╴<Token 'ware' at 108:112 (Text.Lyric.LyricText)>
    ╰╴<Token '}' at 113:114 (Delimiter.Bracket.End)>