RhythmTreeParser

class rhythmtreetools.RhythmTreeParser(debug=False)

A rhythm-tree syntax parser.

Abjad’s rhythm-tree parser parses a micro-language resembling Ircam’s RTM Lisp syntax, and generates a sequence of RhythmTree structures, which can be furthered manipulated by composers, before being converted into an Abjad score object:

>>> parser = rhythmtreetools.RhythmTreeParser()
>>> string = '(3 (1 (1 ((2 (1 1 1)) 2 2 1))))'
>>> rhythm_tree_list = parser(string)
>>> rhythm_tree_container = rhythm_tree_list[0]
>>> rhythm_tree_container.rtm_format
'(3 (1 (1 ((2 (1 1 1)) 2 2 1))))'
>>> print(format(rhythm_tree_container))
rhythmtreetools.RhythmTreeContainer(
    children=(
        rhythmtreetools.RhythmTreeLeaf(
            preprolated_duration=durationtools.Duration(1, 1),
            is_pitched=True,
            ),
        rhythmtreetools.RhythmTreeContainer(
            children=(
                rhythmtreetools.RhythmTreeContainer(
                    children=(
                        rhythmtreetools.RhythmTreeLeaf(
                            preprolated_duration=durationtools.Duration(1, 1),
                            is_pitched=True,
                            ),
                        rhythmtreetools.RhythmTreeLeaf(
                            preprolated_duration=durationtools.Duration(1, 1),
                            is_pitched=True,
                            ),
                        rhythmtreetools.RhythmTreeLeaf(
                            preprolated_duration=durationtools.Duration(1, 1),
                            is_pitched=True,
                            ),
                        ),
                    preprolated_duration=durationtools.Duration(2, 1),
                    ),
                rhythmtreetools.RhythmTreeLeaf(
                    preprolated_duration=durationtools.Duration(2, 1),
                    is_pitched=True,
                    ),
                rhythmtreetools.RhythmTreeLeaf(
                    preprolated_duration=durationtools.Duration(2, 1),
                    is_pitched=True,
                    ),
                rhythmtreetools.RhythmTreeLeaf(
                    preprolated_duration=durationtools.Duration(1, 1),
                    is_pitched=True,
                    ),
                ),
            preprolated_duration=durationtools.Duration(1, 1),
            ),
        ),
    preprolated_duration=durationtools.Duration(3, 1),
    )
>>> base_duration = (1, 4)
>>> component_list = rhythm_tree_container(base_duration)
>>> tuplet = component_list[0]
>>> show(tuplet) 

Returns RhythmTreeParser instance.

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_rhythmtreetools { graph [label=rhythmtreetools]; "abjad.tools.rhythmtreetools.RhythmTreeParser.RhythmTreeParser" [color=black, fontcolor=white, group=2, label=<<B>RhythmTreeParser</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.rhythmtreetools.RhythmTreeParser.RhythmTreeParser"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

debug True if the parser runs in debugging mode.
lexer The parser’s PLY Lexer instance.
lexer_rules_object
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_container__LPAREN__DURATION__node_list_closed__RPAREN(p) container : LPAREN DURATION node_list_closed RPAREN
p_error(p)
p_leaf__INTEGER(p) leaf : DURATION
p_node__container(p) node : container
p_node__leaf(p) node : leaf
p_node_list__node_list__node_list_item(p) node_list : node_list node_list_item
p_node_list__node_list_item(p) node_list : node_list_item
p_node_list_closed__LPAREN__node_list__RPAREN(p) node_list_closed : LPAREN node_list RPAREN
p_node_list_item__node(p) node_list_item : node
p_toplevel__EMPTY(p) toplevel :
p_toplevel__toplevel__node(p) toplevel : toplevel node
parser The parser’s PLY LRParser instance.
parser_rules_object
pickle_path The output path for the parser’s pickled parsing tables.
t_DURATION(t) -?[1-9]d*(/[1-9]d*)?
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

(Parser).debug

True if the parser runs in debugging mode.

(Parser).lexer

The parser’s PLY Lexer instance.

RhythmTreeParser.lexer_rules_object
(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.

RhythmTreeParser.parser_rules_object
(Parser).pickle_path

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

Methods

RhythmTreeParser.p_container__LPAREN__DURATION__node_list_closed__RPAREN(p)

container : LPAREN DURATION node_list_closed RPAREN

RhythmTreeParser.p_error(p)
RhythmTreeParser.p_leaf__INTEGER(p)

leaf : DURATION

RhythmTreeParser.p_node__container(p)

node : container

RhythmTreeParser.p_node__leaf(p)

node : leaf

RhythmTreeParser.p_node_list__node_list__node_list_item(p)

node_list : node_list node_list_item

RhythmTreeParser.p_node_list__node_list_item(p)

node_list : node_list_item

RhythmTreeParser.p_node_list_closed__LPAREN__node_list__RPAREN(p)

node_list_closed : LPAREN node_list RPAREN

RhythmTreeParser.p_node_list_item__node(p)

node_list_item : node

RhythmTreeParser.p_toplevel__EMPTY(p)

toplevel :

RhythmTreeParser.p_toplevel__toplevel__node(p)

toplevel : toplevel node

RhythmTreeParser.t_DURATION(t)

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

RhythmTreeParser.t_error(t)
RhythmTreeParser.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.