Exemple #1
0
def parse(string, language='english'):
    r'''Parses LilyPond `string`.

    ..  container:: example

        Parses LilyPond string with English note names:

        >>> container = abjad.parse("{c'4 d'4 e'4 f'4}")
        >>> abjad.show(container) # doctest: +SKIP

    ..  container:: example

        Parses LilyPond string with Dutch note names:

        >>> container = abjad.parse(
        ...     "{c'8 des' e' fis'}",
        ...     language='nederlands',
        ...     )
        >>> abjad.show(container) # doctest: +SKIP

    Returns Abjad component.
    '''
    from abjad.tools import rhythmtreetools
    from abjad.tools import lilypondparsertools
    if string.startswith('abj:'):
        return lilypondparsertools.parse_reduced_ly_syntax(string[4:])
    elif string.startswith('rtm:'):
        return rhythmtreetools.parse_rtm_syntax(string[4:])
    if language not in _lilypond_parsers_by_language:
        parser = lilypondparsertools.LilyPondParser(default_language=language)
        _lilypond_parsers_by_language[language] = parser
    return _lilypond_parsers_by_language[language](string)
Exemple #2
0
def test_rhythmtreetools_parse_rtm_syntax_01():

    rtm = '(3 (1 (3 (1 (3 (1 (3 (1 1 1 1))))))))'
    result = rhythmtreetools.parse_rtm_syntax(rtm)

    assert format(result) == abjad.String.normalize(
        r'''
        \tweak text #tuplet-number::calc-fraction-text
        \times 3/4 {
            c'4
            \tweak text #tuplet-number::calc-fraction-text
            \times 3/4 {
                c'4
                \tweak text #tuplet-number::calc-fraction-text
                \times 3/4 {
                    c'4
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 3/4 {
                        c'4
                        c'4
                        c'4
                        c'4
                    }
                }
            }
        }
        '''
        )
Exemple #3
0
def parse(arg, language='english'):
    r'''Parses `arg` as LilyPond string.

    ::

        >>> parse("{c'4 d'4 e'4 f'4}")
        Container("c'4 d'4 e'4 f'4")

    ::

        >>> container = _

    ::

        >>> print(format(container))
        {
            c'4
            d'4
            e'4
            f'4
        }

    A pitch-name language may also be specified.

    ::

        >>> parse("{c'8 des' e' fis'}", language='nederlands')
        Container("c'8 df'8 e'8 fs'8")

    Returns Abjad expression.
    '''
    from abjad.tools import rhythmtreetools
    from abjad.tools import lilypondparsertools
    if arg.startswith('abj:'):
        return lilypondparsertools.parse_reduced_ly_syntax(arg[4:])
    elif arg.startswith('rtm:'):
        return rhythmtreetools.parse_rtm_syntax(arg[4:])
    if language not in _lilypond_parsers_by_language:
        parser = lilypondparsertools.LilyPondParser(default_language=language)
        _lilypond_parsers_by_language[language] = parser
    return _lilypond_parsers_by_language[language](arg)
Exemple #4
0
def parse(arg, language='english'):
    r'''Parses `arg` as LilyPond string.

    ::

        >>> parse("{c'4 d'4 e'4 f'4}")
        Container("c'4 d'4 e'4 f'4")

    ::

        >>> container = _

    ::

        >>> print(format(container))
        {
            c'4
            d'4
            e'4
            f'4
        }

    A pitch-name language may also be specified.

    ::

        >>> parse("{c'8 des' e' fis'}", language='nederlands')
        Container("c'8 df'8 e'8 fs'8")

    Returns Abjad expression.
    '''
    from abjad.tools import rhythmtreetools
    from abjad.tools import lilypondparsertools
    if arg.startswith('abj:'):
        return lilypondparsertools.parse_reduced_ly_syntax(arg[4:])
    elif arg.startswith('rtm:'):
        return rhythmtreetools.parse_rtm_syntax(arg[4:])
    if language not in _lilypond_parsers_by_language:
        parser = lilypondparsertools.LilyPondParser(default_language=language)
        _lilypond_parsers_by_language[language] = parser
    return _lilypond_parsers_by_language[language](arg)
Exemple #5
0
 def _parse_string(self, string):
     from abjad.tools import lilypondfiletools
     from abjad.tools import lilypondparsertools
     from abjad.tools import rhythmtreetools
     user_input = string.strip()
     if user_input.startswith('abj:'):
         parser = lilypondparsertools.ReducedLyParser()
         parsed = parser(user_input[4:])
         if parser._toplevel_component_count == 1:
             parsed = Container([parsed])
     elif user_input.startswith('rtm:'):
         parsed = rhythmtreetools.parse_rtm_syntax(user_input[4:])
     else:
         if (not user_input.startswith('<<') or
             not user_input.endswith('>>')):
             user_input = '{{ {} }}'.format(user_input)
         parsed = lilypondparsertools.LilyPondParser()(user_input)
         if isinstance(parsed, lilypondfiletools.LilyPondFile):
             parsed = Container(parsed.items[:])
         assert isinstance(parsed, Container)
     return parsed
Exemple #6
0
 def _parse_string(self, string):
     from abjad.tools import lilypondfiletools
     from abjad.tools import lilypondparsertools
     from abjad.tools import rhythmtreetools
     user_input = string.strip()
     if user_input.startswith('abj:'):
         parser = lilypondparsertools.ReducedLyParser()
         parsed = parser(user_input[4:])
         if parser._toplevel_component_count == 1:
             parsed = Container([parsed])
     elif user_input.startswith('rtm:'):
         parsed = rhythmtreetools.parse_rtm_syntax(user_input[4:])
     else:
         if (not user_input.startswith('<<')
                 or not user_input.endswith('>>')):
             user_input = '{{ {} }}'.format(user_input)
         parsed = lilypondparsertools.LilyPondParser()(user_input)
         if isinstance(parsed, lilypondfiletools.LilyPondFile):
             parsed = Container(parsed.items[:])
         assert isinstance(parsed, Container)
     return parsed
Exemple #7
0
def parse(arg, language='english'):
    r'''Parses `arg` as LilyPond string.

    ::

        >>> parse("{c'4 d'4 e'4 f'4}")
        {c'4, d'4, e'4, f'4}

    ::

        >>> container = _

    ::

        >>> f(container)
        {
            c'4
            d'4
            e'4
            f'4
        }

    A pitch-name language may also be specified.

    ::

        >>> parse("{c'8 des' e' fis'}", language='nederlands')
        {c'8, df'8, e'8, fs'8}

    Returns Abjad expression.
    '''
    from abjad.tools import rhythmtreetools
    from abjad.tools import lilypondparsertools

    if arg.startswith('abj:'):
        return lilypondparsertools.parse_reduced_ly_syntax(arg[4:])
    elif arg.startswith('rtm:'):
        return rhythmtreetools.parse_rtm_syntax(arg[4:])
    return lilypondparsertools.LilyPondParser(default_language=language)(arg)