# The `ly` package

## Module contents

A package of modules dealing with LilyPond and the LilyPond format.

The ly module supports both Python2 and Python3. This is a short description of some modules:

> - ly.slexer: generic tools to build parsers using regular expressions

> - ly.node: a generic list-like node object to build tree structures with

> - ly.document: a tokenized text document (LilyPond file)

> - ly.docinfo: harvests and caches various information from a LilyPond document

> - ly.lex: a parser for LilyPond, Scheme, and other formats, using slexer

> - ly.music: a tree structure of the contents of a document

> - ly.pitch: functions for translating, transposing etc

> - ly.rhythm: functions dealing with rhythm

> - ly.indent: indent LilyPond text

> - ly.reformat: format LilyPond text

> - ly.dom: (deprecated) tree structure to build LilyPond text from

> - ly.words: words for highlighting and autocompletion

> - ly.data: layout objects, properties, interfaces, font glyphs etc extracted from LilyPond

> - ly.cli: the implementation of the command-line ‘ly’ script

A LilyPond document (source file) is held by a ly.document.Document. The Document class automatically parses and tokenizes the text, also when its contents are changed.

A music tree can be built from a document using the ly.music module. In the near future, music trees can be built from scratch and also generate LilyPond output from scratch. At that moment, ly.dom is deprecated.

The functions in ly.pitch, such as transpose and translate currently access the tokens in the document, but in the future they will work on the music tree.

## Subpackages

- ly.lex package
  - Module contents
    - `BlockComment`
      - `BlockComment.end`
      - `BlockComment.pos`
    - `BlockCommentEnd`
      - `BlockCommentEnd.end`
      - `BlockCommentEnd.pos`
    - `BlockCommentStart`
      - `BlockCommentStart.end`
      - `BlockCommentStart.pos`
    - `Character`
      - `Character.end`
      - `Character.pos`
    - `Comment`
      - `Comment.end`
      - `Comment.pos`
    - `Dedent`
    - `Error`
      - `Error.end`
      - `Error.pos`
    - `FallthroughParser`
    - `Fridge`
    - `Indent`
    - `LineComment`
      - `LineComment.end`
      - `LineComment.pos`
    - `MatchEnd`
      - `MatchEnd.matchname`
    - `MatchStart`
      - `MatchStart.matchname`
    - `Newline`
      - `Newline.end`
      - `Newline.pos`
      - `Newline.rx`
    - `Numeric`
      - `Numeric.end`
      - `Numeric.pos`
    - `Parser`
      - `Parser.argcount`
      - `Parser.default`
      - `Parser.freeze()`
      - `Parser.mode`
      - `Parser.re_flags`
    - `Space`
      - `Space.end`
      - `Space.pos`
      - `Space.rx`
    - `State`
      - `State.endArgument()`
      - `State.mode()`
    - `String`
      - `String.end`
      - `String.pos`
    - `StringEnd`
      - `StringEnd.end`
      - `StringEnd.pos`
    - `StringStart`
      - `StringStart.end`
      - `StringStart.pos`
    - `Token`
      - `Token.end`
      - `Token.pos`
    - `Unparsed`
      - `Unparsed.end`
      - `Unparsed.pos`
    - `guessMode()`
    - `guessState()`
    - `state()`
  - Submodules
  - ly.lex.docbook module
    - `ParseDocBook`
      - `ParseDocBook.items`
      - `ParseDocBook.mode`
      - `ParseDocBook.pattern`
  - ly.lex.html module
    - `AttrName`
      - `AttrName.end`
      - `AttrName.pos`
      - `AttrName.rx`
    - `Comment`
      - `Comment.end`
      - `Comment.pos`
    - `CommentEnd`
      - `CommentEnd.end`
      - `CommentEnd.pos`
      - `CommentEnd.rx`
    - `CommentStart`
      - `CommentStart.end`
      - `CommentStart.pos`
      - `CommentStart.rx`
      - `CommentStart.update_state()`
    - `EntityRef`
      - `EntityRef.end`
      - `EntityRef.pos`
      - `EntityRef.rx`
    - `EqualSign`
      - `EqualSign.end`
      - `EqualSign.pos`
      - `EqualSign.rx`
      - `EqualSign.update_state()`
    - `LilyPondCloseTag`
      - `LilyPondCloseTag.end`
      - `LilyPondCloseTag.pos`
      - `LilyPondCloseTag.rx`
    - `LilyPondFileTag`
      - `LilyPondFileTag.end`
      - `LilyPondFileTag.pos`
      - `LilyPondFileTag.rx`
      - `LilyPondFileTag.update_state()`
    - `LilyPondFileTagEnd`
      - `LilyPondFileTagEnd.end`
      - `LilyPondFileTagEnd.pos`
      - `LilyPondFileTagEnd.rx`
    - `LilyPondInlineTag`
      - `LilyPondInlineTag.end`
      - `LilyPondInlineTag.pos`
      - `LilyPondInlineTag.rx`
      - `LilyPondInlineTag.update_state()`
    - `LilyPondInlineTagEnd`
      - `LilyPondInlineTagEnd.end`
      - `LilyPondInlineTagEnd.pos`
      - `LilyPondInlineTagEnd.rx`
    - `LilyPondTag`
      - `LilyPondTag.end`
      - `LilyPondTag.pos`
    - `LilyPondTagEnd`
      - `LilyPondTagEnd.end`
      - `LilyPondTagEnd.pos`
      - `LilyPondTagEnd.rx`
      - `LilyPondTagEnd.update_state()`
    - `LilyPondVersionTag`
      - `LilyPondVersionTag.end`
      - `LilyPondVersionTag.pos`
      - `LilyPondVersionTag.rx`
    - `ParseAttr`
      - `ParseAttr.items`
      - `ParseAttr.pattern`
    - `ParseComment`
      - `ParseComment.default`
      - `ParseComment.items`
      - `ParseComment.pattern`
    - `ParseHTML`
      - `ParseHTML.items`
      - `ParseHTML.mode`
      - `ParseHTML.pattern`
    - `ParseLilyPond`
      - `ParseLilyPond.items`
      - `ParseLilyPond.pattern`
    - `ParseLilyPondAttr`
      - `ParseLilyPondAttr.items`
      - `ParseLilyPondAttr.pattern`
    - `ParseLilyPondFileOptions`
      - `ParseLilyPondFileOptions.items`
      - `ParseLilyPondFileOptions.pattern`
    - `ParseLilyPondInline`
      - `ParseLilyPondInline.items`
      - `ParseLilyPondInline.pattern`
    - `ParseStringDQ`
      - `ParseStringDQ.default`
      - `ParseStringDQ.items`
      - `ParseStringDQ.pattern`
    - `ParseStringSQ`
      - `ParseStringSQ.default`
      - `ParseStringSQ.items`
      - `ParseStringSQ.pattern`
    - `ParseValue`
      - `ParseValue.fallthrough()`
      - `ParseValue.items`
      - `ParseValue.pattern`
    - `SemiColon`
      - `SemiColon.end`
      - `SemiColon.pos`
      - `SemiColon.rx`
      - `SemiColon.update_state()`
    - `String`
      - `String.end`
      - `String.pos`
    - `StringDQEnd`
      - `StringDQEnd.end`
      - `StringDQEnd.pos`
      - `StringDQEnd.rx`
    - `StringDQStart`
      - `StringDQStart.end`
      - `StringDQStart.pos`
      - `StringDQStart.rx`
      - `StringDQStart.update_state()`
    - `StringSQEnd`
      - `StringSQEnd.end`
      - `StringSQEnd.pos`
      - `StringSQEnd.rx`
    - `StringSQStart`
      - `StringSQStart.end`
      - `StringSQStart.pos`
      - `StringSQStart.rx`
      - `StringSQStart.update_state()`
    - `Tag`
      - `Tag.end`
      - `Tag.pos`
    - `TagEnd`
      - `TagEnd.end`
      - `TagEnd.pos`
      - `TagEnd.rx`
    - `TagStart`
      - `TagStart.end`
      - `TagStart.pos`
      - `TagStart.rx`
      - `TagStart.update_state()`
    - `Value`
      - `Value.end`
      - `Value.pos`
      - `Value.rx`
  - ly.lex.latex module
    - `ParseLaTeX`
      - `ParseLaTeX.items`
      - `ParseLaTeX.mode`
      - `ParseLaTeX.pattern`
  - ly.lex.lilypond module
    - `Accidental`
      - `Accidental.end`
      - `Accidental.pos`
    - `AccidentalCautionary`
      - `AccidentalCautionary.end`
      - `AccidentalCautionary.pos`
      - `AccidentalCautionary.rx`
    - `AccidentalReminder`
      - `AccidentalReminder.end`
      - `AccidentalReminder.pos`
      - `AccidentalReminder.rx`
    - `AccidentalStyle`
      - `AccidentalStyle.end`
      - `AccidentalStyle.pos`
      - `AccidentalStyle.rx`
      - `AccidentalStyle.update_state()`
    - `AccidentalStyleSpecifier`
      - `AccidentalStyleSpecifier.end`
      - `AccidentalStyleSpecifier.pos`
      - `AccidentalStyleSpecifier.rx`
    - `AlterBroken`
      - `AlterBroken.end`
      - `AlterBroken.pos`
      - `AlterBroken.rx`
      - `AlterBroken.update_state()`
    - `Articulation`
      - `Articulation.end`
      - `Articulation.pos`
    - `ArticulationCommand`
      - `ArticulationCommand.end`
      - `ArticulationCommand.pos`
      - `ArticulationCommand.test_match()`
    - `BackSlashedContextName`
      - `BackSlashedContextName.end`
      - `BackSlashedContextName.pos`
      - `BackSlashedContextName.rx`
    - `Beam`
      - `Beam.end`
      - `Beam.pos`
    - `BeamEnd`
      - `BeamEnd.end`
      - `BeamEnd.matchname`
      - `BeamEnd.pos`
      - `BeamEnd.rx`
    - `BeamStart`
      - `BeamStart.end`
      - `BeamStart.matchname`
      - `BeamStart.pos`
      - `BeamStart.rx`
    - `BlockComment`
      - `BlockComment.end`
      - `BlockComment.pos`
    - `BlockCommentEnd`
      - `BlockCommentEnd.end`
      - `BlockCommentEnd.pos`
      - `BlockCommentEnd.rx`
    - `BlockCommentStart`
      - `BlockCommentStart.end`
      - `BlockCommentStart.pos`
      - `BlockCommentStart.rx`
      - `BlockCommentStart.update_state()`
    - `Book`
      - `Book.end`
      - `Book.pos`
      - `Book.rx`
      - `Book.update_state()`
    - `BookPart`
      - `BookPart.end`
      - `BookPart.pos`
      - `BookPart.rx`
      - `BookPart.update_state()`
    - `Change`
      - `Change.end`
      - `Change.pos`
      - `Change.rx`
    - `Chord`
      - `Chord.end`
      - `Chord.pos`
    - `ChordEnd`
      - `ChordEnd.end`
      - `ChordEnd.pos`
      - `ChordEnd.rx`
    - `ChordItem`
      - `ChordItem.end`
      - `ChordItem.pos`
    - `ChordMode`
      - `ChordMode.end`
      - `ChordMode.pos`
      - `ChordMode.rx`
      - `ChordMode.update_state()`
    - `ChordModifier`
      - `ChordModifier.end`
      - `ChordModifier.pos`
      - `ChordModifier.rx`
    - `ChordSeparator`
      - `ChordSeparator.end`
      - `ChordSeparator.pos`
      - `ChordSeparator.rx`
    - `ChordStart`
      - `ChordStart.end`
      - `ChordStart.pos`
      - `ChordStart.rx`
      - `ChordStart.update_state()`
    - `ChordStepNumber`
      - `ChordStepNumber.end`
      - `ChordStepNumber.pos`
      - `ChordStepNumber.rx`
    - `Clef`
      - `Clef.end`
      - `Clef.pos`
      - `Clef.rx`
      - `Clef.update_state()`
    - `ClefSpecifier`
      - `ClefSpecifier.end`
      - `ClefSpecifier.pos`
      - `ClefSpecifier.rx`
      - `ClefSpecifier.update_state()`
    - `CloseBracket`
      - `CloseBracket.end`
      - `CloseBracket.matchname`
      - `CloseBracket.pos`
      - `CloseBracket.rx`
      - `CloseBracket.update_state()`
    - `CloseBracketMarkup`
      - `CloseBracketMarkup.end`
      - `CloseBracketMarkup.pos`
      - `CloseBracketMarkup.update_state()`
    - `CloseSimultaneous`
      - `CloseSimultaneous.end`
      - `CloseSimultaneous.matchname`
      - `CloseSimultaneous.pos`
      - `CloseSimultaneous.rx`
      - `CloseSimultaneous.update_state()`
    - `Command`
      - `Command.end`
      - `Command.pos`
      - `Command.test_match()`
    - `Comment`
      - `Comment.end`
      - `Comment.pos`
    - `Context`
      - `Context.end`
      - `Context.pos`
      - `Context.rx`
    - `ContextName`
      - `ContextName.end`
      - `ContextName.pos`
      - `ContextName.rx`
    - `ContextProperty`
      - `ContextProperty.end`
      - `ContextProperty.pos`
      - `ContextProperty.rx`
    - `DecimalValue`
      - `DecimalValue.end`
      - `DecimalValue.pos`
      - `DecimalValue.rx`
    - `Delimiter`
      - `Delimiter.end`
      - `Delimiter.pos`
    - `Direction`
      - `Direction.end`
      - `Direction.pos`
      - `Direction.rx`
      - `Direction.update_state()`
    - `Dot`
      - `Dot.end`
      - `Dot.pos`
      - `Dot.rx`
    - `DotChord`
      - `DotChord.end`
      - `DotChord.pos`
      - `DotChord.rx`
    - `DotPath`
      - `DotPath.end`
      - `DotPath.pos`
      - `DotPath.rx`
    - `DrumChordEnd`
      - `DrumChordEnd.end`
      - `DrumChordEnd.pos`
    - `DrumChordStart`
      - `DrumChordStart.end`
      - `DrumChordStart.pos`
      - `DrumChordStart.update_state()`
    - `DrumMode`
      - `DrumMode.end`
      - `DrumMode.pos`
      - `DrumMode.rx`
      - `DrumMode.update_state()`
    - `DrumNote`
      - `DrumNote.end`
      - `DrumNote.pos`
      - `DrumNote.rx`
    - `Duration`
      - `Duration.end`
      - `Duration.pos`
    - `Dynamic`
      - `Dynamic.end`
      - `Dynamic.pos`
      - `Dynamic.rx`
    - `EqualSign`
      - `EqualSign.end`
      - `EqualSign.pos`
      - `EqualSign.rx`
    - `Error`
      - `Error.end`
      - `Error.pos`
    - `ErrorInChord`
      - `ErrorInChord.end`
      - `ErrorInChord.pos`
      - `ErrorInChord.rx`
    - `ExpectBook`
      - `ExpectBook.pattern`
      - `ExpectBook.replace`
    - `ExpectBookPart`
      - `ExpectBookPart.pattern`
      - `ExpectBookPart.replace`
    - `ExpectChordMode`
      - `ExpectChordMode.pattern`
      - `ExpectChordMode.replace`
    - `ExpectContext`
      - `ExpectContext.pattern`
      - `ExpectContext.replace`
    - `ExpectDrumMode`
      - `ExpectDrumMode.pattern`
      - `ExpectDrumMode.replace`
    - `ExpectFigureMode`
      - `ExpectFigureMode.pattern`
      - `ExpectFigureMode.replace`
    - `ExpectGrobProperty`
      - `ExpectGrobProperty.items`
      - `ExpectGrobProperty.pattern`
      - `ExpectGrobProperty.update_state()`
    - `ExpectHeader`
      - `ExpectHeader.pattern`
      - `ExpectHeader.replace`
    - `ExpectLayout`
      - `ExpectLayout.pattern`
      - `ExpectLayout.replace`
    - `ExpectLyricMode`
      - `ExpectLyricMode.items`
      - `ExpectLyricMode.pattern`
      - `ExpectLyricMode.replace`
    - `ExpectMidi`
      - `ExpectMidi.pattern`
      - `ExpectMidi.replace`
    - `ExpectMusicList`
      - `ExpectMusicList.items`
      - `ExpectMusicList.pattern`
      - `ExpectMusicList.update_state()`
    - `ExpectNoteMode`
      - `ExpectNoteMode.replace`
    - `ExpectOpenBracket`
      - `ExpectOpenBracket.default`
      - `ExpectOpenBracket.items`
      - `ExpectOpenBracket.pattern`
      - `ExpectOpenBracket.update_state()`
    - `ExpectPaper`
      - `ExpectPaper.replace`
    - `ExpectScore`
      - `ExpectScore.replace`
    - `ExpectTranslatorId`
      - `ExpectTranslatorId.items`
      - `ExpectTranslatorId.pattern`
      - `ExpectTranslatorId.update_state()`
    - `ExpectWith`
      - `ExpectWith.replace`
    - `Figure`
      - `Figure.end`
      - `Figure.pos`
    - `FigureAccidental`
      - `FigureAccidental.end`
      - `FigureAccidental.pos`
      - `FigureAccidental.rx`
    - `FigureBracket`
      - `FigureBracket.end`
      - `FigureBracket.pos`
      - `FigureBracket.rx`
    - `FigureEnd`
      - `FigureEnd.end`
      - `FigureEnd.pos`
      - `FigureEnd.rx`
    - `FigureMode`
      - `FigureMode.end`
      - `FigureMode.pos`
      - `FigureMode.rx`
      - `FigureMode.update_state()`
    - `FigureModifier`
      - `FigureModifier.end`
      - `FigureModifier.pos`
      - `FigureModifier.rx`
    - `FigureStart`
      - `FigureStart.end`
      - `FigureStart.pos`
      - `FigureStart.rx`
      - `FigureStart.update_state()`
    - `FigureStep`
      - `FigureStep.end`
      - `FigureStep.pos`
      - `FigureStep.rx`
    - `Fingering`
      - `Fingering.end`
      - `Fingering.pos`
      - `Fingering.rx`
    - `Fraction`
      - `Fraction.end`
      - `Fraction.pos`
      - `Fraction.rx`
    - `GrobName`
      - `GrobName.end`
      - `GrobName.pos`
      - `GrobName.rx`
    - `GrobProperty`
      - `GrobProperty.end`
      - `GrobProperty.pos`
      - `GrobProperty.rx`
    - `Header`
      - `Header.end`
      - `Header.pos`
      - `Header.rx`
      - `Header.update_state()`
    - `HeaderVariable`
      - `HeaderVariable.end`
      - `HeaderVariable.pos`
      - `HeaderVariable.test_match()`
    - `Hide`
      - `Hide.end`
      - `Hide.pos`
      - `Hide.rx`
      - `Hide.update_state()`
    - `Identifier`
      - `Identifier.end`
      - `Identifier.pos`
      - `Identifier.rx`
    - `IdentifierRef`
      - `IdentifierRef.end`
      - `IdentifierRef.pos`
      - `IdentifierRef.rx`
    - `InputMode`
      - `InputMode.end`
      - `InputMode.pos`
    - `IntegerValue`
      - `IntegerValue.end`
      - `IntegerValue.pos`
      - `IntegerValue.rx`
    - `KeySignatureMode`
      - `KeySignatureMode.end`
      - `KeySignatureMode.pos`
      - `KeySignatureMode.rx`
    - `Keyword`
      - `Keyword.end`
      - `Keyword.pos`
      - `Keyword.test_match()`
    - `Layout`
      - `Layout.end`
      - `Layout.pos`
      - `Layout.rx`
      - `Layout.update_state()`
    - `LayoutContext`
      - `LayoutContext.end`
      - `LayoutContext.pos`
      - `LayoutContext.rx`
      - `LayoutContext.update_state()`
    - `LayoutVariable`
      - `LayoutVariable.end`
      - `LayoutVariable.pos`
      - `LayoutVariable.test_match()`
    - `Length`
      - `Length.end`
      - `Length.pos`
      - `Length.rx`
      - `Length.update_state()`
    - `Ligature`
      - `Ligature.end`
      - `Ligature.pos`
    - `LigatureEnd`
      - `LigatureEnd.end`
      - `LigatureEnd.matchname`
      - `LigatureEnd.pos`
      - `LigatureEnd.rx`
    - `LigatureStart`
      - `LigatureStart.end`
      - `LigatureStart.matchname`
      - `LigatureStart.pos`
      - `LigatureStart.rx`
    - `LineComment`
      - `LineComment.end`
      - `LineComment.pos`
      - `LineComment.rx`
    - `Lyric`
      - `Lyric.end`
      - `Lyric.pos`
    - `LyricExtender`
      - `LyricExtender.end`
      - `LyricExtender.pos`
      - `LyricExtender.rx`
    - `LyricHyphen`
      - `LyricHyphen.end`
      - `LyricHyphen.pos`
      - `LyricHyphen.rx`
    - `LyricMode`
      - `LyricMode.end`
      - `LyricMode.pos`
      - `LyricMode.rx`
      - `LyricMode.update_state()`
    - `LyricSkip`
      - `LyricSkip.end`
      - `LyricSkip.pos`
      - `LyricSkip.rx`
    - `LyricText`
      - `LyricText.end`
      - `LyricText.pos`
      - `LyricText.rx`
    - `Markup`
      - `Markup.end`
      - `Markup.pos`
    - `MarkupCommand`
      - `MarkupCommand.end`
      - `MarkupCommand.pos`
      - `MarkupCommand.test_match()`
      - `MarkupCommand.update_state()`
    - `MarkupLines`
      - `MarkupLines.end`
      - `MarkupLines.pos`
      - `MarkupLines.rx`
      - `MarkupLines.update_state()`
    - `MarkupList`
      - `MarkupList.end`
      - `MarkupList.pos`
      - `MarkupList.rx`
      - `MarkupList.update_state()`
    - `MarkupScore`
      - `MarkupScore.end`
      - `MarkupScore.pos`
      - `MarkupScore.rx`
      - `MarkupScore.update_state()`
    - `MarkupStart`
      - `MarkupStart.end`
      - `MarkupStart.pos`
      - `MarkupStart.rx`
      - `MarkupStart.update_state()`
    - `MarkupUserCommand`
      - `MarkupUserCommand.end`
      - `MarkupUserCommand.pos`
      - `MarkupUserCommand.update_state()`
    - `MarkupWord`
      - `MarkupWord.end`
      - `MarkupWord.pos`
      - `MarkupWord.rx`
    - `Midi`
      - `Midi.end`
      - `Midi.pos`
      - `Midi.rx`
      - `Midi.update_state()`
    - `MusicItem`
      - `MusicItem.end`
      - `MusicItem.pos`
    - `Name`
      - `Name.end`
      - `Name.pos`
    - `New`
      - `New.end`
      - `New.pos`
      - `New.rx`
    - `Note`
      - `Note.end`
      - `Note.pos`
      - `Note.rx`
    - `NoteMode`
      - `NoteMode.end`
      - `NoteMode.pos`
      - `NoteMode.rx`
      - `NoteMode.update_state()`
    - `Octave`
      - `Octave.end`
      - `Octave.pos`
      - `Octave.rx`
    - `OctaveCheck`
      - `OctaveCheck.end`
      - `OctaveCheck.pos`
      - `OctaveCheck.rx`
    - `Omit`
      - `Omit.end`
      - `Omit.pos`
      - `Omit.rx`
      - `Omit.update_state()`
    - `OpenBracket`
      - `OpenBracket.end`
      - `OpenBracket.matchname`
      - `OpenBracket.pos`
      - `OpenBracket.rx`
    - `OpenBracketMarkup`
      - `OpenBracketMarkup.end`
      - `OpenBracketMarkup.pos`
      - `OpenBracketMarkup.update_state()`
    - `OpenSimultaneous`
      - `OpenSimultaneous.end`
      - `OpenSimultaneous.matchname`
      - `OpenSimultaneous.pos`
      - `OpenSimultaneous.rx`
    - `Override`
      - `Override.end`
      - `Override.pos`
      - `Override.rx`
      - `Override.update_state()`
    - `Paper`
      - `Paper.end`
      - `Paper.pos`
      - `Paper.rx`
      - `Paper.update_state()`
    - `PaperVariable`
      - `PaperVariable.end`
      - `PaperVariable.pos`
      - `PaperVariable.test_match()`
    - `ParseAccidentalStyle`
      - `ParseAccidentalStyle.items`
      - `ParseAccidentalStyle.pattern`
      - `ParseAccidentalStyle.update_state()`
    - `ParseAlterBroken`
      - `ParseAlterBroken.items`
      - `ParseAlterBroken.pattern`
      - `ParseAlterBroken.update_state()`
    - `ParseBlockComment`
      - `ParseBlockComment.default`
      - `ParseBlockComment.items`
      - `ParseBlockComment.pattern`
    - `ParseBook`
      - `ParseBook.items`
      - `ParseBook.pattern`
    - `ParseBookPart`
      - `ParseBookPart.items`
      - `ParseBookPart.pattern`
    - `ParseChord`
      - `ParseChord.items`
      - `ParseChord.pattern`
    - `ParseChordItems`
      - `ParseChordItems.items`
      - `ParseChordItems.pattern`
    - `ParseChordMode`
      - `ParseChordMode.items`
      - `ParseChordMode.pattern`
      - `ParseChordMode.update_state()`
    - `ParseClef`
      - `ParseClef.argcount`
      - `ParseClef.items`
      - `ParseClef.pattern`
    - `ParseContext`
      - `ParseContext.items`
      - `ParseContext.pattern`
    - `ParseDecimalValue`
      - `ParseDecimalValue.items`
      - `ParseDecimalValue.pattern`
    - `ParseDrumChord`
      - `ParseDrumChord.items`
      - `ParseDrumChord.pattern`
    - `ParseDrumMode`
      - `ParseDrumMode.items`
      - `ParseDrumMode.pattern`
    - `ParseDuration`
      - `ParseDuration.fallthrough()`
      - `ParseDuration.items`
      - `ParseDuration.pattern`
    - `ParseDurationScaling`
      - `ParseDurationScaling.fallthrough()`
      - `ParseDurationScaling.items`
      - `ParseDurationScaling.pattern`
    - `ParseFigure`
      - `ParseFigure.items`
      - `ParseFigure.pattern`
    - `ParseFigureMode`
      - `ParseFigureMode.items`
      - `ParseFigureMode.pattern`
    - `ParseGlobal`
      - `ParseGlobal.items`
      - `ParseGlobal.pattern`
      - `ParseGlobal.update_state()`
    - `ParseGlobalAssignment`
      - `ParseGlobalAssignment.items`
      - `ParseGlobalAssignment.pattern`
    - `ParseGrobPropertyPath`
      - `ParseGrobPropertyPath.items`
      - `ParseGrobPropertyPath.pattern`
      - `ParseGrobPropertyPath.update_state()`
    - `ParseHeader`
      - `ParseHeader.items`
      - `ParseHeader.pattern`
    - `ParseHideOmit`
      - `ParseHideOmit.items`
      - `ParseHideOmit.pattern`
      - `ParseHideOmit.update_state()`
    - `ParseInputMode`
      - `ParseInputMode.update_state()`
    - `ParseLayout`
      - `ParseLayout.items`
      - `ParseLayout.pattern`
    - `ParseLilyPond`
      - `ParseLilyPond.mode`
    - `ParseLyricMode`
      - `ParseLyricMode.items`
      - `ParseLyricMode.pattern`
    - `ParseMarkup`
      - `ParseMarkup.items`
      - `ParseMarkup.pattern`
    - `ParseMidi`
      - `ParseMidi.items`
      - `ParseMidi.pattern`
    - `ParseMusic`
      - `ParseMusic.items`
      - `ParseMusic.pattern`
    - `ParseNoteMode`
    - `ParseOverride`
      - `ParseOverride.argcount`
      - `ParseOverride.items`
      - `ParseOverride.pattern`
      - `ParseOverride.update_state()`
    - `ParsePaper`
      - `ParsePaper.items`
      - `ParsePaper.pattern`
    - `ParsePitchCommand`
      - `ParsePitchCommand.argcount`
      - `ParsePitchCommand.items`
      - `ParsePitchCommand.pattern`
      - `ParsePitchCommand.update_state()`
    - `ParseRepeat`
      - `ParseRepeat.items`
      - `ParseRepeat.pattern`
    - `ParseRevert`
      - `ParseRevert.items`
      - `ParseRevert.pattern`
      - `ParseRevert.update_state()`
    - `ParseScore`
      - `ParseScore.items`
      - `ParseScore.pattern`
    - `ParseScriptAbbreviationOrFingering`
      - `ParseScriptAbbreviationOrFingering.argcount`
      - `ParseScriptAbbreviationOrFingering.items`
      - `ParseScriptAbbreviationOrFingering.pattern`
    - `ParseSet`
      - `ParseSet.argcount`
      - `ParseSet.items`
      - `ParseSet.pattern`
      - `ParseSet.update_state()`
    - `ParseString`
      - `ParseString.default`
      - `ParseString.items`
      - `ParseString.pattern`
    - `ParseTempo`
      - `ParseTempo.items`
      - `ParseTempo.pattern`
      - `ParseTempo.update_state()`
    - `ParseTempoAfterEqualSign`
      - `ParseTempoAfterEqualSign.items`
      - `ParseTempoAfterEqualSign.pattern`
    - `ParseTranslator`
      - `ParseTranslator.items`
      - `ParseTranslator.pattern`
      - `ParseTranslator.update_state()`
    - `ParseTranslatorId`
      - `ParseTranslatorId.argcount`
      - `ParseTranslatorId.items`
      - `ParseTranslatorId.pattern`
      - `ParseTranslatorId.update_state()`
    - `ParseTremolo`
      - `ParseTremolo.items`
      - `ParseTremolo.pattern`
    - `ParseTweak`
      - `ParseTweak.items`
      - `ParseTweak.pattern`
      - `ParseTweak.update_state()`
    - `ParseTweakGrobProperty`
      - `ParseTweakGrobProperty.items`
      - `ParseTweakGrobProperty.pattern`
      - `ParseTweakGrobProperty.update_state()`
    - `ParseUnset`
      - `ParseUnset.items`
      - `ParseUnset.pattern`
      - `ParseUnset.update_state()`
    - `ParseWith`
      - `ParseWith.items`
      - `ParseWith.pattern`
    - `Partial`
      - `Partial.end`
      - `Partial.pos`
      - `Partial.rx`
    - `PhrasingSlurEnd`
      - `PhrasingSlurEnd.end`
      - `PhrasingSlurEnd.matchname`
      - `PhrasingSlurEnd.pos`
      - `PhrasingSlurEnd.rx`
    - `PhrasingSlurStart`
      - `PhrasingSlurStart.end`
      - `PhrasingSlurStart.matchname`
      - `PhrasingSlurStart.pos`
      - `PhrasingSlurStart.rx`
    - `PipeSymbol`
      - `PipeSymbol.end`
      - `PipeSymbol.pos`
      - `PipeSymbol.rx`
    - `PitchCommand`
      - `PitchCommand.end`
      - `PitchCommand.pos`
      - `PitchCommand.rx`
      - `PitchCommand.update_state()`
    - `Q`
      - `Q.end`
      - `Q.pos`
      - `Q.rx`
    - `Repeat`
      - `Repeat.end`
      - `Repeat.pos`
      - `Repeat.rx`
      - `Repeat.update_state()`
    - `RepeatCount`
      - `RepeatCount.end`
      - `RepeatCount.pos`
    - `RepeatSpecifier`
      - `RepeatSpecifier.end`
      - `RepeatSpecifier.pos`
      - `RepeatSpecifier.rx`
    - `Rest`
      - `Rest.end`
      - `Rest.pos`
      - `Rest.rx`
    - `Revert`
      - `Revert.end`
      - `Revert.pos`
      - `Revert.rx`
      - `Revert.update_state()`
    - `Scaling`
      - `Scaling.end`
      - `Scaling.pos`
      - `Scaling.rx`
    - `SchemeStart`
      - `SchemeStart.end`
      - `SchemeStart.pos`
      - `SchemeStart.rx`
      - `SchemeStart.update_state()`
    - `Score`
      - `Score.end`
      - `Score.pos`
      - `Score.rx`
      - `Score.update_state()`
    - `ScriptAbbreviation`
      - `ScriptAbbreviation.end`
      - `ScriptAbbreviation.pos`
      - `ScriptAbbreviation.rx`
    - `SequentialEnd`
      - `SequentialEnd.end`
      - `SequentialEnd.pos`
    - `SequentialStart`
      - `SequentialStart.end`
      - `SequentialStart.pos`
      - `SequentialStart.update_state()`
    - `Set`
      - `Set.end`
      - `Set.pos`
      - `Set.rx`
      - `Set.update_state()`
    - `SimultaneousEnd`
      - `SimultaneousEnd.end`
      - `SimultaneousEnd.pos`
    - `SimultaneousOrSequentialCommand`
      - `SimultaneousOrSequentialCommand.end`
      - `SimultaneousOrSequentialCommand.pos`
      - `SimultaneousOrSequentialCommand.rx`
    - `SimultaneousStart`
      - `SimultaneousStart.end`
      - `SimultaneousStart.pos`
      - `SimultaneousStart.update_state()`
    - `Skip`
      - `Skip.end`
      - `Skip.pos`
      - `Skip.rx`
    - `Slur`
      - `Slur.end`
      - `Slur.pos`
    - `SlurEnd`
      - `SlurEnd.end`
      - `SlurEnd.matchname`
      - `SlurEnd.pos`
      - `SlurEnd.rx`
    - `SlurStart`
      - `SlurStart.end`
      - `SlurStart.matchname`
      - `SlurStart.pos`
      - `SlurStart.rx`
    - `Spacer`
      - `Spacer.end`
      - `Spacer.pos`
      - `Spacer.rx`
    - `Specifier`
      - `Specifier.end`
      - `Specifier.pos`
    - `String`
      - `String.end`
      - `String.pos`
    - `StringNumber`
      - `StringNumber.end`
      - `StringNumber.pos`
      - `StringNumber.rx`
    - `StringQuoteEscape`
      - `StringQuoteEscape.end`
      - `StringQuoteEscape.pos`
      - `StringQuoteEscape.rx`
    - `StringQuotedEnd`
      - `StringQuotedEnd.end`
      - `StringQuotedEnd.pos`
      - `StringQuotedEnd.rx`
      - `StringQuotedEnd.update_state()`
    - `StringQuotedStart`
      - `StringQuotedStart.end`
      - `StringQuotedStart.pos`
      - `StringQuotedStart.rx`
      - `StringQuotedStart.update_state()`
    - `Tempo`
      - `Tempo.end`
      - `Tempo.pos`
      - `Tempo.rx`
      - `Tempo.update_state()`
    - `TempoSeparator`
      - `TempoSeparator.end`
      - `TempoSeparator.pos`
      - `TempoSeparator.rx`
    - `Tie`
      - `Tie.end`
      - `Tie.pos`
      - `Tie.rx`
    - `Translator`
      - `Translator.end`
      - `Translator.pos`
      - `Translator.update_state()`
    - `Tremolo`
      - `Tremolo.end`
      - `Tremolo.pos`
    - `TremoloColon`
      - `TremoloColon.end`
      - `TremoloColon.pos`
      - `TremoloColon.rx`
      - `TremoloColon.update_state()`
    - `TremoloDuration`
      - `TremoloDuration.end`
      - `TremoloDuration.pos`
      - `TremoloDuration.rx`
    - `Tweak`
      - `Tweak.end`
      - `Tweak.pos`
      - `Tweak.rx`
      - `Tweak.update_state()`
    - `Unit`
      - `Unit.end`
      - `Unit.pos`
      - `Unit.rx`
    - `Unset`
      - `Unset.end`
      - `Unset.pos`
      - `Unset.rx`
      - `Unset.update_state()`
    - `UserCommand`
      - `UserCommand.end`
      - `UserCommand.pos`
    - `UserVariable`
      - `UserVariable.end`
      - `UserVariable.pos`
    - `Value`
      - `Value.end`
      - `Value.pos`
    - `Variable`
      - `Variable.end`
      - `Variable.pos`
    - `VoiceSeparator`
      - `VoiceSeparator.end`
      - `VoiceSeparator.pos`
      - `VoiceSeparator.rx`
    - `With`
      - `With.end`
      - `With.pos`
      - `With.rx`
      - `With.update_state()`
  - ly.lex.scheme module
    - `BlockComment`
      - `BlockComment.end`
      - `BlockComment.pos`
    - `BlockCommentEnd`
      - `BlockCommentEnd.end`
      - `BlockCommentEnd.pos`
      - `BlockCommentEnd.rx`
    - `BlockCommentStart`
      - `BlockCommentStart.end`
      - `BlockCommentStart.pos`
      - `BlockCommentStart.rx`
      - `BlockCommentStart.update_state()`
    - `Bool`
      - `Bool.end`
      - `Bool.pos`
      - `Bool.rx`
    - `Char`
      - `Char.end`
      - `Char.pos`
      - `Char.rx`
    - `CloseParen`
      - `CloseParen.end`
      - `CloseParen.matchname`
      - `CloseParen.pos`
      - `CloseParen.rx`
      - `CloseParen.update_state()`
    - `Comment`
      - `Comment.end`
      - `Comment.pos`
    - `Constant`
      - `Constant.end`
      - `Constant.pos`
      - `Constant.test_match()`
    - `Dot`
      - `Dot.end`
      - `Dot.pos`
      - `Dot.rx`
    - `Float`
      - `Float.end`
      - `Float.pos`
      - `Float.rx`
    - `Fraction`
      - `Fraction.end`
      - `Fraction.pos`
      - `Fraction.rx`
    - `Function`
      - `Function.end`
      - `Function.pos`
      - `Function.test_match()`
    - `Keyword`
      - `Keyword.end`
      - `Keyword.pos`
      - `Keyword.test_match()`
    - `LilyPond`
      - `LilyPond.end`
      - `LilyPond.pos`
    - `LilyPondEnd`
      - `LilyPondEnd.end`
      - `LilyPondEnd.matchname`
      - `LilyPondEnd.pos`
      - `LilyPondEnd.rx`
    - `LilyPondStart`
      - `LilyPondStart.end`
      - `LilyPondStart.matchname`
      - `LilyPondStart.pos`
      - `LilyPondStart.rx`
      - `LilyPondStart.update_state()`
    - `LineComment`
      - `LineComment.end`
      - `LineComment.pos`
      - `LineComment.rx`
    - `Number`
      - `Number.end`
      - `Number.pos`
      - `Number.rx`
    - `OpenParen`
      - `OpenParen.end`
      - `OpenParen.matchname`
      - `OpenParen.pos`
      - `OpenParen.rx`
      - `OpenParen.update_state()`
    - `ParseBlockComment`
      - `ParseBlockComment.default`
      - `ParseBlockComment.items`
      - `ParseBlockComment.pattern`
    - `ParseLilyPond`
      - `ParseLilyPond.items`
      - `ParseLilyPond.pattern`
    - `ParseScheme`
      - `ParseScheme.items`
      - `ParseScheme.mode`
      - `ParseScheme.pattern`
    - `ParseString`
      - `ParseString.default`
      - `ParseString.items`
      - `ParseString.pattern`
    - `Quote`
      - `Quote.end`
      - `Quote.pos`
      - `Quote.rx`
    - `Scheme`
      - `Scheme.end`
      - `Scheme.pos`
    - `String`
      - `String.end`
      - `String.pos`
    - `StringQuoteEscape`
      - `StringQuoteEscape.end`
      - `StringQuoteEscape.pos`
      - `StringQuoteEscape.rx`
    - `StringQuotedEnd`
      - `StringQuotedEnd.end`
      - `StringQuotedEnd.pos`
      - `StringQuotedEnd.rx`
      - `StringQuotedEnd.update_state()`
    - `StringQuotedStart`
      - `StringQuotedStart.end`
      - `StringQuotedStart.pos`
      - `StringQuotedStart.rx`
      - `StringQuotedStart.update_state()`
    - `Variable`
      - `Variable.end`
      - `Variable.pos`
      - `Variable.test_match()`
    - `VectorStart`
      - `VectorStart.end`
      - `VectorStart.pos`
      - `VectorStart.rx`
    - `Word`
      - `Word.end`
      - `Word.pos`
      - `Word.rx`
  - ly.lex.texinfo module
    - `Accent`
      - `Accent.end`
      - `Accent.pos`
      - `Accent.rx`
    - `Attribute`
      - `Attribute.end`
      - `Attribute.pos`
    - `Block`
      - `Block.end`
      - `Block.pos`
    - `BlockCommentEnd`
      - `BlockCommentEnd.end`
      - `BlockCommentEnd.pos`
      - `BlockCommentEnd.rx`
    - `BlockCommentStart`
      - `BlockCommentStart.end`
      - `BlockCommentStart.pos`
      - `BlockCommentStart.rx`
      - `BlockCommentStart.update_state()`
    - `BlockEnd`
      - `BlockEnd.end`
      - `BlockEnd.pos`
      - `BlockEnd.rx`
    - `BlockStart`
      - `BlockStart.end`
      - `BlockStart.pos`
      - `BlockStart.rx`
      - `BlockStart.update_state()`
    - `Comment`
      - `Comment.end`
      - `Comment.pos`
    - `EscapeChar`
      - `EscapeChar.end`
      - `EscapeChar.pos`
      - `EscapeChar.rx`
    - `Keyword`
      - `Keyword.end`
      - `Keyword.pos`
      - `Keyword.rx`
    - `LilyPondAttrEnd`
      - `LilyPondAttrEnd.end`
      - `LilyPondAttrEnd.pos`
      - `LilyPondAttrEnd.rx`
    - `LilyPondAttrStart`
      - `LilyPondAttrStart.end`
      - `LilyPondAttrStart.pos`
      - `LilyPondAttrStart.rx`
      - `LilyPondAttrStart.update_state()`
    - `LilyPondBlockEnd`
      - `LilyPondBlockEnd.end`
      - `LilyPondBlockEnd.pos`
      - `LilyPondBlockEnd.rx`
    - `LilyPondBlockStart`
      - `LilyPondBlockStart.end`
      - `LilyPondBlockStart.pos`
      - `LilyPondBlockStart.rx`
      - `LilyPondBlockStart.update_state()`
    - `LilyPondBlockStartBrace`
      - `LilyPondBlockStartBrace.end`
      - `LilyPondBlockStartBrace.pos`
      - `LilyPondBlockStartBrace.rx`
      - `LilyPondBlockStartBrace.update_state()`
    - `LilyPondEnvEnd`
      - `LilyPondEnvEnd.end`
      - `LilyPondEnvEnd.pos`
      - `LilyPondEnvEnd.rx`
    - `LilyPondEnvStart`
      - `LilyPondEnvStart.end`
      - `LilyPondEnvStart.pos`
      - `LilyPondEnvStart.rx`
      - `LilyPondEnvStart.update_state()`
    - `LilyPondFileStart`
      - `LilyPondFileStart.end`
      - `LilyPondFileStart.pos`
      - `LilyPondFileStart.rx`
      - `LilyPondFileStart.update_state()`
    - `LilyPondFileStartBrace`
      - `LilyPondFileStartBrace.end`
      - `LilyPondFileStartBrace.pos`
      - `LilyPondFileStartBrace.rx`
      - `LilyPondFileStartBrace.update_state()`
    - `LineComment`
      - `LineComment.end`
      - `LineComment.pos`
      - `LineComment.rx`
    - `ParseBlock`
      - `ParseBlock.items`
      - `ParseBlock.pattern`
    - `ParseComment`
      - `ParseComment.default`
      - `ParseComment.items`
      - `ParseComment.pattern`
    - `ParseLilyPondAttr`
      - `ParseLilyPondAttr.default`
      - `ParseLilyPondAttr.items`
      - `ParseLilyPondAttr.pattern`
    - `ParseLilyPondBlock`
      - `ParseLilyPondBlock.items`
      - `ParseLilyPondBlock.pattern`
    - `ParseLilyPondBlockAttr`
      - `ParseLilyPondBlockAttr.items`
      - `ParseLilyPondBlockAttr.pattern`
    - `ParseLilyPondEnv`
      - `ParseLilyPondEnv.items`
      - `ParseLilyPondEnv.pattern`
    - `ParseLilyPondEnvAttr`
      - `ParseLilyPondEnvAttr.fallthrough()`
      - `ParseLilyPondEnvAttr.items`
      - `ParseLilyPondEnvAttr.pattern`
    - `ParseLilyPondFile`
      - `ParseLilyPondFile.items`
      - `ParseLilyPondFile.pattern`
    - `ParseTexinfo`
      - `ParseTexinfo.items`
      - `ParseTexinfo.mode`
      - `ParseTexinfo.pattern`
    - `ParseVerbatim`
      - `ParseVerbatim.default`
      - `ParseVerbatim.items`
      - `ParseVerbatim.pattern`
    - `Verbatim`
      - `Verbatim.end`
      - `Verbatim.pos`
    - `VerbatimEnd`
      - `VerbatimEnd.end`
      - `VerbatimEnd.pos`
      - `VerbatimEnd.rx`
    - `VerbatimStart`
      - `VerbatimStart.end`
      - `VerbatimStart.pos`
      - `VerbatimStart.rx`
      - `VerbatimStart.update_state()`
- ly.music package
  - Module contents
    - `document()`
  - Submodules
  - ly.music.event module
    - `Events`
      - `Events.read()`
      - `Events.traverse()`
      - `Events.unfold_repeats`
  - ly.music.items module
    - `Absolute`
    - `AfterGrace`
    - `Alternative`
    - `Articulation`
    - `Assignment`
      - `Assignment.name()`
      - `Assignment.value()`
    - `Beam`
      - `Beam.event`
    - `Book`
    - `BookPart`
    - `Change`
    - `Chord`
    - `ChordItem`
    - `ChordMode`
    - `ChordSpecifier`
    - `Clef`
      - `Clef.specifier()`
    - `Command`
    - `Container`
    - `Context`
    - `Document`
      - `Document.get_included_document_node()`
      - `Document.get_music()`
      - `Document.iter_music()`
      - `Document.music_events_til_position()`
      - `Document.node()`
      - `Document.resolve_filename()`
      - `Document.substitute_for_node()`
      - `Document.time_length()`
      - `Document.time_position()`
    - `DrumMode`
    - `DrumNote`
    - `Durable`
      - `Durable.duration`
      - `Durable.events()`
      - `Durable.length()`
    - `Duration`
    - `Dynamic`
    - `FigureMode`
    - `Grace`
      - `Grace.events()`
      - `Grace.preceding()`
    - `Header`
    - `Include`
      - `Include.filename()`
    - `InputMode`
    - `Item`
      - `Item.document`
      - `Item.end_position()`
      - `Item.events()`
      - `Item.has_output()`
      - `Item.iter_toplevel_items()`
      - `Item.iter_toplevel_items_include()`
      - `Item.length()`
      - `Item.music_children()`
      - `Item.music_parent()`
      - `Item.plaintext()`
      - `Item.position`
      - `Item.token`
      - `Item.tokens`
    - `KeySignature`
      - `KeySignature.mode()`
      - `KeySignature.pitch()`
    - `Keyword`
    - `Language`
      - `Language.language`
    - `Layout`
    - `LayoutContext`
    - `LyricItem`
    - `LyricMode`
    - `LyricText`
    - `LyricsTo`
      - `LyricsTo.context_id()`
    - `Markup`
      - `Markup.plaintext()`
    - `MarkupCommand`
      - `MarkupCommand.plaintext()`
    - `MarkupList`
      - `MarkupList.plaintext()`
    - `MarkupScore`
    - `MarkupUserCommand`
      - `MarkupUserCommand.name()`
      - `MarkupUserCommand.value()`
    - `MarkupWord`
      - `MarkupWord.plaintext()`
    - `Midi`
    - `Music`
      - `Music.events()`
      - `Music.length()`
      - `Music.preceding()`
    - `MusicList`
      - `MusicList.events()`
      - `MusicList.preceding()`
      - `MusicList.simultaneous`
    - `Note`
      - `Note.accidental_token`
      - `Note.octave_token`
      - `Note.octavecheck_token`
      - `Note.pitch`
    - `NoteMode`
    - `Number`
      - `Number.value()`
    - `Override`
      - `Override.context()`
      - `Override.grob()`
    - `Paper`
    - `PartCombine`
      - `PartCombine.events()`
      - `PartCombine.preceding()`
    - `Partial`
      - `Partial.duration`
      - `Partial.partial_length()`
    - `PathItem`
    - `PhrasingSlur`
      - `PhrasingSlur.event`
    - `PipeSymbol`
    - `Postfix`
    - `Q`
    - `Relative`
    - `Repeat`
      - `Repeat.events()`
      - `Repeat.repeat_count()`
      - `Repeat.specifier()`
    - `Rest`
    - `Revert`
      - `Revert.context()`
      - `Revert.grob()`
    - `Scaler`
      - `Scaler.denominator`
      - `Scaler.events()`
      - `Scaler.numerator`
      - `Scaler.preceding()`
      - `Scaler.scaling`
    - `Scheme`
      - `Scheme.get_fraction()`
      - `Scheme.get_int()`
      - `Scheme.get_list_ints()`
      - `Scheme.get_ly_make_moment()`
      - `Scheme.get_pair_ints()`
      - `Scheme.get_string()`
      - `Scheme.plaintext()`
    - `SchemeItem`
    - `SchemeLily`
    - `SchemeList`
    - `SchemeQuote`
    - `Score`
    - `Set`
      - `Set.context()`
      - `Set.property()`
      - `Set.value()`
    - `Skip`
    - `Slur`
      - `Slur.event`
    - `String`
      - `String.plaintext()`
      - `String.value()`
    - `StringTuning`
    - `Tag`
      - `Tag.events()`
      - `Tag.preceding()`
    - `Tempo`
      - `Tempo.duration`
      - `Tempo.fraction()`
      - `Tempo.tempo()`
      - `Tempo.text()`
    - `Tie`
    - `TimeSignature`
      - `TimeSignature.beatstructure()`
      - `TimeSignature.fraction()`
      - `TimeSignature.measure_length()`
      - `TimeSignature.numerator()`
    - `Token`
    - `Translator`
      - `Translator.context()`
      - `Translator.context_id()`
    - `Transpose`
    - `Tremolo`
      - `Tremolo.duration`
    - `Tweak`
    - `Unpitched`
      - `Unpitched.pitch`
    - `Unset`
      - `Unset.context()`
      - `Unset.property()`
    - `UserCommand`
      - `UserCommand.events()`
      - `UserCommand.name()`
      - `UserCommand.value()`
    - `Version`
      - `Version.version()`
      - `Version.version_string()`
    - `VoiceSeparator`
    - `With`
  - ly.music.read module
    - `Reader`
      - `Reader.add_bracketed()`
      - `Reader.add_duration()`
      - `Reader.add_markup_arguments()`
      - `Reader.consume()`
      - `Reader.factory()`
      - `Reader.handle_absolute()`
      - `Reader.handle_after_grace()`
      - `Reader.handle_alternative()`
      - `Reader.handle_articulation()`
      - `Reader.handle_beam()`
      - `Reader.handle_bracketed()`
      - `Reader.handle_chord_start()`
      - `Reader.handle_clef()`
      - `Reader.handle_direct_items()`
      - `Reader.handle_direction()`
      - `Reader.handle_grace()`
      - `Reader.handle_include()`
      - `Reader.handle_inputmode()`
      - `Reader.handle_key()`
      - `Reader.handle_language()`
      - `Reader.handle_length()`
      - `Reader.handle_lyricmode()`
      - `Reader.handle_markup()`
      - `Reader.handle_markup_command()`
      - `Reader.handle_markup_open_bracket()`
      - `Reader.handle_markup_score()`
      - `Reader.handle_markup_user_command()`
      - `Reader.handle_markup_word()`
      - `Reader.handle_music_item()`
      - `Reader.handle_music_list()`
      - `Reader.handle_name()`
      - `Reader.handle_number_class()`
      - `Reader.handle_override()`
      - `Reader.handle_partcombine()`
      - `Reader.handle_partial()`
      - `Reader.handle_relative()`
      - `Reader.handle_repeat()`
      - `Reader.handle_revert()`
      - `Reader.handle_scaler()`
      - `Reader.handle_scheme_lilypond_start()`
      - `Reader.handle_scheme_open_parenthesis()`
      - `Reader.handle_scheme_quote()`
      - `Reader.handle_scheme_start()`
      - `Reader.handle_scheme_token()`
      - `Reader.handle_set()`
      - `Reader.handle_slurs()`
      - `Reader.handle_string_start()`
      - `Reader.handle_string_tuning()`
      - `Reader.handle_tag()`
      - `Reader.handle_tempo()`
      - `Reader.handle_time()`
      - `Reader.handle_translator()`
      - `Reader.handle_transpose()`
      - `Reader.handle_tweak()`
      - `Reader.handle_unset()`
      - `Reader.handle_variable_assignment()`
      - `Reader.handle_version()`
      - `Reader.read()`
      - `Reader.read_assignment()`
      - `Reader.read_chord_specifier()`
      - `Reader.read_command()`
      - `Reader.read_item()`
      - `Reader.read_keyword()`
      - `Reader.read_lyric_item()`
      - `Reader.read_markup()`
      - `Reader.read_music_item()`
      - `Reader.read_scheme()`
      - `Reader.read_scheme_item()`
      - `Reader.read_tremolo()`
      - `Reader.read_user_command()`
      - `Reader.set_language()`
      - `Reader.test_music_list()`
    - `dispatcher`
      - `dispatcher.method()`
      - `dispatcher.read_arg()`
    - `dispatcher_class`
      - `dispatcher_class.method()`
      - `dispatcher_class.read_arg()`
    - `skip()`
- ly.musicxml package
  - Module contents
    - `writer()`
  - Submodules
  - ly.musicxml.create_musicxml module
    - `CreateMusicXML`
      - `CreateMusicXML.add_accidental()`
      - `CreateMusicXML.add_articulations()`
      - `CreateMusicXML.add_backup()`
      - `CreateMusicXML.add_bar_style()`
      - `CreateMusicXML.add_barline()`
      - `CreateMusicXML.add_beam()`
      - `CreateMusicXML.add_chord()`
      - `CreateMusicXML.add_clef()`
      - `CreateMusicXML.add_creator()`
      - `CreateMusicXML.add_direction()`
      - `CreateMusicXML.add_dirwords()`
      - `CreateMusicXML.add_div_duration()`
      - `CreateMusicXML.add_divisions()`
      - `CreateMusicXML.add_dot()`
      - `CreateMusicXML.add_duration_type()`
      - `CreateMusicXML.add_dynamic_dashes()`
      - `CreateMusicXML.add_dynamic_mark()`
      - `CreateMusicXML.add_dynamic_text()`
      - `CreateMusicXML.add_dynamic_wedge()`
      - `CreateMusicXML.add_fingering()`
      - `CreateMusicXML.add_gliss()`
      - `CreateMusicXML.add_grace()`
      - `CreateMusicXML.add_key()`
      - `CreateMusicXML.add_lyric()`
      - `CreateMusicXML.add_mark()`
      - `CreateMusicXML.add_metron_dir()`
      - `CreateMusicXML.add_mordent()`
      - `CreateMusicXML.add_named_artic()`
      - `CreateMusicXML.add_named_notation()`
      - `CreateMusicXML.add_notations()`
      - `CreateMusicXML.add_octave_shift()`
      - `CreateMusicXML.add_ornaments()`
      - `CreateMusicXML.add_pitch()`
      - `CreateMusicXML.add_prall()`
      - `CreateMusicXML.add_rest()`
      - `CreateMusicXML.add_rest_w_pos()`
      - `CreateMusicXML.add_rights()`
      - `CreateMusicXML.add_skip()`
      - `CreateMusicXML.add_slur()`
      - `CreateMusicXML.add_sound_dir()`
      - `CreateMusicXML.add_staff()`
      - `CreateMusicXML.add_staves()`
      - `CreateMusicXML.add_technical()`
      - `CreateMusicXML.add_tie()`
      - `CreateMusicXML.add_tied()`
      - `CreateMusicXML.add_time()`
      - `CreateMusicXML.add_time_modify()`
      - `CreateMusicXML.add_tremolo()`
      - `CreateMusicXML.add_trill()`
      - `CreateMusicXML.add_tuplet_type()`
      - `CreateMusicXML.add_turn()`
      - `CreateMusicXML.add_unpitched()`
      - `CreateMusicXML.add_voice()`
      - `CreateMusicXML.add_wavyline()`
      - `CreateMusicXML.adjust_time_modify()`
      - `CreateMusicXML.change_div_duration()`
      - `CreateMusicXML.create_bar_attr()`
      - `CreateMusicXML.create_measure()`
      - `CreateMusicXML.create_new_node()`
      - `CreateMusicXML.create_note()`
      - `CreateMusicXML.create_part()`
      - `CreateMusicXML.create_partgroup()`
      - `CreateMusicXML.create_score_info()`
      - `CreateMusicXML.create_tempo()`
      - `CreateMusicXML.create_title()`
      - `CreateMusicXML.get_time_modify()`
      - `CreateMusicXML.musicxml()`
      - `CreateMusicXML.new_adv_ornament()`
      - `CreateMusicXML.new_articulation()`
      - `CreateMusicXML.new_bar_attr()`
      - `CreateMusicXML.new_note()`
      - `CreateMusicXML.new_rest()`
      - `CreateMusicXML.new_simple_ornament()`
      - `CreateMusicXML.new_system()`
      - `CreateMusicXML.new_unpitched_note()`
      - `CreateMusicXML.set_stem_dir()`
      - `CreateMusicXML.tie_note()`
      - `CreateMusicXML.tuplet_note()`
    - `MusicXML`
      - `MusicXML.indent()`
      - `MusicXML.tostring()`
      - `MusicXML.write()`
    - `get_tag_index()`
  - ly.musicxml.ly2xml_mediator module
    - `Mediator`
      - `Mediator.add_break()`
      - `Mediator.add_snippet()`
      - `Mediator.add_staff_id()`
      - `Mediator.add_to_bar()`
      - `Mediator.bijective()`
      - `Mediator.calc_tupl_den()`
      - `Mediator.change_group_bracket()`
      - `Mediator.change_to_tuplet()`
      - `Mediator.change_tuplet_type()`
      - `Mediator.check_current_note()`
      - `Mediator.check_divs()`
      - `Mediator.check_duration()`
      - `Mediator.check_lyrics()`
      - `Mediator.check_name()`
      - `Mediator.check_part()`
      - `Mediator.check_score()`
      - `Mediator.check_simultan()`
      - `Mediator.check_voices()`
      - `Mediator.check_voices_by_nr()`
      - `Mediator.chord_end()`
      - `Mediator.clear_chord()`
      - `Mediator.close_group()`
      - `Mediator.copy_barnote_basics()`
      - `Mediator.copy_prev_chord()`
      - `Mediator.create_barline()`
      - `Mediator.create_barnote_from_note()`
      - `Mediator.create_unpitched()`
      - `Mediator.do_action_onnext()`
      - `Mediator.duration_from_tokens()`
      - `Mediator.end_gliss()`
      - `Mediator.get_first_var()`
      - `Mediator.get_part_by_id()`
      - `Mediator.get_var_byname()`
      - `Mediator.increase_bar_dura()`
      - `Mediator.new_articulation()`
      - `Mediator.new_bar()`
      - `Mediator.new_chord()`
      - `Mediator.new_chord_grace()`
      - `Mediator.new_chordbase()`
      - `Mediator.new_chordnote()`
      - `Mediator.new_clef()`
      - `Mediator.new_duration_token()`
      - `Mediator.new_dynamics()`
      - `Mediator.new_gliss()`
      - `Mediator.new_grace()`
      - `Mediator.new_group()`
      - `Mediator.new_header_assignment()`
      - `Mediator.new_iso_dura()`
      - `Mediator.new_key()`
      - `Mediator.new_lyric_nr()`
      - `Mediator.new_lyric_section()`
      - `Mediator.new_lyrics_item()`
      - `Mediator.new_lyrics_text()`
      - `Mediator.new_mark()`
      - `Mediator.new_note()`
      - `Mediator.new_ottava()`
      - `Mediator.new_part()`
      - `Mediator.new_repeat()`
      - `Mediator.new_rest()`
      - `Mediator.new_section()`
      - `Mediator.new_snippet()`
      - `Mediator.new_tempo()`
      - `Mediator.new_time()`
      - `Mediator.new_trill_spanner()`
      - `Mediator.new_word()`
      - `Mediator.note2rest()`
      - `Mediator.part_not_empty()`
      - `Mediator.revert_voicenr()`
      - `Mediator.scale_rest()`
      - `Mediator.sections`
      - `Mediator.set_by_property()`
      - `Mediator.set_groupabbr()`
      - `Mediator.set_groupname()`
      - `Mediator.set_mult_rest()`
      - `Mediator.set_mult_rest_bar()`
      - `Mediator.set_octave()`
      - `Mediator.set_ottava()`
      - `Mediator.set_partabbr()`
      - `Mediator.set_partmidi()`
      - `Mediator.set_partname()`
      - `Mediator.set_pickup()`
      - `Mediator.set_relative()`
      - `Mediator.set_slur()`
      - `Mediator.set_staffnr()`
      - `Mediator.set_tremolo()`
      - `Mediator.set_tuplspan_dur()`
      - `Mediator.set_voicenr()`
      - `Mediator.stem_direction()`
      - `Mediator.tie_to_next()`
      - `Mediator.unset_tuplspan_dur()`
    - `artic_token2xml_name()`
    - `calc_trem_dur()`
    - `clefname2clef()`
    - `durval2type()`
    - `getNoteName()`
    - `get_fifths()`
    - `get_group_symbol()`
    - `get_line_style()`
    - `get_mult()`
    - `get_voice()`
    - `get_xml_alter()`
  - ly.musicxml.lymus2musxml module
    - `End`
    - `ParseSource`
      - `ParseSource.Articulation()`
      - `ParseSource.Assignment()`
      - `ParseSource.Beam()`
      - `ParseSource.Change()`
      - `ParseSource.Chord()`
      - `ParseSource.ChordMode()`
      - `ParseSource.Clef()`
      - `ParseSource.Command()`
      - `ParseSource.Context()`
      - `ParseSource.DrumMode()`
      - `ParseSource.DrumNote()`
      - `ParseSource.Duration()`
      - `ParseSource.Dynamic()`
      - `ParseSource.End()`
      - `ParseSource.FigureMode()`
      - `ParseSource.Grace()`
      - `ParseSource.KeySignature()`
      - `ParseSource.LyricItem()`
      - `ParseSource.LyricMode()`
      - `ParseSource.LyricText()`
      - `ParseSource.LyricsTo()`
      - `ParseSource.Markup()`
      - `ParseSource.MarkupList()`
      - `ParseSource.MarkupWord()`
      - `ParseSource.MusicList()`
      - `ParseSource.Note()`
      - `ParseSource.NoteMode()`
      - `ParseSource.Number()`
      - `ParseSource.Override()`
      - `ParseSource.Partial()`
      - `ParseSource.PathItem()`
      - `ParseSource.PhrasingSlur()`
      - `ParseSource.PipeSymbol()`
      - `ParseSource.Postfix()`
      - `ParseSource.Q()`
      - `ParseSource.Relative()`
      - `ParseSource.Repeat()`
      - `ParseSource.Rest()`
      - `ParseSource.Scaler()`
      - `ParseSource.Scheme()`
      - `ParseSource.SchemeItem()`
      - `ParseSource.SchemeQuote()`
      - `ParseSource.Set()`
      - `ParseSource.Skip()`
      - `ParseSource.Slur()`
      - `ParseSource.String()`
      - `ParseSource.Tempo()`
      - `ParseSource.Tie()`
      - `ParseSource.TimeSignature()`
      - `ParseSource.Tremolo()`
      - `ParseSource.Unpitched()`
      - `ParseSource.UserCommand()`
      - `ParseSource.VoiceSeparator()`
      - `ParseSource.With()`
      - `ParseSource.check_context()`
      - `ParseSource.check_note()`
      - `ParseSource.check_tuplet()`
      - `ParseSource.find_score_sub()`
      - `ParseSource.gen_med_caller()`
      - `ParseSource.get_previous_node()`
      - `ParseSource.get_score()`
      - `ParseSource.iter_header()`
      - `ParseSource.iter_score()`
      - `ParseSource.look_ahead()`
      - `ParseSource.look_behind()`
      - `ParseSource.musicxml()`
      - `ParseSource.parse_document()`
      - `ParseSource.parse_nodes()`
      - `ParseSource.parse_text()`
      - `ParseSource.parse_tree()`
      - `ParseSource.simple_node_gen()`
      - `ParseSource.unfold_repeat()`
  - ly.musicxml.xml_objs module
    - `Bar`
      - `Bar.add()`
      - `Bar.create_backup()`
      - `Bar.has_attr()`
      - `Bar.has_music()`
      - `Bar.inject_voice()`
      - `Bar.is_skip()`
    - `BarAttr`
      - `BarAttr.add_break()`
      - `BarAttr.has_attr()`
      - `BarAttr.merge_attr()`
      - `BarAttr.set_barline()`
      - `BarAttr.set_clef()`
      - `BarAttr.set_key()`
      - `BarAttr.set_mark()`
      - `BarAttr.set_multp_rest()`
      - `BarAttr.set_tempo()`
      - `BarAttr.set_time()`
      - `BarAttr.set_word()`
    - `BarBackup`
    - `BarMus`
      - `BarMus.add_dot()`
      - `BarMus.add_other_notation()`
      - `BarMus.has_attr()`
      - `BarMus.set_dynamics_dashes()`
      - `BarMus.set_dynamics_mark()`
      - `BarMus.set_dynamics_text()`
      - `BarMus.set_dynamics_wedge()`
      - `BarMus.set_oct_shift()`
      - `BarMus.set_staff()`
      - `BarMus.set_tuplet()`
    - `BarNote`
      - `BarNote.add_adv_ornament()`
      - `BarNote.add_articulation()`
      - `BarNote.add_fingering()`
      - `BarNote.add_lyric()`
      - `BarNote.add_ornament()`
      - `BarNote.change_lyric_nr()`
      - `BarNote.change_lyric_syll()`
      - `BarNote.set_duration()`
      - `BarNote.set_durtype()`
      - `BarNote.set_gliss()`
      - `BarNote.set_grace()`
      - `BarNote.set_octave()`
      - `BarNote.set_slur()`
      - `BarNote.set_stem_direction()`
      - `BarNote.set_tie()`
      - `BarNote.set_tremolo()`
    - `BarRest`
      - `BarRest.set_duration()`
      - `BarRest.set_durtype()`
    - `Dynamics`
    - `DynamicsDashes`
    - `DynamicsMark`
    - `DynamicsText`
    - `DynamicsWedge`
    - `IterateXmlObjs`
      - `IterateXmlObjs.after_note()`
      - `IterateXmlObjs.before_note()`
      - `IterateXmlObjs.count_duration()`
      - `IterateXmlObjs.gener_xml_mus()`
      - `IterateXmlObjs.iterate_bar()`
      - `IterateXmlObjs.iterate_part()`
      - `IterateXmlObjs.iterate_partgroup()`
      - `IterateXmlObjs.new_xml_bar_attr()`
      - `IterateXmlObjs.new_xml_note()`
      - `IterateXmlObjs.new_xml_rest()`
    - `LyricsSection`
    - `OctaveShift`
    - `Score`
      - `Score.add_right()`
      - `Score.debug_score()`
      - `Score.is_empty()`
      - `Score.merge_globally()`
    - `ScorePart`
      - `ScorePart.extract_global_to_section()`
      - `ScorePart.merge_part_to_part()`
      - `ScorePart.set_first_bar()`
    - `ScorePartGroup`
      - `ScorePartGroup.merge_voice()`
      - `ScorePartGroup.set_bracket()`
    - `ScoreSection`
      - `ScoreSection.merge_lyrics()`
      - `ScoreSection.merge_voice()`
    - `Slur`
    - `SlurCount`
      - `SlurCount.dec()`
      - `SlurCount.inc()`
    - `Snippet`
    - `TempoDir`
      - `TempoDir.set_midi_tempo()`
    - `Tuplet`
    - `Unpitched`
    - `convert_barl()`
    - `dur2lines()`
- ly.pitch package
  - Module contents
    - `LanguageName`
      - `LanguageName.end`
      - `LanguageName.pos`
    - `Pitch`
      - `Pitch.c0()`
      - `Pitch.c1()`
      - `Pitch.copy()`
      - `Pitch.f0()`
      - `Pitch.makeAbsolute()`
      - `Pitch.makeRelative()`
      - `Pitch.output()`
    - `PitchIterator`
      - `PitchIterator.pitches()`
      - `PitchIterator.position()`
      - `PitchIterator.read()`
      - `PitchIterator.setLanguage()`
      - `PitchIterator.tokens()`
      - `PitchIterator.write()`
    - `PitchNameNotAvailable`
    - `PitchReader`
    - `PitchWriter`
      - `PitchWriter.language`
    - `octaveToNum()`
    - `octaveToString()`
    - `pitchReader()`
    - `pitchWriter()`
  - Submodules
  - ly.pitch.abs2rel module
    - `abs2rel()`
  - ly.pitch.rel2abs module
    - `rel2abs()`
  - ly.pitch.translate module
    - `insert_language()`
    - `translate()`
  - ly.pitch.transpose module
    - `ModalTransposer`
      - `ModalTransposer.getKeyIndex()`
      - `ModalTransposer.transpose()`
    - `ModeShifter`
      - `ModeShifter.closestPitch()`
      - `ModeShifter.transpose()`
    - `Simplifier`
      - `Simplifier.transpose()`
    - `Transposer`
      - `Transposer.scale`
      - `Transposer.transpose()`
    - `transpose()`
- ly.xml package
  - Introduction
  - Module contents
  - The `xml-export.ily` file
  - Example
- ly.data package
  - Module contents
    - `all_grob_properties()`
    - `all_scheme_words()`
    - `context_properties()`
    - `engravers()`
    - `grob_interface_properties()`
    - `grob_interfaces()`
    - `grob_interfaces_for_property()`
    - `grob_properties()`
    - `grob_properties_with_interface()`
    - `grobs()`
    - `music_glyphs()`
    - `scheme_constants()`
    - `scheme_functions()`
    - `scheme_keywords()`
    - `scheme_variables()`
  - Submodules
  - ly.data.makeschemedata module
- ly.cli package
  - Module contents
  - Submodules
  - ly.cli.command module
    - `abs2rel`
      - `abs2rel.run()`
    - `highlight`
      - `highlight.run()`
    - `hl`
    - `indent`
      - `indent.indenter()`
      - `indent.run()`
    - `language`
      - `language.get_info()`
    - `mode`
      - `mode.get_info()`
    - `musicxml`
      - `musicxml.run()`
    - `reformat`
      - `reformat.run()`
    - `rel2abs`
      - `rel2abs.run()`
    - `set_variable`
      - `set_variable.run()`
    - `simplify_accidentals`
      - `simplify_accidentals.run()`
    - `translate`
      - `translate.run()`
    - `transpose`
      - `transpose.run()`
    - `version`
      - `version.get_info()`
    - `write`
      - `write.run()`
  - ly.cli.main module
    - `Options`
      - `Options.set_variable()`
    - `Output`
      - `Output.file()`
      - `Output.get_filename()`
    - `die()`
    - `load()`
    - `main()`
    - `parse_command()`
    - `parse_command_line()`
    - `usage()`
    - `usage_short()`
    - `version()`
- ly.server package
  - Module contents
  - Submodules
  - ly.server.command module
    - `abs2rel`
      - `abs2rel.edit()`
    - `highlight`
      - `highlight.export()`
    - `indent`
      - `indent.edit()`
      - `indent.indenter()`
    - `language`
      - `language.get_info()`
    - `mode`
      - `mode.get_info()`
    - `musicxml`
      - `musicxml.export()`
    - `reformat`
      - `reformat.edit()`
    - `rel2abs`
      - `rel2abs.edit()`
    - `set_variable`
      - `set_variable.run()`
    - `translate`
      - `translate.edit()`
    - `transpose`
      - `transpose.edit()`
    - `version`
      - `version.get_info()`
  - ly.server.handler module
    - `RequestHandler`
      - `RequestHandler.create_command()`
      - `RequestHandler.do_POST()`
      - `RequestHandler.process_json_request()`
      - `RequestHandler.process_options()`
      - `RequestHandler.read_json_request()`
  - ly.server.main module
    - `die()`
    - `main()`
    - `parse_command_line()`
    - `usage()`
    - `usage_short()`
    - `version()`
  - ly.server.options module
    - `Options`
      - `Options.set_variable()`
    - `ServerOptions`

## Submodules

## ly.slexer module

### slexer – Stateful Lexer

parses text, searching for tokens represented by a regular expression.

Only depends on the standard Python re module.

You need to create at least one subclass of Parser, and a subclass of Token for every type of text to search for. Then you list the token class names in the ‘items’ tuple of the Parser subclass definition.

Different contexts can be parsed by creating multiple Parser subclasses. A Parser searches for tokens using the list of Token classes. (Token is simply a subclass of str). Every Token subclass has the regular expression part to search for in its ‘rx’ class attribute.

You start parsing text by instantiating a State (you don’t need to subclass that) with the Parser subclass you want to parse the text with. Then you iterate over the generated tokens using the tokens(text) method of the State instance. You can use the tokens just as strings (e.g. if token == ‘text’…) but you can also test for the type of the token (e.g. if isinstance(token, Number)…). The tokens also carry a ‘pos’ and an ‘end’ attribute, specifying their position in the parsed text string.

A token may cause a different Parser to be entered, of the current Parser to be left, etc. This is done by implementing the update_state() method of the Token subclass. This method is called automatically when the Token is instantiated.

The State maintains the parsing state (the list of active Parser instances). A State can be frozen to be thawed later to resume parsing text starting in a particular context. A Fridge can be used to store and recover a state under a simple integer number.

How to use slexer:

    from slexer import Token, Parser, State

    # create token classes:
    class Word(Token):
        rx = r'\w+'

    class Number(Token):
        rx = r'\d+'

    class String(Token):
        pass

    class StringStart(String):
        rx = '"'
        def update_state(self, state):
            state.enter(PString())

    class StringEnd(String):
        rx = '"'
        def update_state(self, state):
            state.leave()

    # create parsers:
    class PTest(Parser):
        '''Looks for numbers, words and the double quote.'''
        items = (
            Number,
            Word,
            StringStart,
        )

    class PString(Parser):
        '''Returns String by default, quits at double quote.'''
        default = String
        items = (
            StringEnd,
        )

    s = State(PTest)
    for t in s.tokens(
        'een tekst met 7 woorden, '
        'een "tekst met 2 aanhalingstekens" '
        'en 2 of 3 nummers'):
        print(t.__class__, t)

Running the above code, the result is:

    <class '__main__.Word'> een
    <class '__main__.Word'> tekst
    <class '__main__.Word'> met
    <class '__main__.Number'> 7
    <class '__main__.Word'> woorden
    <class '__main__.Word'> een
    <class '__main__.StringStart'> "
    <class '__main__.String'> tekst met 2 aanhalingstekens
    <class '__main__.StringEnd'> "
    <class '__main__.Word'> en
    <class '__main__.Number'> 2
    <class '__main__.Word'> of
    <class '__main__.Number'> 3
    <class '__main__.Word'> nummers

class ly.slexer.FallthroughParser

  Bases: `Parser`

  Base class for parsers that ‘match’ instead of ‘search’ for a pattern.

  You can also implement the fallthrough() method to do something with the state if there is no match. The default is to leave the current parser. See Parser().

  fallthrough(state)

    Called when no match is returned by parse().

    This implementation leaves the current parser and returns None (causing the State to continue parsing).

  parse(text, pos)

    Match text at position pos and returns a Match Object or None.

class ly.slexer.Fridge(stateClass=<class 'ly.slexer.State'>)

  Bases: `object`

  Stores frozen States under an integer number.

  count()

    Returns the number of stored frozen states.

  freeze(state)

    Stores a state and return an identifying integer.

  thaw(num)

    Returns the state stored under the specified number.

class ly.slexer.Parser

  Bases: `object`

  Abstract base class for Parsers.

  When creating Parser subclasses, you should set the ‘items’ attribute to a tuple of Token subclasses. On class construction, a large regular expression pattern is built by combining the expressions from the ‘rx’ attributes of the Token subclasses.

  Additionally, you may implement the update_state() method which is called by the default implementation of update_state() in Token.

  default = None
  fallthrough(state)

    Called when no match is returned by parse().

    If this function returns True, the tokenizer stops parsing, assuming all text has been consumed. If this function returns False or None, it should alter the state (switch parsers) and parsing continues using the new Parser.

    The default implementation simply returns True.

  freeze()

    Return our instance values as a hashable tuple.

  items = ()
  parse(text, pos)

    Parse text from position pos and returns a Match Object or None.

  re_flags = 0
  classmethod thaw(attrs)
  token(match)

    Return a Token instance of the correct class.

    The match object is returned by the parse() method.

  update_state(state, token)

    Called by the default implementation of Token.update_state().

    Does nothing by default.

class ly.slexer.State(initialParserClass)

  Bases: `object`

  Maintains state while parsing text.

  You instantiate a State object with an initial parser class. Then you use tokens(text) to start parsing for tokens.

  The state is basically a list of Parser instances; the last one is the active one. The enter() and leave() methods respectively enter a new parser or leave the current parser.

  You can’t leave() the initial parser instance.

  depth()

    Return the number of parsers currently active (1 or more).

    You can use this e.g. to keep parsing until some context ends:

        tokens = state.tokens(text) # iterator
        depth = state.depth()
        for token in tokens:
            if state.depth() < depth:
                break
            # do something

  enter(parser)

    Enter a new parser.

    Note: ‘parser’ is an instantiated Parser subclass. Most times this method will be called from with the update_state() method of a Token subclass (or from a Parser subclass, which is also possible: the default implementation of Token.update_state() calls Parser.update_state(), which does nothing by default).

    E.g. in the Token subclass:

        def update_state(self, state):
            state.enter(SomeDifferentParser())

  follow(token)

    Act as if the token has been instantiated with the current state.

    You need this when you already have the parsed tokens, (e.g. cached or saved somehow) but want to know which parser created them.

    This method changes state according to the token. Basically it calls the update_state() method of the token instance, but it does some more work behind the scenes to ensure that the FallthroughParser type (see below) also is handled correctly.

  freeze()

    Return the current state as a tuple (hashable object).

  leave()

    Leave the current parser and pop back to the previous.

    The first parser (specified on instantiation) will never be left.

  parser()

    Return the currently active Parser instance.

  parsers()

    Return all active parsers, the most current one first.

  replace(parser)

    Replace the current parser with a new one.

    Somewhat equivalent to:

        state.leave()
        state.enter(SomeDifferentParser)

    But using this method you can also replace the first parser.

  classmethod thaw(frozen)

    Reproduce a State object from the frozen state argument.

  tokens(text, pos=0)

    Parse a text string using our state info.

    Yields Token instances. All tokens are a subclass of str and have a pos and an end attribute, describing their position in the original string. If the current parser defines a ‘default’ class attribute, it is the Token subclass to use for pieces of text that would otherwise be skipped.

class ly.slexer.Token(string, pos)

  Bases: `str`

  Represents a parsed piece of text.

  The subclass determines the type.

  You should put the regular expression string in the rx class attribute. In the rx string, you may not use named groups starting with “g_”.

  To add token types to a Parser class, list the token class in the items attribute of the Parser class.

  end
  pos
  rx = None
  classmethod test_match(match)

    Should return True if the match should indeed instantiate this class.

    This class method is only called if multiple Token classes in the Parser’s items list have the same rx attribute. This method is then called for every matching Token subclass until one returns True. That token is then instantiated. (The method is not called for the last class in the list that have the same rx attribute, and also not if there is only one class with that rx attribute.)

    The default implementation always returns True.

  update_state(state)

    Lets the token update the state, e.g. enter a different parser.

    This method is called by the State upon instantiation of the tokens.

    Don’t use it later on to have a State follow already instantiated Tokens because the FallthroughParser type can also change the state without generating a Token. Use State.follow() to have a State follow instantiated Tokens.

    The default implementation lets the Parser decide on state change.

## ly.document module

### DocumentBase and Document

Represents a LilyPond source document (the text contents).

The Document implementation keeps the document in a (unicode) text string, but you can inherit from the DocumentBase class to support other representations of the text content.

Modifying is preferably done inside a context (the with statement), e.g.:

    d = Document('some string')
    with d:
        d[5:5] = 'different '
    d.plaintext()  --> 'some different string'

Changes are applied when the context is exited, also the modified part of the document is re-tokenized. Changes may not overlap.

You may modify the document outside a context, in which case the document is re-tokenized immediately. This is much slower however when performing multiple changes after each other.

The tokens(block) method returns a tuple of tokens for the specified block. Depending on the implementation, a block describes a line in the LilyPond source document. It is not expected to have any methods, except that the ‘==’ operator is supported between two blocks, and returns True if both refer to the same line of text in the source document.

### Cursor

Defines a range or position in a Document.

### Runner

A Runner allows iterating back and forth over the tokens of a document.

### Source

Iterate over tokens in a (part of a) Document, with or without state.

class ly.document.Cursor(doc, start=0, end=None)

  Bases: `object`

  Defines a certain range (selection) in a Document.

  You may change the start and end attributes yourself. Both must be an integer, end may also be None, denoting the end of the document.

  As long as you keep a reference to the Cursor, its positions are updated when the document changes. When text is inserted at the start position, it remains the same. But when text is inserted at the end of a cursor, the end position moves along with the new text. E.g.:

      d = Document('hi there, folks!')
      c = Cursor(d, 8, 8)
      with d:
          d[8:8] = 'new text'
      c.start, c.end --> (8, 16)

  Many tools in the ly module use this object to describe (part of) a document.

  blocks()

    Iterate over the selected blocks.

    If there are multiple blocks and the cursor ends on the first position of the last selected block, that block is not included.

  property document
  end_block()

    Return the block the end attribute points at.

  has_selection()

    Return True when there is some text selected.

  lstrip(chars=None)

    Move start to the right, like Python’s lstrip() string method.

  rstrip(chars=None)

    Move end to the left, like Python’s lstrip() string method.

  select_all()

    Select all text.

  select_end_of_block()

    Move end to the end of the block.

  select_start_of_block()

    Move start to the start of the block.

  start_block()

    Return the block the start attribute points at.

  strip(chars=None)

    Strip chars from the selection, like Python’s strip() method.

  text()

    Convenience method to return the selected text.

  text_after()

    Return text after the cursor in it’s end block.

  text_before()

    Return text before the cursor in it’s start block.

class ly.document.Document(text='', mode=None)

  Bases: `DocumentBase`

  A plain text LilyPond source document that auto-updates the tokens.

  The modified attribute is set to True as soon as the document is changed, but the setplaintext() method sets it to False.

  apply_changes()

    Apply the changes and update the tokens.

  block(position)

    Return the text block at the specified character position.

  copy()

    Return a full copy of the document.

  index(block)

    Return the linenumber of the block (starting with 0).

  initial_state()

    Return the state at the beginning of the document.

  isvalid(block)

    Return True if the block is a valid block.

  classmethod load(filename, encoding='utf-8', mode=None)

    Load the document from a file, using the specified encoding and mode.

  mode()

    Return the mode (lilypond, html, etc). None means automatic mode.

  modified = False
  position(block)

    Return the position of the specified block.

  setmode(mode)

    Sets the mode to one of the ly.lex modes.

    Use None to auto-determine the mode.

  setplaintext(text)

    Set the text of the document, sets modified to False.

  state_end(block)

    Return the state at the end of the specified block.

  text(block)

    Return the text of the specified block.

  tokens(block)

    Return the tuple of tokens of the specified block.

class ly.document.DocumentBase

  Bases: `object`

  Abstract base class for Document instances.

  You should inherit the following methods:

  setplaintext __len__ __getitem__ block index position text tokens isvalid initial_state state_end apply_changes

  You may inherit (e.g. to get speed improvements):

  plaintext next_block previous_block blocks_forward blocks_backward state

  You may use the following attributes:

  filename (None) # can represent the filename of the document on disk encoding (None) # can represent the encoding of the document when reading/writing to disk

  apply_changes()

    Apply the changes and update the tokens.

  block(position)

    Return the text block at the specified character position.

    The text block itself has no methods, but it can be used as an argument to other methods of this class.

    (Blocks do have to support the ‘==’ operator.)

  blocks_backward(block)

    Iter backwards starting with the specified block.

  blocks_forward(block)

    Iter forward starting with the specified block.

  check_changes()

    Debugging method that checks for overlapping edits.

  encoding = None
  filename = None
  index(block)

    Return the linenumber of the block (starting with 0).

  initial_state()

    Return the state at the beginning of the document.

  isblank(block)

    Return True if the block is empty or blank.

  isvalid(block)

    Return True if the block is a valid block.

  next_block(block)

    Return the next block, which may be invalid.

  plaintext()

    The document contents as a plain text string.

  position(block)

    Return the position of the specified block.

  previous_block(block)

    Return the previous block, which may be invalid.

  setplaintext(text)

    Sets the document contents to the text string.

  size()

    Return the number of characters in the document.

  state(block)

    Return the state at the start of the specified block.

  state_end(block)

    Return the state at the end of the specified block.

  text(block)

    Return the text of the specified block.

  tokens(block)

    Return the tuple of tokens of the specified block.

    The pos and end attributes of every token point to the position of the token in the block.

  tokens_with_position(block)

    Return a tuple of tokens of the specified block.

    The pos and end attributes of every token point to the position in the Document, instead of to the position in the current block.

    This makes it easier to iterate over tokens and change the document.

  update_cursors()

    Updates the position of the registered Cursor instances.

class ly.document.Runner(doc, tokens_with_position=False)

  Bases: `object`

  Iterates back and forth over tokens.

  A Runner can stop anywhere and remembers its current token.

  classmethod at(cursor, after_token=False, tokens_with_position=False)

    Create and init from a Cursor.

    The Runner is positioned so that yielding forward starts with the first complete token after the cursor’s start position.

    Set after_token to True if you want to position the cursor after the token, so that it gets yielded when you go backward.

    If tokens_with_position is True, uses the tokens_with_position() method to get the tokens, else (by default), the tokens() method is used.

  backward()

    Yields tokens in backward direction across blocks.

  backward_line()

    Yields tokens in backward direction in the current block.

  copy()

    Return a new Runner at the current position.

  property document

    Return our Document.

  forward()

    Yields tokens in forward direction across blocks.

  forward_line()

    Yields tokens in forward direction in the current block.

  move_to_block(block, at_end=False)

    Positions the Runner at the start of the given text block.

    If at_end == True, the iterator is positioned past the end of the block.

  next(current_block=False)

    Return the next token or False if there is no more token. If current_block=True stop at the end of the current block.

  next_block(at_end=False)

    Go to the next block, positioning the cursor at the start by default.

    Returns False if there was no next block, else True.

  position()

    Returns the position of the current token.

  previous(current_block=False)

    Return the previous token or False if there is no more token. If current_block=True stop at the beginning of the current block.

  previous_block(at_end=True)

    Go to the previous block, positioning the cursor at the end by default.

    Returns False if there was no previous block, else True.

  set_position(position, after_token=False)

    Positions the Runner at the specified position.

    Set after_token to True if you want to position the cursor after the token, so that it gets yielded when you go backward.

  token()

    Re-returns the last yielded token.

class ly.document.Source(cursor, state=None, partial=1, tokens_with_position=False)

  Bases: `object`

  Helper iterator.

  Iterates over the (block, tokens) tuples from a Document (or a part thereof). Stores the current block in the block attribute and the tokens (which also is a generator) in the tokens attribute.

  Iterating over the source object itself just yields the tokens, while the block attribute contains the current block.

  You can also iterate over the tokens attribute, which will yield the remaining tokens of the current block and then stop.

  If you specify a state, the tokens will update the state. If you specify state = True, the state will be taken from the document.

  consume(iterable, position)

    Consumes iterable (supposed to be reading from us) until position.

    Returns the last token if that overlaps position.

  property document

    Return our Document.

  next()
  position(token)

    Returns the position of the token in the current block.

    If the iterator was instantiated with tokens_with_position == True, this position is the same as the token.pos attribute, and the current block does not matter. (In that case you’ll probably not use this method.)

  pushback(pushback=True)

    Yields the last yielded token again on the next request.

    This can be called multiple times, but only the last token will be yielded again. You can also undo a call to pushback() using pushback(False).

  token()

    Re-returns the last yielded token.

  until_parser_end()

    Yield the tokens until the current parser is quit.

    You can only use this method if you have a State enabled.

## ly.docinfo module

Harvest information from a ly.document.DocumentBase instance.

class ly.docinfo.DocInfo(doc)

  Bases: `object`

  Harvest information from a ly.document.DocumentBase instance.

  All tokens are saved in the tokens attribute as a tuple. Newline tokens are added between all lines. All corresponding classes are in the classes attribute as a tuple. This makes quick search and access possible.

  The tokens are requested from the document using the tokens_with_position() method, so you can always locate them back in the original document using their pos attribute.

  DocInfo does not update when the document changes, you should just instantiate a new one.

  complete()

    Return whether the document is probably complete and could be compilable.

  count_tokens(cls)

    Return the number of tokens that are (a subclass) of the specified class.

    If you only want the number of instances of the exact class (not a subclass of) you can use info.classes.count(cls), where info is a DocInfo instance.

  counted_tokens()

    Return a dictionary mapping classes to the number of instances of that class.

  definitions()

    The list of LilyPond identifiers the document defines.

  property document
  find(token=None, cls=None, pos=0, endpos=-1)

    Return the index of the first specified token and/or class after pos.

    If token is None, the cls should be specified. If cls is given, the token should be an instance of the specified class. If endpos is given, never searches beyond endpos. Returns -1 if the token is not found.

  find_all(token=None, cls=None, pos=0, endpos=-1)

    Yield all indices of the first specified token and/or class after pos.

    If token is None, the cls should be specified. If cls is given, the token should be an instance of the specified class. If endpos is given, never searches beyond endpos. Returns -1 if the token is not found.

  global_staff_size()

    The global-staff-size, if set, else None.

  has_output()

    Return True when the document probably generates output.

    I.e. has notes, rests, markup or other output-generating commands.

  include_args()

    The list of include command arguments.

  language()

    The pitch language, None if not set in the document.

  markup_definitions()

    The list of markup command definitions in the document.

  mode()

    Return the mode, e.g. “lilypond”.

  output_args()

    The list of arguments of constructs defining the name of output documents.

    This looks at the bookOutputName, bookOutputSuffix and define output-suffix commands.

    Every argument is a two tuple(type, argument) where type is either “suffix” or “name”.

  range(start=0, end=None)

    Return a new instance of the DocInfo class for the selected range.

    Only the tokens completely contained within the range start..end are added to the new instance. This can be used to perform fast searches on a subset of a document.

  scheme_load_args()

    The list of scheme (load) command arguments.

  token_hash()

    Return an integer hash for all non-whitespace and non-comment tokens.

    This hash does not change when only comments or whitespace are changed.

  version()

    Return the version_string() as a tuple of ints, e.g. (2, 16, 2).

  version_string()

    Return the version as a string, e.g. “2.19.8”.

    Looks for the version LilyPond command. The string is returned without quotes. Returns None if there was no version command found.

## ly.barcheck module

Add, check or remove bar checks in selected music.

class ly.barcheck.event

  Bases: `object`

  A limited event type at a certain time.

  append(node)

ly.barcheck.insert(cursor, music=None)

  Insert bar checks within the selected range.

ly.barcheck.remove(cursor)

  Remove bar checks from the selected music.

## ly.colorize module

Classes and functions to colorize (syntax-highlight) parsed source.

Highlighting is based on CSS properties and their values, although the Mapping object can map a token’s class to any object or value.

The Mapping object normally maps a token’s class basically to a CSS class and possibly a base CSS class. This way you can define base styles (e.g. string, comment, etc) and have specific classes (e.g. LilyPond string, Scheme comment) inherit from that base style. This CSS class is described by the css_class named tuple, with its three fields: mode, name, base. E.g. (‘lilypond’, ‘articulation’, ‘keyword’). The base field may be None.

The css classes are mapped to dictionaries of css properties, like {‘font-weight’: ‘bold’, ‘color’: ‘#4800ff’}, etc.

A scheme (a collection of styles) is simply a dictionary mapping the mode to a dictionary of CSS dictionaries. The base styles are in the [None] item of the scheme dictionary.

class ly.colorize.HtmlWriter

  Bases: `object`

  A do-it-all object to create syntax highlighted HTML.

  You can set the instance attributes to configure the behaviour in all details. Then call the html(cursor) method to get the HTML.

  bgcolor = None
  css_mapper = None
  css_scheme = {'html': {}, 'lilypond': {'articulation': {'color': '#ff8000', 'font-weight': 'bold'}, 'context': {'font-weight': 'bold'}, 'duration': {'color': '#008080'}, 'dynamic': {'color': '#ff8000', 'font-weight': 'bold'}, 'fingering': {'color': '#ff8000'}, 'grob': {'color': '#c000c0'}, 'lyricmode': {'color': '#006000'}, 'lyrictext': {'color': '#006000'}, 'markup': {'color': '#008000', 'font-weight': 'normal'}, 'slur': {'font-weight': 'bold'}, 'stringnumber': {'color': '#ff8000'}}, 'mup': {}, 'scheme': {}, 'texinfo': {}, None: {'comment': {'color': '#808080', 'font-style': 'italic'}, 'error': {'color': '#ff0000', 'text-decoration': 'underline', 'text-decoration-color': '#ff0000'}, 'escape': {'color': '#008080'}, 'function': {'color': '#0000c0', 'font-weight': 'bold'}, 'keyword': {'font-weight': 'bold'}, 'string': {'color': '#c00000'}, 'value': {'color': '#808000'}, 'variable': {'color': '#0000ff'}}}
  document_id = 'document'
  encoding = 'UTF-8'
  fgcolor = None
  full_html = True
  html(cursor)

    Return the output HTML.

  inline_style = False
  linenumbers_bgcolor = '#eeeeee'
  linenumbers_fgcolor = None
  linenumbers_id = 'linenumbers'
  number_lines = False
  set_wrapper_attribute(attr)

    Choose attribute name for wrapper tag

  set_wrapper_tag(tag)

    Define the tag to be used for wrapping the content

  stylesheet_ref = None
  title = ''
  wrapper_attribute = 'id'
  wrapper_tag = 'pre'

class ly.colorize.Mapper

  Bases: `dict`

  Maps token classes to arbitrary values, which can be highlighting styles.

  Mapper behaves like a dict, you set items with a token class as key to an arbitrary value.

  But getting items can be done using a token. The token class’s method resolution order is walked up and the value for the first available class found in the keys is returned. The class is also cached to speed up requests for other tokens.

ly.colorize.add_line_numbers(cursor, html, linenum_attrs=None, document_attrs=None)

  Combines the html (returned by html()) with the line numbers in a HTML table.

  The linenum_attrs are put in the <td> tag for the line numbers. The default value is: {“style”: “background: #eeeeee;”}. The document_attrs are put in the <td> tag for the document. The default is empty.

  By default, the id for the linenumbers <td> is set to “linenumbers”, and the id for the document <td> is set to “document”.

ly.colorize.css_attr(d)

  Return a dictionary with a ‘style’ key.

  The value is the style items in d formatted with css_item() joined with spaces. If d is empty, an empty dictionary is returned.

class ly.colorize.css_class(mode, name, base)

  Bases: `tuple`

  base

    Alias for field number 2

  mode

    Alias for field number 0

  name

    Alias for field number 1

ly.colorize.css_dict(css_style, scheme={'html': {}, 'lilypond': {'articulation': {'color': '#ff8000', 'font-weight': 'bold'}, 'context': {'font-weight': 'bold'}, 'duration': {'color': '#008080'}, 'dynamic': {'color': '#ff8000', 'font-weight': 'bold'}, 'fingering': {'color': '#ff8000'}, 'grob': {'color': '#c000c0'}, 'lyricmode': {'color': '#006000'}, 'lyrictext': {'color': '#006000'}, 'markup': {'color': '#008000', 'font-weight': 'normal'}, 'slur': {'font-weight': 'bold'}, 'stringnumber': {'color': '#ff8000'}}, 'mup': {}, 'scheme': {}, 'texinfo': {}, None: {'comment': {'color': '#808080', 'font-style': 'italic'}, 'error': {'color': '#ff0000', 'text-decoration': 'underline', 'text-decoration-color': '#ff0000'}, 'escape': {'color': '#008080'}, 'function': {'color': '#0000c0', 'font-weight': 'bold'}, 'keyword': {'font-weight': 'bold'}, 'string': {'color': '#c00000'}, 'value': {'color': '#808000'}, 'variable': {'color': '#0000ff'}}})

  Return the css properties dict for the style, taken from the scheme.

  This can be used for inline style attributes.

ly.colorize.css_group(selector, d)

  Return a “selector { items…}” part of a CSS stylesheet.

ly.colorize.css_item(i)

  Return “name: value;” where i = (name, value).

ly.colorize.css_mapper(mapping=None)

  Return a Mapper dict, mapping token classes to two CSS classes.

  By default the mapping returned by default_mapping() is used.

class ly.colorize.css_style_attribute_formatter(scheme={'html': {}, 'lilypond': {'articulation': {'color': '#ff8000', 'font-weight': 'bold'}, 'context': {'font-weight': 'bold'}, 'duration': {'color': '#008080'}, 'dynamic': {'color': '#ff8000', 'font-weight': 'bold'}, 'fingering': {'color': '#ff8000'}, 'grob': {'color': '#c000c0'}, 'lyricmode': {'color': '#006000'}, 'lyrictext': {'color': '#006000'}, 'markup': {'color': '#008000', 'font-weight': 'normal'}, 'slur': {'font-weight': 'bold'}, 'stringnumber': {'color': '#ff8000'}}, 'mup': {}, 'scheme': {}, 'texinfo': {}, None: {'comment': {'color': '#808080', 'font-style': 'italic'}, 'error': {'color': '#ff0000', 'text-decoration': 'underline', 'text-decoration-color': '#ff0000'}, 'escape': {'color': '#008080'}, 'function': {'color': '#0000c0', 'font-weight': 'bold'}, 'keyword': {'font-weight': 'bold'}, 'string': {'color': '#c00000'}, 'value': {'color': '#808000'}, 'variable': {'color': '#0000ff'}}})

  Bases: `object`

  Return the inline style attribute for a specified style.

ly.colorize.default_mapping()

  Return a good default mapping from token class(es) to style and default style, per group.

ly.colorize.format_css_span_class(css_style)

  Return a string like ‘class=”mode-style base”’ for the specified style.

ly.colorize.format_html_document(body, title='', stylesheet=None, stylesheet_ref=None, encoding='UTF-8')

  Return a complete HTML document.

  The body is put inside body tags unchanged. The title is html-escaped. If stylesheet_ref is given, it is put as a <link> reference in the HTML; if stylesheet is given, it is put verbatim in a <style> section in the HTML. The encoding is set in the meta http-equiv field, but the returned HTML is in normal Python unicode (python2) or str (python3) format, you should encode it yourself in the same encoding (by default utf-8) when writing it to a file.

ly.colorize.format_stylesheet(scheme={'html': {}, 'lilypond': {'articulation': {'color': '#ff8000', 'font-weight': 'bold'}, 'context': {'font-weight': 'bold'}, 'duration': {'color': '#008080'}, 'dynamic': {'color': '#ff8000', 'font-weight': 'bold'}, 'fingering': {'color': '#ff8000'}, 'grob': {'color': '#c000c0'}, 'lyricmode': {'color': '#006000'}, 'lyrictext': {'color': '#006000'}, 'markup': {'color': '#008000', 'font-weight': 'normal'}, 'slur': {'font-weight': 'bold'}, 'stringnumber': {'color': '#ff8000'}}, 'mup': {}, 'scheme': {}, 'texinfo': {}, None: {'comment': {'color': '#808080', 'font-style': 'italic'}, 'error': {'color': '#ff0000', 'text-decoration': 'underline', 'text-decoration-color': '#ff0000'}, 'escape': {'color': '#008080'}, 'function': {'color': '#0000c0', 'font-weight': 'bold'}, 'keyword': {'font-weight': 'bold'}, 'string': {'color': '#c00000'}, 'value': {'color': '#808000'}, 'variable': {'color': '#0000ff'}}})

  Return a formatted stylesheet for the stylesheet scheme dictionary.

ly.colorize.get_tokens(cursor)

  Return the list of tokens for the cursor.

  Tokens that are partially inside the cursor’s selection are re-created so that they fall exactly within the selection.

  This can be used to convert a highlighted part of a document to e.g. HTML.

ly.colorize.html(cursor, mapper, span=<function format_css_span_class>)

  Return a HTML string with the tokens wrapped in <span class=> elements.

  The span argument is a function returning an attribute for the <span> tag for the specified style. By default the format_css_span_class() function is used, that returns a ‘class=”group style base”’ string. You’ll want to wrap the HTML inside <pre> tokens and add a CSS stylesheet.

ly.colorize.html_escape(text)

  Escape &, < and >.

ly.colorize.html_escape_attr(text)

  Escape &, “, < and >.

ly.colorize.html_format_attrs(d)

  Format the attributes dict as a string.

  The attributes are escaped correctly. A space is prepended for every assignment.

ly.colorize.map_tokens(cursor, mapper)

  Yield a two-tuple(token, style) for every token.

  The style is what mapper[token] returns. Style may be None, which also happens with unparsed (not-tokenized) text.

ly.colorize.melt_mapped_tokens(mapped_tokens)

  Melt adjacent tokens with the same mapping together.

class ly.colorize.style(name, base, classes)

  Bases: `tuple`

  base

    Alias for field number 1

  classes

    Alias for field number 2

  name

    Alias for field number 0

## ly.cursortools module

Routines manipulating ly.document.Cursor instances.

ly.cursortools.find_indent(iterable)

  Yield (token, is_indent, nest) for every occurring indent/dedent token.

  The tokens are yielded from the specified iterable.

ly.cursortools.select_block(cursor)

  Try to select a meaningful block.

  Searches backwards for an indenting token, then selects up to the corresponding dedenting token. If needed searches an extra level back to always extend the selection. Returns True if the cursor’s selection has changed.

## ly.dom module

This module is deprecated. When ly.music is able to generate LilyPond code from scratch, this module will be removed.

LilyPond DOM

(c) 2008-2011 Wilbert Berendsen License: GPL.

A simple Document Object Model for LilyPond documents.

The purpose is to easily build a LilyPond document with good syntax, not to fully understand all features LilyPond supports. (This DOM does not enforce a legal LilyPond file.)

All elements of a LilyPond document inherit Node.

Note: elements keep a weak reference to their parent.

class ly.dom.AddDuration

  Bases: `object`

  Mixin to add a duration (as child).

  ly(printer)

class ly.dom.AddLyrics(parent=None)

  Bases: `InputLyrics`

  after = 1
  before = 1
  may_remove_brackets = False
  name = 'addlyrics'

class ly.dom.Assignment(name=None, parent=None, valueObj=None)

  Bases: `Container`

  A varname = value construct with it’s value as its first child The name can be a string or a Reference object: so that everywhere where this varname is referenced, the name is the same.

  after = 1
  before = 1
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

  setValue(obj)
  value()

class ly.dom.BlankLine(parent=None)

  Bases: `Newline`

  A blank line.

  before = 1

class ly.dom.Block(parent=None)

  Bases: `Container`

  A vertical container type that puts everything on a new line.

  after = 1
  before = 1
  defaultSpace = '\n'

class ly.dom.BlockComment(text='', parent=None)

  Bases: `Comment`

  A block comment between %{ and %}

  property after

    int([x]) -> integer int(x, base=10) -> integer

    Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

    If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

  property before

    int([x]) -> integer int(x, base=10) -> integer

    Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

    If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Book(parent=None)

  Bases: `Section`

  name = 'book'

class ly.dom.BookPart(parent=None)

  Bases: `Section`

  name = 'bookpart'

class ly.dom.ChoirStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Chord(parent=None)

  Bases: `Container`

  A chord containing one of more Pitches and optionally one Duration. This is a bit of a hack, awaiting real music object support.

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.ChordMode(parent=None)

  Bases: `InputMode`

  name = 'chordmode'

class ly.dom.ChordNames(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Clef(clef, parent=None)

  Bases: `Leaf`

  A clef.

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Command(name, parent=None)

  Bases: `Statement`

  Use this to create a LilyPond command supplying the name (or a Reference) when instantiating.

class ly.dom.CommandEnclosed(name, parent=None)

  Bases: `StatementEnclosed`

  Use this to print LilyPond commands that have a single bracket-enclosed list of arguments. The command name is supplied to the constructor.

class ly.dom.Comment(text='', parent=None)

  Bases: `Text`

  A LilyPond comment at the end of a line

  after = 1
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Container(parent=None)

  Bases: `LyNode`

  A node that concatenates its children on output

  property after

    int([x]) -> integer int(x, base=10) -> integer

    Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

    If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

  property before

    int([x]) -> integer int(x, base=10) -> integer

    Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

    If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

  defaultSpace = ' '
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Context(contextName='', parent=None)

  Bases: `HandleVars`, `Section`

  A context section for use inside Layout or Midi sections.

  name = 'context'

class ly.dom.ContextName(text='', parent=None)

  Bases: `Text`

  Used to print a context name, like Score.

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.ContextProperty(prop, context=None, parent=None)

  Bases: `Leaf`

  A Context.property or Context.layoutObject construct. Call e.g. ContextProperty(‘aDueText’, ‘Staff’) to get ‘Staff.aDueText’.

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.ContextType(cid=None, new=True, parent=None)

  Bases: `Container`

  new or context Staff = ‘bla’ with { } << music >>

  A with (With) element is added automatically as the first child as soon as you use our convenience methods that manipulate the variables in with. If the with element is empty, it does not print anything. You should add one other music object to this.

  addInstrumentNameEngraverIfNecessary()

    Adds the Instrument_name_engraver to the node if it would need it to print instrument names.

  after = 1
  before = 1
  ctype = None
  getWith()

    Gets the attached with clause. Creates it if not there.

  isAtom = True
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.CueVoice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Devnull(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Document(parent=None)

  Bases: `Container`

  A container type that puts everything on a new line. To be used as a full LilyPond document.

  after = 1
  defaultSpace = '\n'

class ly.dom.DrumMode(parent=None)

  Bases: `InputMode`

  name = 'drummode'

class ly.dom.DrumStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.DrumVoice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Duration(dur, dots=0, factor=1, parent=None)

  Bases: `Leaf`

  A duration with duration (in logarithmic form): (-2 … 8), where -2 = longa, -1 = breve, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16, etc, dots (number of dots), factor (Fraction giving the scaling of the duration).

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Dynamics(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Enclosed(parent=None)

  Bases: `Container`

  Encloses all children between brackets: { … } If may_remove_brackets is True in subclasses, the brackets are removed if there is only one child and that child is an atom (i.e. a single LilyPond expression.

  after = 0
  before = 0
  isAtom = True
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

  may_remove_brackets = False
  post = '}'
  pre = '{'

class ly.dom.FigureMode(parent=None)

  Bases: `InputMode`

  name = 'figuremode'

class ly.dom.FiguredBass(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.FretBoards(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Global(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.GrandStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.GregorianTranscriptionStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.GregorianTranscriptionVoice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.HandleVars

  Bases: `object`

  A powerful mixin class to facilitate handling unique variable assignments inside a Container more. E.g.: >>> h = Header() >>> h[‘composer’] = “Johann Sebastian Bach” creates a subnode (by default Assignment) with the name ‘composer’, and that node again gets an autogenerated subnode of type QuotedString (if the argument wasn’t already a Node).

  childClass

    alias of `Assignment`

  ifbasestring()

    Ensure that the method is only called for basestring objects. Otherwise the same method from the super class is called.

  importNode(obj)

    Try to interpret the object and transform it into a Node object of the right species.

class ly.dom.Header(parent=None)

  Bases: `HandleVars`, `Section`

  name = 'header'

class ly.dom.Identifier(name=None, parent=None)

  Bases: `Leaf`

  An identifier, prints as name. Name may be a string or a Reference object.

  isAtom = True
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Include(text='', parent=None)

  Bases: `Line`

  a LilyPond include statement

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.InnerChoirStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.InnerStaffGroup(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.InputChords(parent=None)

  Bases: `ChordMode`

  name = 'chords'

class ly.dom.InputDrums(parent=None)

  Bases: `DrumMode`

  name = 'drums'

class ly.dom.InputFigures(parent=None)

  Bases: `FigureMode`

  name = 'figures'

class ly.dom.InputLyrics(parent=None)

  Bases: `LyricMode`

  name = 'lyrics'

class ly.dom.InputMode(parent=None)

  Bases: `StatementEnclosed`

  The abstract base class for input modes such as lyricmode/lyrics, chordmode/chords etc.

class ly.dom.InputNotes(parent=None)

  Bases: `NoteMode`

  name = 'notes'

class ly.dom.KeySignature(note=0, alter=0, mode='major', parent=None)

  Bases: `Leaf`

  A key signature expression, like:

  key c major The pitch should be given in the arguments note and alter and is written out in the document’s language.

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Layout(parent=None)

  Bases: `HandleVars`, `Section`

  name = 'layout'

class ly.dom.Leaf(parent=None)

  Bases: `LyNode`

  A leaf node without children

class ly.dom.Line(text='', parent=None)

  Bases: `Text`

  A text node that claims its own line.

  after = 1
  before = 1

class ly.dom.LineComment(text='', parent=None)

  Bases: `Comment`

  A LilyPond comment that takes a full line

  before = 1

class ly.dom.LyNode(parent=None)

  Bases: `WeakNode`

  Base class for LilyPond objects, based on Node, which takes care of the tree structure.

  after = 0
  before = 0
  concat(other)

    Returns a string with newlines to concat this node to another one. If zero newlines are requested, an empty string is returned.

  isAtom = False
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.LyricMode(parent=None)

  Bases: `InputMode`

  name = 'lyricmode'

class ly.dom.Lyrics(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.LyricsTo(cid, parent=None)

  Bases: `LyricMode`

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

  name = 'lyricsto'

class ly.dom.Mark(parent=None)

  Bases: `Statement`

  The mark command.

  name = 'mark'

class ly.dom.Markup(parent=None)

  Bases: `StatementEnclosed`

  The markup command. You can add many children, in that case Markup automatically prints { and } around them.

  name = 'markup'

class ly.dom.MarkupCommand(name, parent=None)

  Bases: `Command`

  A markup command with more or no arguments, that does not auto-enclose its arguments. Useful for commands like note-by-number or hspace.

  You must supply the name. Its arguments are its children. If one argument can be a markup list, use a Enclosed() construct for that.

class ly.dom.MarkupEnclosed(name, parent=None)

  Bases: `CommandEnclosed`

  A markup that auto-encloses all its arguments, like ‘italic’, ‘bold’ etc. You must supply the name.

class ly.dom.MensuralStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.MensuralVoice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Midi(parent=None)

  Bases: `HandleVars`, `Section`

  name = 'midi'

class ly.dom.Named

  Bases: `object`

  Mixin to print a name before the contents of the container. format() is called on the self.name attribute, so it may also be a Reference.

  ly(printer)
  name = ''

class ly.dom.Newline(parent=None)

  Bases: `LyNode`

  A newline.

  after = 1

class ly.dom.NoteMode(parent=None)

  Bases: `InputMode`

  name = 'notemode'

class ly.dom.NoteNames(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Paper(parent=None)

  Bases: `HandleVars`, `Section`

  name = 'paper'

class ly.dom.Partial(dur, dots=0, factor=1, parent=None)

  Bases: `Named`, `Duration`

  partial <duration> You should add a Duration element

  after = 1
  before = 1
  name = 'partial'

class ly.dom.PianoStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Pitch(octave=0, note=0, alter=0, parent=None)

  Bases: `Leaf`

  A pitch with octave, note, alter. octave is specified by an integer, zero for the octave containing middle C. note is a number from 0 to 6, with 0 corresponding to pitch C and 6 corresponding to pitch B. alter is the number of whole tones for alteration (can be int or Fraction)

  ly(printer)

    Print the pitch in the preferred language.

class ly.dom.Printer

  Bases: `object`

  Performs certain operations on behalf of a LyNode tree, like quoting strings or translating pitch names, etc.

  indent(node)

    Return a formatted printout of node (and its children)

  indentGen(node, startIndent=0)

    A generator that walks on the output of the given node, and returns properly indented LilyPond code.

  primary_quote_left = '‘'
  primary_quote_right = '’'
  quoteString(text)
  secondary_quote_left = '“'
  secondary_quote_right = '”'

class ly.dom.QuotedString(text='', parent=None)

  Bases: `Text`

  A string that is output inside double quotes.

  isAtom = True
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Reference(name='')

  Bases: `object`

  A simple object that keeps a name, to use as a (context) identifier. Set the name attribute to the name you want to display, and on all places in the document the name will show up.

class ly.dom.Relative(parent=None)

  Bases: `Statement`

  relative <pitch> music

  You should add a Pitch (optionally) and another music object, e.g. Sim or Seq, etc.

  name = 'relative'

class ly.dom.RhythmicStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Scheme(text='', parent=None)

  Bases: `Text`

  A Scheme expression, without the extra # prepended

  isAtom = True
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.SchemeLily(parent=None)

  Bases: `Enclosed`

  A LilyPond expression between #{ #} (inside scheme)

  post = '#}'
  pre = '#{'

class ly.dom.SchemeList(parent=None)

  Bases: `Enclosed`

  A list of items enclosed in parentheses

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

  post = ')'
  pre = '('

class ly.dom.Score(parent=None)

  Bases: `Section`

  name = 'score'

class ly.dom.ScoreContext(cid=None, new=True, parent=None)

  Bases: `ContextType`

  Represents the Score context in LilyPond, but the name would collide with the Score class that represents score { } constructs.

  Because the latter is used more often, use ScoreContext to get new Score etc.

  ctype = 'Score'

class ly.dom.Section(parent=None)

  Bases: `StatementEnclosed`

  Very much like a Statement. Use as base class for book { }, score { } etc. By default never removes the brackets and always starts on a new line.

  after = 1
  before = 1
  may_remove_brackets = False

class ly.dom.Seq(parent=None)

  Bases: `Enclosed`

  An SequentialMusic expression between { }

  post = '}'
  pre = '{'

class ly.dom.Seqr(parent=None)

  Bases: `Seq`

  may_remove_brackets = True

class ly.dom.Sim(parent=None)

  Bases: `Enclosed`

  An SimultaneousMusic expression between << >>

  post = '>>'
  pre = '<<'

class ly.dom.Simr(parent=None)

  Bases: `Sim`

  may_remove_brackets = True

class ly.dom.Staff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.StaffGroup(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Statement(parent=None)

  Bases: `Named`, `Container`

  Base class for statements with arguments. The statement is read in the name attribute, the arguments are the children.

  before = 0
  isAtom = True

class ly.dom.StatementEnclosed(parent=None)

  Bases: `Named`, `Enclosed`

  Base class for LilyPond commands that have a single bracket-enclosed list of arguments.

  may_remove_brackets = True

class ly.dom.TabStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.TabVoice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Tempo(duration, value, parent=None)

  Bases: `Container`

  A tempo setting, like: tempo 4 = 100 May have a child markup or quoted string.

  after = 1
  before = 1
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Text(text='', parent=None)

  Bases: `Leaf`

  A leaf node with arbitrary text

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.TextDur(text='', parent=None)

  Bases: `AddDuration`, `Text`

  A text note with an optional duration as child.

class ly.dom.TimeSignature(num, beat, parent=None)

  Bases: `Leaf`

  A time signature, like: time 4/4

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Transposition(parent=None)

  Bases: `Statement`

  transposition <pitch> You should add a Pitch.

  name = 'transposition'

class ly.dom.UserContext(ctype, cid=None, new=True, parent=None)

  Bases: `ContextType`

  Represents a context the user creates. e.g. new MyStaff = cid << music >>

class ly.dom.VaticanaStaff(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.VaticanaVoice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.Version(text='', parent=None)

  Bases: `Line`

  a LilyPond version instruction

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.Voice(cid=None, new=True, parent=None)

  Bases: `ContextType`

class ly.dom.VoiceSeparator(parent=None)

  Bases: `Leaf`

  A Voice Separator: \

  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

class ly.dom.With(parent=None)

  Bases: `HandleVars`, `Section`

  If this item has no children, it prints nothing.

  after = 0
  before = 0
  ly(printer)

    Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc.

  name = 'with'

## ly.duration module

LilyPond information and logic concerning durations

ly.duration.base_scaling(tokens)

  Return (base, scaling) as two Fractions for the list of tokens.

ly.duration.base_scaling_string(duration)

  Return (base, scaling) as two Fractions for the specified string.

ly.duration.format_fraction(value)

  Format the value as “5/1” etc.

ly.duration.fraction(tokens)

  Return the duration of the Duration tokens as a Fraction.

ly.duration.fraction_string(duration)

  Return the duration of the specified string as a Fraction.

ly.duration.tostring(dur, dots=0, factor=1)

  Returns the LilyPond string representation of a given logarithmic duration.

  Supports values from -3 up to and including 11. -2 = ‘longa’, 0 = ‘1’ (whole note), etc.

  Adds the number of dots (defaults to 0) and the fraction factor if given.

## ly.etreeutil module

Utility functions for use with xml.etree.ElementTree.

ly.etreeutil.indent(elem, indent_string=' ', level=0)

  Indent the XML in element.

  Text content that is already non-whitespace is not changed.

ly.etreeutil.isblank(s)

  Return True if s is empty or whitespace only.

## ly.indent module

Indent and auto-indent.

class ly.indent.Indenter

  Bases: `object`

  compute_indent(document, block)

    Return the indent the specified block should have.

    Returns False if the block is not indentable, e.g. when it is part of a multiline string.

    This method is used to determine the indent of one line, and just looks to previous lines, copying the indent of the line where the current indent depth starts, and/or adding a level of indent or alignment space.

    Use this method only for one line or the first of a group you’re indenting.

  decrease_indent(cursor)

    Manually remove one level of indent from all lines of cursor.

  get_indent(document, block)

    Return the indent the block currently has.

    Returns False if the block is not indentable, e.g. when it is part of a multiline string.

  increase_indent(cursor)

    Manually add indent to all lines of cursor.

  indent(cursor, indent_blank_lines=False)

    Indent all lines in the cursor’s range.

    If indent_blank_lines is True, the indent of blank lines is made larger if necessary. If False (the default), the indent of blank lines if not changed if it is shorter than it should be.

  indent_tabs = False
  indent_width = 2

class ly.indent.Line(document, block)

  Bases: `object`

  Brings together all relevant information about a line (block).

  is_special_scheme_keyword(token)

    Return True if token is a special Scheme word like “define”, etc.

    The tokens in the list below and those that start with “def”, like “define”, do not follow the standard Scheme indentation patterns.

    The list below and the “def” rule are from GNU Emacs source code, which sets the standard for GNU Guile Scheme indentation. See: emacs/lisp/progmodes/scheme.el See also: http://community.schemewiki.org/?scheme-style

## ly.node module

The Node class.

(c) 2008-2011 Wilbert Berendsen License: GPL.

This module contains the Node class that can be used as a simple DOM (Document Object Model) for building a tree structure.

A Node has children with list-like access methods and keeps also a reference to its parent. A Node can have one parent; appending a Node to another Node causes it to be removed from its parent node (if any).

To iterate over the children of a Node:

    for n in node:
        do_something(n)

To get the list of children of a Node:

    children = list(node)

Of course you can get the children directly using:

    child = node[3]

You should inherit from Node to make meaningful tree node types, e.g. to add custom attributes or multiple sub-types.

A WeakNode class is provided as well, which uses a weak reference to the parent, so that no cyclic references are created which might improve garbage collection.

class ly.node.Node(parent=None)

  Bases: `object`

  A list-like class to build tree structures with.

  ancestors()

    Climb the tree up over the parents.

  append(node)

    Append a node to the current node.

    It will be reparented, that means it will be removed from it’s former parent if it had one.

  backward()

    Iterate (backwards) over the preceding siblings.

  clear()

    Remove all children.

  copy()

    Return a deep copy of the node and its children

  descendants(depth=-1)

    Yield all the descendants, in tree order. Same as iter_depth().

  dump()

    Return a string representation of the tree.

  extend(iterable)

    Append every Node from iterable.

  find(cls, depth=-1)

    Yield all descendants if they are an instance of cls.

    cls may also be a tuple of classes. This method uses iter_depth().

  find_child(cls, depth=-1)

    Return the first descendant that’s an instance of cls.

    cls may also be a tuple of classes. This method uses iter_rings().

  find_children(cls, depth=-1)

    Yield all descendants if they are an instance of cls.

    cls may also be a tuple of classes. This method uses iter_rings().

  find_parent(cls)

    Find an ancestor that’s an instance of the given class.

    cls may also be a tuple of classes.

  forward()

    Iterate over the following siblings.

  index(node)

    Return the index of the given child node.

  insert(index, node)

    Insert a node at the specified index.

  insert_before(other, node)

    Insert a node before the other node.

  is_descendant_of(parent)

    Return True if self is a descendant of parent, else False.

  iter_depth(depth=-1)

    Iterate over all the children, and their children, etc.

    Set depth to restrict the search to a certain depth, -1 is unrestricted.

  iter_rings(depth=-1)

    Iterate over the children in rings, depth last.

    This method returns the closest descendants first. Set depth to restrict the search to a certain depth, -1 is unrestricted.

  next_sibling()

    Return the sibling object just after us in our parents list.

    Returns None if this is the last child, or if we have no parent.

  parent()

    The parent, or None if the node has no parent.

  previous_sibling()

    Return the sibling object just before us in our parents list.

    Returns None if this is the first child, or if we have no parent.

  remove(node)

    Remove the given child node.

  replace(old, new)

    Replace a child node with another node.

  sort(key=None, reverse=False)

    Sorts the children, optionally using the key function.

    Using a key function is recommended, or you must add comparison methods to your Node subclass.

  toplevel()

    Return the toplevel parent Node of this node.

  unlink()

    Remove all children and unlink() them as well.

class ly.node.WeakNode(parent=None)

  Bases: `Node`

  A Node type using a weak reference to the parent.

  parent()

    The parent, or None if the node has no parent.

## ly.reformat module

Formatting tools to improve the readability of a ly.document.Document without changing the semantic meaning of the LilyPond source.

Basically the tools only change whitespace to make the source-code more readable.

See also ly.indent.

ly.reformat.break_indenters(cursor)

  Add newlines around indent and dedent tokens where needed.

  If there is stuff after a { or << (that’s not closed on the same line) it is put on a new line, and if there if stuff before a } or >>, the } or >> is put on a new line.

  It is necessary to run the indenter again over the same part of the document, as it will look garbled with the added newlines.

ly.reformat.move_long_comments(cursor)

  Move line comments with more than 2 comment characters to column 0.

ly.reformat.reformat(cursor, indenter)

  A do-it-all function improving the LilyPond source formatting.

ly.reformat.remove_trailing_whitespace(cursor)

  Removes whitespace from all lines in the cursor’s range.

## ly.rhythm module

Implementation of the tools to edit durations of selected music.

Durations are represented simply by lists of ly.lex.lilypond.Duration tokens.

All functions expect a ly.document.Cursor with the selected range.

class ly.rhythm.music_item(tokens, dur_tokens, may_remove, insert_pos, pos, end)

  Bases: `tuple`

  dur_tokens

    Alias for field number 1

  end

    Alias for field number 5

  insert_pos

    Alias for field number 3

  may_remove

    Alias for field number 2

  pos

    Alias for field number 4

  tokens

    Alias for field number 0

ly.rhythm.music_items(cursor, command=False, chord=False, partial=1)

  Yield music_item instances describing rests, skips or pitches.

  cursor is a ly.document.Cursor instance.

  The following keyword arguments can be used:

  - command: whether to allow pitches in \relative, \transpose, etc.

  - chord: whether to allow pitches inside chords.

  - partial: ly.document.INSIDE (default), PARTIAL or OUTSIDE. See the documentation of ly.document.Source.__init__().

ly.rhythm.music_tokens(source, command=False, chord=False)

  DEPRECATED. Yield lists of tokens describing rests, skips or pitches.

  source is a ly.document.Source instance following the state.

  The following keyword arguments can be used:

  - command: whether to allow pitches in \relative, \transpose, etc.

  - chord: whether to allow pitches inside chords.

  This function is deprecated and will be removed. You should use music_items() instead.

ly.rhythm.preceding_duration(cursor)

  Return a preceding duration before the cursor, or an empty list.

ly.rhythm.remove_dups(iterable)

  Change reoccurring strings to ‘’ in iterable.

ly.rhythm.rhythm_dot(cursor)

  Add a dot to all durations.

ly.rhythm.rhythm_double(cursor)

  Doubles all duration values.

ly.rhythm.rhythm_explicit(cursor)

  Make all durations explicit.

ly.rhythm.rhythm_extract(cursor)

  Return a list of the durations from the cursor’s range.

ly.rhythm.rhythm_halve(cursor)

  Halves all duration values.

ly.rhythm.rhythm_implicit(cursor)

  Remove reoccurring durations.

ly.rhythm.rhythm_implicit_per_line(cursor)

  Remove reoccurring durations, but always write one on a new line.

ly.rhythm.rhythm_overwrite(cursor, durations)

  Apply a list of durations to the cursor’s range.

  The durations list looks like [“4”, “8”, “”, “16.”,] etc.

ly.rhythm.rhythm_remove(cursor)

  Remove all durations.

ly.rhythm.rhythm_remove_fraction_scaling(cursor)

  Remove the scaling containing fractions (like `*1/3`) from all durations.

ly.rhythm.rhythm_remove_scaling(cursor)

  Remove the scaling (like `*3`, `*1/3`) from all durations.

ly.rhythm.rhythm_undot(cursor)

  Remove one dot from all durations.

## ly.util module

Utility functions.

ly.util.int2letter(number, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ')

  Converts an integer to one or more letters.

  E.g. 1 -> A, 2 -> B, … 26 -> Z, 27 -> AA, etc. Zero returns the empty string.

  chars is the string to pick characters from, defaulting to string.ascii_uppercase.

ly.util.int2roman(n)

  Convert an integer value to a roman number string.

  E.g. 1 -> “I”, 12 -> “XII”, 2015 -> “MMXV”

  n has to be > 1.

ly.util.int2text(number)

  Converts an integer to the English language name of that integer.

  E.g. converts 1 to “One”. Supports numbers 0 to 999999. This can be used in LilyPond identifiers (that do not support digits).

ly.util.mkid(*args)

  Makes a lower-camel-case identifier of the strings in args.

  All strings are concatenated with the first character of every string uppercased, except for the first character, which is lowercased.

  Examples:

      mkid("Violin") ==> "violin"
      mkid("soprano", "verse") ==> "sopranoVerse"
      mkid("scoreOne", "choirII") ==> "scoreOneChoirII"

## ly.words module

LilyPond reserved words for auto completion and highlighting.