From af0e83bbf940ce4785725aece9cb390ea5d6b209 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 2 Sep 2015 10:27:17 +0200 Subject: [PATCH] [chordpro] Accepting + and * in chords References patacrep/patadata#18 --- patacrep/songs/chordpro/ast.py | 2 ++ patacrep/songs/chordpro/data/chordpro/content_chord | 1 + patacrep/songs/chordpro/data/latex/content_chord | 1 + patacrep/songs/chordpro/lexer.py | 2 +- patacrep/songs/chordpro/syntax.py | 5 +++-- patacrep/songs/chordpro/test/chords.sgc | 2 ++ patacrep/songs/chordpro/test/chords.source | 2 ++ patacrep/songs/chordpro/test/chords.tex | 2 ++ patacrep/songs/chordpro/test/customchords.sgc | 2 ++ patacrep/songs/chordpro/test/customchords.source | 2 ++ patacrep/songs/chordpro/test/customchords.tex | 2 ++ patacrep/songs/chordpro/test/invalid_chord.source | 2 +- 12 files changed, 21 insertions(+), 4 deletions(-) diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 1aaae349..178e09ba 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -153,6 +153,7 @@ class Chord(AST): addnote=None, basskey=None, bassalteration=None, + star=None, ): # pylint: disable=too-many-arguments self.key = key @@ -161,6 +162,7 @@ class Chord(AST): self.addnote = addnote self.basskey = basskey self.bassalteration = bassalteration + self.star = star class Verse(AST): """A verse (or bridge, or chorus)""" diff --git a/patacrep/songs/chordpro/data/chordpro/content_chord b/patacrep/songs/chordpro/data/chordpro/content_chord index 6fce5be6..99e0d4c4 100644 --- a/patacrep/songs/chordpro/data/chordpro/content_chord +++ b/patacrep/songs/chordpro/data/chordpro/content_chord @@ -6,4 +6,5 @@ / ((- content.basskey -)) (* if content.bassalteration *)(( content.bassalteration ))(* endif -*) +(* if content.star *)*(* endif -*) (* endif -*) diff --git a/patacrep/songs/chordpro/data/latex/content_chord b/patacrep/songs/chordpro/data/latex/content_chord index 29a1cc30..406b75fe 100644 --- a/patacrep/songs/chordpro/data/latex/content_chord +++ b/patacrep/songs/chordpro/data/latex/content_chord @@ -8,4 +8,5 @@ ((- content.basskey -)) (* if content.bassalteration == '#' *)#(* endif -*) (* if content.bassalteration == 'b' *)&(* endif -*) +(* if content.star *)*(* endif -*) (* endif -*) diff --git a/patacrep/songs/chordpro/lexer.py b/patacrep/songs/chordpro/lexer.py index 813c42b0..6d47bea8 100644 --- a/patacrep/songs/chordpro/lexer.py +++ b/patacrep/songs/chordpro/lexer.py @@ -39,7 +39,7 @@ class ChordProLexer: t_SPACE = r'[ \t]+' - t_chord_CHORD = r'[A-G#bmajdisus2-9/ ]+' + t_chord_CHORD = r'[A-G#bmajdisus+*2-9/ ]+' t_directive_SPACE = r'[ \t]+' t_directive_KEYWORD = r'[a-zA-Z_]+' diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index 1e1420bc..89264f68 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -12,13 +12,14 @@ CHORD_RE = re.compile( ^ (?P[A-G]) (?P[b#])? - (?P(maj|sus|dim|m))? + (?P(maj|sus|dim|m|\+))? (?P[2-9])? ( / (?P[A-G]) (?P[b#])? )? + (?P\*)? $ """, re.VERBOSE @@ -223,7 +224,7 @@ class ChordproParser(Parser): def p_chord(self, symbols): """chord : CHORD""" - symbols[0] = ast.ChordList(*self._parse_chords(symbols[1], symbols=symbols)) + symbols[0] = ast.ChordList(*list(self._parse_chords(symbols[1], symbols=symbols))) @staticmethod def p_chorus(symbols): diff --git a/patacrep/songs/chordpro/test/chords.sgc b/patacrep/songs/chordpro/test/chords.sgc index 955f44d6..942a0223 100644 --- a/patacrep/songs/chordpro/test/chords.sgc +++ b/patacrep/songs/chordpro/test/chords.sgc @@ -14,4 +14,6 @@ [F/Fb]Deux notes, bémol [B/C#]Deux notes, dièse [Ab B#/A]Plusieurs notes à la suite + [E5/A*]Avec une étoile + [B#+8]Avec un plus {end_of_verse} diff --git a/patacrep/songs/chordpro/test/chords.source b/patacrep/songs/chordpro/test/chords.source index 84397df2..a4803589 100644 --- a/patacrep/songs/chordpro/test/chords.source +++ b/patacrep/songs/chordpro/test/chords.source @@ -11,3 +11,5 @@ [F/Fb]Deux notes, bémol [B/C#]Deux notes, dièse [Ab B#/A]Plusieurs notes à la suite +[E5/A*]Avec une étoile +[B#+8]Avec un plus diff --git a/patacrep/songs/chordpro/test/chords.tex b/patacrep/songs/chordpro/test/chords.tex index 9bb98002..a621a7cd 100644 --- a/patacrep/songs/chordpro/test/chords.tex +++ b/patacrep/songs/chordpro/test/chords.tex @@ -20,6 +20,8 @@ \[F/F&]Deux notes, bémol \[B/C#]Deux notes, dièse \[A& B#/A]Plusieurs notes à la suite + \[E5/A*]Avec une étoile + \[B#+8]Avec un plus \end{verse} \endsong diff --git a/patacrep/songs/chordpro/test/customchords.sgc b/patacrep/songs/chordpro/test/customchords.sgc index 1148a901..3357bb96 100644 --- a/patacrep/songs/chordpro/test/customchords.sgc +++ b/patacrep/songs/chordpro/test/customchords.sgc @@ -1,3 +1,5 @@ {language: english} {define: E4 base-fret 7 frets 0 1 3 3 x x} {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 - -} diff --git a/patacrep/songs/chordpro/test/customchords.source b/patacrep/songs/chordpro/test/customchords.source index b7192c87..4c6734cc 100644 --- a/patacrep/songs/chordpro/test/customchords.source +++ b/patacrep/songs/chordpro/test/customchords.source @@ -1,2 +1,4 @@ {define: E4 base-fret 7 frets 0 1 3 3 x x} {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 - -} diff --git a/patacrep/songs/chordpro/test/customchords.tex b/patacrep/songs/chordpro/test/customchords.tex index 3f2000b2..80f13c9a 100644 --- a/patacrep/songs/chordpro/test/customchords.tex +++ b/patacrep/songs/chordpro/test/customchords.tex @@ -7,6 +7,8 @@ \gtab{E4}{7:0133XX} \gtab{E5}{7:0133XX:012300} +\gtab{E5/A*}{7:0133XX:012300} +\gtab{A#+2}{7:0133XX:012300} \endsong diff --git a/patacrep/songs/chordpro/test/invalid_chord.source b/patacrep/songs/chordpro/test/invalid_chord.source index 872697b3..7df0d1f9 100644 --- a/patacrep/songs/chordpro/test/invalid_chord.source +++ b/patacrep/songs/chordpro/test/invalid_chord.source @@ -1,3 +1,3 @@ This is [H] invalid. -This [A+]too. +This [A@]too. And [Amm]as well.