From 093a9c4ddf43508fc5d19286ba0916c1dc8d2e73 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Thu, 22 Oct 2015 09:39:29 +0200 Subject: [PATCH 1/2] Support define_special directive in chordpro #84 --- patacrep/songs/chordpro/ast.py | 3 ++- patacrep/songs/chordpro/data/chordpro/content_define | 6 +++++- patacrep/songs/chordpro/data/latex/content_define | 10 ++++++++-- patacrep/songs/chordpro/syntax.py | 7 ++++--- test/test_chordpro/customchords.sgc | 1 + test/test_chordpro/customchords.source | 1 + test/test_chordpro/customchords.tex | 1 + 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 9213ed37..60a2adc8 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -334,11 +334,12 @@ class Define(Directive): open). Can be `None` if not defined. """ - def __init__(self, key, basefret, frets, fingers): + def __init__(self, key, basefret, frets, fingers, is_special): self.key = key self.basefret = basefret # Can be None self.frets = frets self.fingers = fingers # Can be None + self.is_special = is_special super().__init__("define", None) @property diff --git a/patacrep/songs/chordpro/data/chordpro/content_define b/patacrep/songs/chordpro/data/chordpro/content_define index 47a93abf..14fbe1c9 100644 --- a/patacrep/songs/chordpro/data/chordpro/content_define +++ b/patacrep/songs/chordpro/data/chordpro/content_define @@ -1,4 +1,8 @@ -{define: (( render(content.key) )) +{define +(*- if content.is_special -*) + _special +(*- endif -*) +: (( render(content.key) )) (*- if content.basefret *) base-fret ((content.basefret)) (*- endif *) diff --git a/patacrep/songs/chordpro/data/latex/content_define b/patacrep/songs/chordpro/data/latex/content_define index d1294b3a..6f8caa93 100644 --- a/patacrep/songs/chordpro/data/latex/content_define +++ b/patacrep/songs/chordpro/data/latex/content_define @@ -1,7 +1,13 @@ (*- if content.frets|length == 4 -*) -\utab{ +\utab +(*- if content.is_special -*) + * +(*- endif -*){ (*- else -*) -\gtab{ +\gtab +(*- if content.is_special -*) + * +(*- endif -*){ (*- endif -*) ((- render(content.key) -)) }{ diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index e88d7360..0133a051 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -69,7 +69,7 @@ class ChordproParser(Parser): symbols[0] = None @staticmethod - def _parse_define(groups): + def _parse_define(groups, is_special=False): """Parse a `{define: KEY base-fret BASE frets FRETS fingers FINGERS}` directive Return a :class:`ast.Define` object. @@ -110,6 +110,7 @@ class ChordproParser(Parser): basefret=basefret, frets=frets, fingers=fingers, + is_special=is_special, ) def p_directive(self, symbols): @@ -123,7 +124,7 @@ class ChordproParser(Parser): keyword = symbols[3] argument = symbols[4] - if keyword == "define": + if keyword == "define" or keyword == "define_special": match = re.compile( r""" ^ @@ -150,7 +151,7 @@ class ChordproParser(Parser): symbols[0] = ast.Error() return - define = self._parse_define(match.groupdict()) + define = self._parse_define(match.groupdict(), keyword == "define_special") if define is None: self.error( line=symbols.lexer.lineno, diff --git a/test/test_chordpro/customchords.sgc b/test/test_chordpro/customchords.sgc index dd42e025..317f6d20 100644 --- a/test/test_chordpro/customchords.sgc +++ b/test/test_chordpro/customchords.sgc @@ -3,3 +3,4 @@ {define: E5 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} {define: E5/A* base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} {define: A#+2 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} +{define_special: A#+2 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} diff --git a/test/test_chordpro/customchords.source b/test/test_chordpro/customchords.source index 4c6734cc..ee89fb6f 100644 --- a/test/test_chordpro/customchords.source +++ b/test/test_chordpro/customchords.source @@ -2,3 +2,4 @@ {define: E5 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} {define: E5/A* base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} {define: A#+2 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} +{define_special: A#+2 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} diff --git a/test/test_chordpro/customchords.tex b/test/test_chordpro/customchords.tex index 80f13c9a..7b7c4cb7 100644 --- a/test/test_chordpro/customchords.tex +++ b/test/test_chordpro/customchords.tex @@ -9,6 +9,7 @@ \gtab{E5}{7:0133XX:012300} \gtab{E5/A*}{7:0133XX:012300} \gtab{A#+2}{7:0133XX:012300} +\gtab*{A#+2}{7:0133XX:012300} \endsong From 788c69532756a1762a9122e575e43ae4648d8b02 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Thu, 22 Oct 2015 09:42:57 +0200 Subject: [PATCH 2/2] pylint --- patacrep/songs/chordpro/ast.py | 1 + 1 file changed, 1 insertion(+) diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 60a2adc8..9723ab8d 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -335,6 +335,7 @@ class Define(Directive): """ def __init__(self, key, basefret, frets, fingers, is_special): + # pylint: disable=too-many-arguments self.key = key self.basefret = basefret # Can be None self.frets = frets