Browse Source

Support repeat inline directive

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

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",
}
#: 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:
#: Foo}` are equivalent.
DIRECTIVE_SHORTCUTS = {
@ -376,6 +382,31 @@ class Directive(AST):
"""Return `True` iff `self` is an inline directive."""
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):
"""A chord definition.

13
patacrep/songs/chordpro/syntax.py

@ -251,6 +251,18 @@ class ChordproParser(Parser):
else:
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
def p_directive_next(symbols):
@ -310,6 +322,7 @@ class ChordproParser(Parser):
| space line_next
| chord line_next
| echo line_next
| verse_directive line_next
| empty
"""
if len(symbols) == 2:

Loading…
Cancel
Save