ReducedLyParser

class lilypondparsertools.ReducedLyParser(debug=False)

Parses the “reduced-ly” syntax, a modified subset of LilyPond syntax.

>>> parser = lilypondparsertools.ReducedLyParser()

Understands LilyPond-like representation of notes, chords and rests:

>>> string = "c'4 r8. <b d' fs'>16"
>>> result = parser(string)
>>> print(format(result))
{
    c'4
    r8.
    <b d' fs'>16
}

Also parses bare duration as notes on middle-C, and negative bare durations as rests:

>>> string = '4 -8 16. -32'
>>> result = parser(string)
>>> print(format(result))
{
    c'4
    r8
    c'16.
    r32
}

Note that the leaf syntax is greedy, and therefore duration specifiers following pitch specifiers will be treated as part of the same expression. The following produces 2 leaves, rather than 3:

>>> string = "4 d' 4"
>>> result = parser(string)
>>> print(format(result))
{
    c'4
    d'4
}

Understands LilyPond-like default durations:

>>> string = "c'4 d' e' f'"
>>> result = parser(string)
>>> print(format(result))
{
    c'4
    d'4
    e'4
    f'4
}

Also understands various types of container specifications.

Can create arbitrarily nested tuplets:

>>> string = "2/3 { 4 4 3/5 { 8 8 8 } }"
>>> result = parser(string)
>>> print(format(result))
\tweak edge-height #'(0.7 . 0)
\times 2/3 {
    c'4
    c'4
    \tweak text #tuplet-number::calc-fraction-text
    \tweak edge-height #'(0.7 . 0)
    \times 3/5 {
        c'8
        c'8
        c'8
    }
}

Can also create empty FixedDurationContainers:

>>> string = '{1/4} {3/4}'
>>> result = parser(string)
>>> for x in result: x
...
FixedDurationContainer(Duration(1, 4), [])
FixedDurationContainer(Duration(3, 4), [])

Can create measures too:

>>> string = '| 4/4 4 4 4 4 || 3/8 8 8 8 |'
>>> result = parser(string)
>>> for x in result: x
...
Measure((4, 4), "c'4 c'4 c'4 c'4")
Measure((3, 8), "c'8 c'8 c'8")

Finally, understands ties, slurs and beams:

>>> string = 'c16 [ ( d ~ d ) f ]'
>>> result = parser(string)
>>> print(format(result))
{
    c16 [ (
    d16 ~
    d16 )
    f16 ]
}

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.Parser.Parser" [color=1, group=0, label=Parser, shape=oval, style=bold]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.Parser.Parser"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_lilypondparsertools { graph [label=lilypondparsertools]; "abjad.tools.lilypondparsertools.ReducedLyParser.ReducedLyParser" [color=black, fontcolor=white, group=2, label=<<B>ReducedLyParser</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.Parser.Parser" -> "abjad.tools.lilypondparsertools.ReducedLyParser.ReducedLyParser"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

debug Gets debug boolean of reduced ly parser.
lexer The parser’s PLY Lexer instance.
lexer_rules_object Lexer rules object of reduced ly parser.
logger The parser’s Logger instance.
logger_path The output path for the parser’s logfile.
output_path The output path for files associated with the parser.
p_apostrophes__APOSTROPHE(p) apostrophes : APOSTROPHE
p_apostrophes__apostrophes__APOSTROPHE(p) apostrophes : apostrophes APOSTROPHE
p_beam__BRACKET_L(p) beam : BRACKET_L
p_beam__BRACKET_R(p) beam : BRACKET_R
p_chord_body__chord_pitches(p) chord_body : chord_pitches
p_chord_body__chord_pitches__positive_leaf_duration(p) chord_body : chord_pitches positive_leaf_duration
p_chord_pitches__CARAT_L__pitches__CARAT_R(p) chord_pitches : CARAT_L pitches CARAT_R
p_commas__COMMA(p) commas : COMMA
p_commas__commas__commas(p) commas : commas COMMA
p_component__container(p) component : container
p_component__fixed_duration_container(p) component : fixed_duration_container
p_component__leaf(p) component : leaf
p_component__tuplet(p) component : tuplet
p_component_list__EMPTY(p) component_list :
p_component_list__component_list__component(p) component_list : component_list component
p_container__BRACE_L__component_list__BRACE_R(p) container : BRACE_L component_list BRACE_R
p_dots__EMPTY(p) dots :
p_dots__dots__DOT(p) dots : dots DOT
p_error(p)
p_fixed_duration_container__BRACE_L__FRACTION__BRACE_R(p) fixed_duration_container : BRACE_L FRACTION BRACE_R
p_leaf__leaf_body__post_events(p) leaf : leaf_body post_events
p_leaf_body__chord_body(p) leaf_body : chord_body
p_leaf_body__note_body(p) leaf_body : note_body
p_leaf_body__rest_body(p) leaf_body : rest_body
p_measure__PIPE__FRACTION__component_list__PIPE(p) measure : PIPE FRACTION component_list PIPE
p_negative_leaf_duration__INTEGER_N__dots(p) negative_leaf_duration : INTEGER_N dots
p_note_body__pitch(p) note_body : pitch
p_note_body__pitch__positive_leaf_duration(p) note_body : pitch positive_leaf_duration
p_note_body__positive_leaf_duration(p) note_body : positive_leaf_duration
p_pitch__PITCHNAME(p) pitch : PITCHNAME
p_pitch__PITCHNAME__apostrophes(p) pitch : PITCHNAME apostrophes
p_pitch__PITCHNAME__commas(p) pitch : PITCHNAME commas
p_pitches__pitch(p) pitches : pitch
p_pitches__pitches__pitch(p) pitches : pitches pitch
p_positive_leaf_duration__INTEGER_P__dots(p) positive_leaf_duration : INTEGER_P dots
p_post_event__beam(p) post_event : beam
p_post_event__slur(p) post_event : slur
p_post_event__tie(p) post_event : tie
p_post_events__EMPTY(p) post_events :
p_post_events__post_events__post_event(p) post_events : post_events post_event
p_rest_body__RESTNAME(p) rest_body : RESTNAME
p_rest_body__RESTNAME__positive_leaf_duration(p) rest_body : RESTNAME positive_leaf_duration
p_rest_body__negative_leaf_duration(p) rest_body : negative_leaf_duration
p_slur__PAREN_L(p) slur : PAREN_L
p_slur__PAREN_R(p) slur : PAREN_R
p_start__EMPTY(p) start :
p_start__start__component(p) start : start component
p_start__start__measure(p) start : start measure
p_tie__TILDE(p) tie : TILDE
p_tuplet__FRACTION__container(p) tuplet : FRACTION container
parser The parser’s PLY LRParser instance.
parser_rules_object Parser rules object of reduced ly parser.
pickle_path The output path for the parser’s pickled parsing tables.
t_FRACTION(t) ([1-9]d*/[1-9]d*)
t_INTEGER_N(t) (-[1-9]d*)
t_INTEGER_P(t) ([1-9]d*)
t_PITCHNAME(t) [a-g](ff|ss|f|s|tqf|tqs|qs|qf)?
t_error(t)
t_newline(t) n+
tokenize(input_string) Tokenize input string and print results.
__call__(input_string) Parse input_string and return result.
__eq__(argument) Is true when ID of argument equals ID of Abjad object.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes Abjad object.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

ReducedLyParser.debug

Gets debug boolean of reduced ly parser.

Returns true or false.

(Parser).lexer

The parser’s PLY Lexer instance.

ReducedLyParser.lexer_rules_object

Lexer rules object of reduced ly parser.

(Parser).logger

The parser’s Logger instance.

(Parser).logger_path

The output path for the parser’s logfile.

(Parser).output_path

The output path for files associated with the parser.

(Parser).parser

The parser’s PLY LRParser instance.

ReducedLyParser.parser_rules_object

Parser rules object of reduced ly parser.

(Parser).pickle_path

The output path for the parser’s pickled parsing tables.

Methods

ReducedLyParser.p_apostrophes__APOSTROPHE(p)

apostrophes : APOSTROPHE

ReducedLyParser.p_apostrophes__apostrophes__APOSTROPHE(p)

apostrophes : apostrophes APOSTROPHE

ReducedLyParser.p_beam__BRACKET_L(p)

beam : BRACKET_L

ReducedLyParser.p_beam__BRACKET_R(p)

beam : BRACKET_R

ReducedLyParser.p_chord_body__chord_pitches(p)

chord_body : chord_pitches

ReducedLyParser.p_chord_body__chord_pitches__positive_leaf_duration(p)

chord_body : chord_pitches positive_leaf_duration

ReducedLyParser.p_chord_pitches__CARAT_L__pitches__CARAT_R(p)

chord_pitches : CARAT_L pitches CARAT_R

ReducedLyParser.p_commas__COMMA(p)

commas : COMMA

ReducedLyParser.p_commas__commas__commas(p)

commas : commas COMMA

ReducedLyParser.p_component__container(p)

component : container

ReducedLyParser.p_component__fixed_duration_container(p)

component : fixed_duration_container

ReducedLyParser.p_component__leaf(p)

component : leaf

ReducedLyParser.p_component__tuplet(p)

component : tuplet

ReducedLyParser.p_component_list__EMPTY(p)

component_list :

ReducedLyParser.p_component_list__component_list__component(p)

component_list : component_list component

ReducedLyParser.p_container__BRACE_L__component_list__BRACE_R(p)

container : BRACE_L component_list BRACE_R

ReducedLyParser.p_dots__EMPTY(p)

dots :

ReducedLyParser.p_dots__dots__DOT(p)

dots : dots DOT

ReducedLyParser.p_error(p)
ReducedLyParser.p_fixed_duration_container__BRACE_L__FRACTION__BRACE_R(p)

fixed_duration_container : BRACE_L FRACTION BRACE_R

ReducedLyParser.p_leaf__leaf_body__post_events(p)

leaf : leaf_body post_events

ReducedLyParser.p_leaf_body__chord_body(p)

leaf_body : chord_body

ReducedLyParser.p_leaf_body__note_body(p)

leaf_body : note_body

ReducedLyParser.p_leaf_body__rest_body(p)

leaf_body : rest_body

ReducedLyParser.p_measure__PIPE__FRACTION__component_list__PIPE(p)

measure : PIPE FRACTION component_list PIPE

ReducedLyParser.p_negative_leaf_duration__INTEGER_N__dots(p)

negative_leaf_duration : INTEGER_N dots

ReducedLyParser.p_note_body__pitch(p)

note_body : pitch

ReducedLyParser.p_note_body__pitch__positive_leaf_duration(p)

note_body : pitch positive_leaf_duration

ReducedLyParser.p_note_body__positive_leaf_duration(p)

note_body : positive_leaf_duration

ReducedLyParser.p_pitch__PITCHNAME(p)

pitch : PITCHNAME

ReducedLyParser.p_pitch__PITCHNAME__apostrophes(p)

pitch : PITCHNAME apostrophes

ReducedLyParser.p_pitch__PITCHNAME__commas(p)

pitch : PITCHNAME commas

ReducedLyParser.p_pitches__pitch(p)

pitches : pitch

ReducedLyParser.p_pitches__pitches__pitch(p)

pitches : pitches pitch

ReducedLyParser.p_positive_leaf_duration__INTEGER_P__dots(p)

positive_leaf_duration : INTEGER_P dots

ReducedLyParser.p_post_event__beam(p)

post_event : beam

ReducedLyParser.p_post_event__slur(p)

post_event : slur

ReducedLyParser.p_post_event__tie(p)

post_event : tie

ReducedLyParser.p_post_events__EMPTY(p)

post_events :

ReducedLyParser.p_post_events__post_events__post_event(p)

post_events : post_events post_event

ReducedLyParser.p_rest_body__RESTNAME(p)

rest_body : RESTNAME

ReducedLyParser.p_rest_body__RESTNAME__positive_leaf_duration(p)

rest_body : RESTNAME positive_leaf_duration

ReducedLyParser.p_rest_body__negative_leaf_duration(p)

rest_body : negative_leaf_duration

ReducedLyParser.p_slur__PAREN_L(p)

slur : PAREN_L

ReducedLyParser.p_slur__PAREN_R(p)

slur : PAREN_R

ReducedLyParser.p_start__EMPTY(p)

start :

ReducedLyParser.p_start__start__component(p)

start : start component

ReducedLyParser.p_start__start__measure(p)

start : start measure

ReducedLyParser.p_tie__TILDE(p)

tie : TILDE

ReducedLyParser.p_tuplet__FRACTION__container(p)

tuplet : FRACTION container

ReducedLyParser.t_FRACTION(t)

([1-9]d*/[1-9]d*)

ReducedLyParser.t_INTEGER_N(t)

(-[1-9]d*)

ReducedLyParser.t_INTEGER_P(t)

([1-9]d*)

ReducedLyParser.t_PITCHNAME(t)

[a-g](ff|ss|f|s|tqf|tqs|qs|qf)?

ReducedLyParser.t_error(t)
ReducedLyParser.t_newline(t)

n+

(Parser).tokenize(input_string)

Tokenize input string and print results.

Special methods

(Parser).__call__(input_string)

Parse input_string and return result.

(AbjadObject).__eq__(argument)

Is true when ID of argument equals ID of Abjad object. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(AbjadObject).__hash__()

Hashes Abjad object.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.