Browse Source

Support repeat inline directive

content_repeat
Oliverpool 9 years ago
committed by oliverpool
parent
commit
d712a80601
  1. 2
      patacrep/data/templates/songs/chordpro/chordpro/content_meta
  2. 2
      patacrep/data/templates/songs/chordpro/latex/content_meta
  3. 1
      patacrep/data/templates/songs/chordpro/latex/content_repeat
  4. 31
      patacrep/songs/chordpro/ast.py
  5. 13
      patacrep/songs/chordpro/syntax.py

2
patacrep/data/templates/songs/chordpro/chordpro/content_meta

@ -1 +1 @@
{meta: (( content.argument[0] )):(( content.argument[2] ))} {meta: (( content.argument[0] )):(( content.argument[2] ))}

2
patacrep/data/templates/songs/chordpro/latex/content_meta

@ -1 +1 @@
\metacrep{((- content.argument[0] -))}{((- content.argument[2] -))} \metacrep{((- content.argument[0] -))}{((- content.argument[2] -))}

1
patacrep/data/templates/songs/chordpro/latex/content_repeat

@ -0,0 +1 @@
\rep{((- content -))}

31
patacrep/songs/chordpro/ast.py

@ -46,6 +46,12 @@ INLINE_DIRECTIVES = {
"meta", "meta",
} }
#: List of properties that are to be displayed in the flow of the song (not as
#: metadata at the beginning or end of song.
VERSE_DIRECTIVES = {
"repeat",
}
#: Some directive have alternative names. For instance `{title: Foo}` and `{t: #: Some directive have alternative names. For instance `{title: Foo}` and `{t:
#: Foo}` are equivalent. #: Foo}` are equivalent.
DIRECTIVE_SHORTCUTS = { DIRECTIVE_SHORTCUTS = {
@ -376,6 +382,31 @@ class Directive(AST):
"""Return `True` iff `self` is an inline directive.""" """Return `True` iff `self` is an inline directive."""
return self.keyword in INLINE_DIRECTIVES return self.keyword in INLINE_DIRECTIVES
class VerseDirective(Directive):
"""A verse directive (can be inside some text)"""
def __init__(self, keyword, argument=None):
if keyword not in VERSE_DIRECTIVES:
#TODO Raise better exception
raise Exception
super().__init__(keyword, argument)
@property
def _template(self):
"""Name of the template to use to render this keyword.
This only applies if ``self.inline == True``
"""
return self.keyword
def __str__(self):
return str(self.argument)
@property
def inline(self):
"""Return `True` iff `self` is an inline directive."""
return True
class Define(Directive): class Define(Directive):
"""A chord definition. """A chord definition.

13
patacrep/songs/chordpro/syntax.py

@ -251,6 +251,18 @@ class ChordproParser(Parser):
else: else:
self._directives.append(directive) self._directives.append(directive)
def p_verse_directive(self, symbols):
"""verse_directive : LBRACE KEYWORD directive_next RBRACE
| LBRACE SPACE KEYWORD directive_next RBRACE
"""
if len(symbols) == 5:
keyword = symbols[2]
argument = symbols[3]
else:
keyword = symbols[3]
argument = symbols[4]
symbols[0] = ast.VerseDirective(keyword, argument)
@staticmethod @staticmethod
def p_directive_next(symbols): def p_directive_next(symbols):
@ -310,6 +322,7 @@ class ChordproParser(Parser):
| space line_next | space line_next
| chord line_next | chord line_next
| echo line_next | echo line_next
| verse_directive line_next
| empty | empty
""" """
if len(symbols) == 2: if len(symbols) == 2:

Loading…
Cancel
Save