Browse Source

Support define_special directive in chordpro #84

pull/127/head
Oliverpool 9 years ago
parent
commit
093a9c4ddf
  1. 3
      patacrep/songs/chordpro/ast.py
  2. 6
      patacrep/songs/chordpro/data/chordpro/content_define
  3. 10
      patacrep/songs/chordpro/data/latex/content_define
  4. 7
      patacrep/songs/chordpro/syntax.py
  5. 1
      test/test_chordpro/customchords.sgc
  6. 1
      test/test_chordpro/customchords.source
  7. 1
      test/test_chordpro/customchords.tex

3
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

6
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 *)

10
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) -))
}{

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

1
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 - -}

1
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 - -}

1
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

Loading…
Cancel
Save