oliverpool
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with
56 additions and
12 deletions
-
patacrep/data/templates/songs/chordpro/chordpro/content_meta
-
patacrep/data/templates/songs/chordpro/latex/content_meta
-
patacrep/data/templates/songs/chordpro/latex/content_repeat
-
patacrep/songs/chordpro/ast.py
-
patacrep/songs/chordpro/syntax.py
-
test/test_patatools/test_convert.py
-
test/test_song/newline.crlf.csg
-
test/test_song/newline.crlf.html
-
test/test_song/newline.crlf.tsg
-
test/test_song/newline.csg
-
test/test_song/newline.html
-
test/test_song/newline.tsg
|
|
@ -1 +1 @@ |
|
|
|
{meta: (( content.argument[0] )):(( content.argument[2] ))} |
|
|
|
{meta: (( content.argument[0] )):(( content.argument[2] ))} |
|
|
|
|
|
@ -1 +1 @@ |
|
|
|
\metacrep{((- content.argument[0] -))}{((- content.argument[2] -))} |
|
|
|
\metacrep{((- content.argument[0] -))}{((- content.argument[2] -))} |
|
|
|
|
|
@ -0,0 +1 @@ |
|
|
|
\rep{((- content -))} |
|
|
@ -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(keyword) |
|
|
|
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. |
|
|
|
|
|
|
|
|
|
@ -251,6 +251,19 @@ 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] |
|
|
|
|
|
|
|
if keyword != "newline": |
|
|
|
symbols[0] = ast.VerseDirective(keyword, argument) |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def p_directive_next(symbols): |
|
|
@ -310,6 +323,7 @@ class ChordproParser(Parser): |
|
|
|
| space line_next |
|
|
|
| chord line_next |
|
|
|
| echo line_next |
|
|
|
| verse_directive line_next |
|
|
|
| empty |
|
|
|
""" |
|
|
|
if len(symbols) == 2: |
|
|
|
|
|
@ -70,10 +70,8 @@ class TestConvert(unittest.TestCase, metaclass=dynamic.DynamicTest): |
|
|
|
with logging_reduced(): |
|
|
|
if os.path.exists(destname): |
|
|
|
os.remove(destname) |
|
|
|
self.assertEqual( |
|
|
|
self._system(main, args + [in_format, out_format, sourcename]), |
|
|
|
1, |
|
|
|
) |
|
|
|
with self.assertRaises(Exception): |
|
|
|
self._system(main, args + [in_format, out_format, sourcename]) |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@contextlib.contextmanager |
|
|
|
|
|
@ -38,4 +38,4 @@ New lines can also |
|
|
|
Be surrounded by spaces |
|
|
|
|
|
|
|
|
|
|
|
New lines cannot |
|
|
|
New lines cannot appear in the middle of a line |
|
|
|
|
|
@ -38,6 +38,6 @@ Be in bridges |
|
|
|
Be surrounded by spaces |
|
|
|
</p> |
|
|
|
|
|
|
|
<p class="verse">New lines cannot |
|
|
|
<p class="verse">New lines cannot appear in the middle of a line |
|
|
|
</p> |
|
|
|
</div> |
|
|
@ -55,7 +55,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
\begin{verse} |
|
|
|
New lines cannot |
|
|
|
New lines cannot appear in the middle of a line |
|
|
|
\end{verse} |
|
|
|
|
|
|
|
\endsong |
|
|
|
|
|
@ -38,4 +38,4 @@ New lines can also |
|
|
|
Be surrounded by spaces |
|
|
|
|
|
|
|
|
|
|
|
New lines cannot |
|
|
|
New lines cannot appear in the middle of a line |
|
|
|
|
|
@ -38,6 +38,6 @@ Be in bridges |
|
|
|
Be surrounded by spaces |
|
|
|
</p> |
|
|
|
|
|
|
|
<p class="verse">New lines cannot |
|
|
|
<p class="verse">New lines cannot appear in the middle of a line |
|
|
|
</p> |
|
|
|
</div> |
|
|
@ -55,7 +55,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
\begin{verse} |
|
|
|
New lines cannot |
|
|
|
New lines cannot appear in the middle of a line |
|
|
|
\end{verse} |
|
|
|
|
|
|
|
\endsong |
|
|
|