From d712a8060133a21c217d56738b53755141a1c342 Mon Sep 17 00:00:00 2001
From: Oliverpool
Date: Sun, 13 Mar 2016 17:46:24 +0100
Subject: [PATCH 1/2] Support repeat inline directive
---
.../songs/chordpro/chordpro/content_meta | 2 +-
.../songs/chordpro/latex/content_meta | 2 +-
.../songs/chordpro/latex/content_repeat | 1 +
patacrep/songs/chordpro/ast.py | 31 +++++++++++++++++++
patacrep/songs/chordpro/syntax.py | 13 ++++++++
5 files changed, 47 insertions(+), 2 deletions(-)
create mode 100644 patacrep/data/templates/songs/chordpro/latex/content_repeat
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..380d1437 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
+ 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..b44d0334 100644
--- a/patacrep/songs/chordpro/syntax.py
+++ b/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:
From 865e980579132926269dd56ff07743e7538167ee Mon Sep 17 00:00:00 2001
From: oliverpool
Date: Sat, 1 Jul 2017 23:56:12 +0200
Subject: [PATCH 2/2] fix newline tests
---
patacrep/songs/chordpro/ast.py | 2 +-
patacrep/songs/chordpro/syntax.py | 3 ++-
test/test_patatools/test_convert.py | 6 ++----
test/test_song/newline.crlf.csg | 2 +-
test/test_song/newline.crlf.html | 2 +-
test/test_song/newline.crlf.tsg | 2 +-
test/test_song/newline.csg | 2 +-
test/test_song/newline.html | 2 +-
test/test_song/newline.tsg | 2 +-
9 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py
index 380d1437..bca092b6 100644
--- a/patacrep/songs/chordpro/ast.py
+++ b/patacrep/songs/chordpro/ast.py
@@ -388,7 +388,7 @@ class VerseDirective(Directive):
def __init__(self, keyword, argument=None):
if keyword not in VERSE_DIRECTIVES:
#TODO Raise better exception
- raise Exception
+ raise Exception(keyword)
super().__init__(keyword, argument)
@property
diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py
index b44d0334..bb294143 100644
--- a/patacrep/songs/chordpro/syntax.py
+++ b/patacrep/songs/chordpro/syntax.py
@@ -262,7 +262,8 @@ class ChordproParser(Parser):
keyword = symbols[3]
argument = symbols[4]
- symbols[0] = ast.VerseDirective(keyword, argument)
+ if keyword != "newline":
+ symbols[0] = ast.VerseDirective(keyword, argument)
@staticmethod
def p_directive_next(symbols):
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