Browse Source

Merge 865e980579 into 48040d2215

pull/255/merge
oliverpool 7 months ago
committed by GitHub
parent
commit
98e626f09c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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. 14
      patacrep/songs/chordpro/syntax.py
  6. 6
      test/test_patatools/test_convert.py
  7. 2
      test/test_song/newline.crlf.csg
  8. 2
      test/test_song/newline.crlf.html
  9. 2
      test/test_song/newline.crlf.tsg
  10. 2
      test/test_song/newline.csg
  11. 2
      test/test_song/newline.html
  12. 2
      test/test_song/newline.tsg

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",
}
#: 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.

14
patacrep/songs/chordpro/syntax.py

@ -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:

6
test/test_patatools/test_convert.py

@ -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

2
test/test_song/newline.crlf.csg

@ -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

2
test/test_song/newline.crlf.html

@ -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>

2
test/test_song/newline.crlf.tsg

@ -55,7 +55,7 @@
\begin{verse}
New lines cannot
New lines cannot appear in the middle of a line
\end{verse}
\endsong

2
test/test_song/newline.csg

@ -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

2
test/test_song/newline.html

@ -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>

2
test/test_song/newline.tsg

@ -55,7 +55,7 @@
\begin{verse}
New lines cannot
New lines cannot appear in the middle of a line
\end{verse}
\endsong

Loading…
Cancel
Save