diff --git a/patacrep/data/templates/songs/chordpro/chordpro/content_meta b/patacrep/data/templates/songs/chordpro/chordpro/content_meta index a4015066..7af09db0 100644 --- a/patacrep/data/templates/songs/chordpro/chordpro/content_meta +++ b/patacrep/data/templates/songs/chordpro/chordpro/content_meta @@ -1 +1 @@ -{meta: (( content.argument[0] )):(( content.argument[2] ))} \ No newline at end of file +{meta: (( content.argument[0] )):(( content.argument[2] ))} diff --git a/patacrep/data/templates/songs/chordpro/latex/content_meta b/patacrep/data/templates/songs/chordpro/latex/content_meta index 919f95a7..ff5d49d7 100644 --- a/patacrep/data/templates/songs/chordpro/latex/content_meta +++ b/patacrep/data/templates/songs/chordpro/latex/content_meta @@ -1 +1 @@ -\metacrep{((- content.argument[0] -))}{((- content.argument[2] -))} \ No newline at end of file +\metacrep{((- content.argument[0] -))}{((- content.argument[2] -))} diff --git a/patacrep/data/templates/songs/chordpro/latex/content_repeat b/patacrep/data/templates/songs/chordpro/latex/content_repeat new file mode 100644 index 00000000..5939f45c --- /dev/null +++ b/patacrep/data/templates/songs/chordpro/latex/content_repeat @@ -0,0 +1 @@ +\rep{((- content -))} \ No newline at end of file diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 2bbddaf1..bca092b6 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/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. diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index a1e3f6e6..bb294143 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/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: diff --git a/test/test_patatools/test_convert.py b/test/test_patatools/test_convert.py index f882fe88..437a54c0 100644 --- a/test/test_patatools/test_convert.py +++ b/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 diff --git a/test/test_song/newline.crlf.csg b/test/test_song/newline.crlf.csg index e9bf0c62..5ebdcec7 100644 --- a/test/test_song/newline.crlf.csg +++ b/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 diff --git a/test/test_song/newline.crlf.html b/test/test_song/newline.crlf.html index 5540af64..d29e7530 100644 --- a/test/test_song/newline.crlf.html +++ b/test/test_song/newline.crlf.html @@ -38,6 +38,6 @@ Be in bridges Be surrounded by spaces
-New lines cannot +
New lines cannot appear in the middle of a line
\ No newline at end of file diff --git a/test/test_song/newline.crlf.tsg b/test/test_song/newline.crlf.tsg index d557de5f..5122de62 100644 --- a/test/test_song/newline.crlf.tsg +++ b/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 diff --git a/test/test_song/newline.csg b/test/test_song/newline.csg index e9bf0c62..5ebdcec7 100644 --- a/test/test_song/newline.csg +++ b/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 diff --git a/test/test_song/newline.html b/test/test_song/newline.html index 5540af64..d29e7530 100644 --- a/test/test_song/newline.html +++ b/test/test_song/newline.html @@ -38,6 +38,6 @@ Be in bridges Be surrounded by spaces -New lines cannot +
New lines cannot appear in the middle of a line
\ No newline at end of file diff --git a/test/test_song/newline.tsg b/test/test_song/newline.tsg index d557de5f..5122de62 100644 --- a/test/test_song/newline.tsg +++ b/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