diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index 8be6ad5e..97b83670 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -30,10 +30,7 @@ class ChordproSong(Song): def render(self, output, output_format): context = { - 'language': self.config.get( - 'lang', - self.cached['song'].get_data_argument('language', 'english'), - ), + 'language': self.languages[0], "path": files.relpath(self.fullpath, os.path.dirname(output)), "titles": self.titles, "authors": self.authors, diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 173f73f4..8b6690c2 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -367,19 +367,13 @@ class Song(AST): def add_key(self, data): """Add a new {key: foo: bar} directive.""" key, *argument = data.argument.split(":") - self._keys.insert(0, Directive( + if 'keys' not in self.meta: + self.meta['keys'] = [] + self.meta['keys'].insert(0, Directive( key.strip(), ":".join(argument).strip(), )) - @property - def keys(self): - """Return the list of keys. - - That is, directive that where given of the form ``{key: foo: bar}``. - """ - return self._keys - def _process_relative(self, directive): """Return the directive, in which the argument is given relative to file @@ -484,6 +478,7 @@ class Tab(AST): """Tablature""" inline = True + _template = "tablature" def __init__(self): super().__init__() diff --git a/patacrep/songs/chordpro/data/chordpro/content_chord b/patacrep/songs/chordpro/data/chordpro/content_chord new file mode 100644 index 00000000..6fce5be6 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_chord @@ -0,0 +1,9 @@ +((- content.key -)) +(* if content.alteration *)(( content.alteration ))(* endif -*) +(* if content.modifier *)((content.modifier))(* endif -*) +(* if content.addnote *)((content.addnote))(* endif -*) +(* if content.basskey -*) + / + ((- content.basskey -)) + (* if content.bassalteration *)(( content.bassalteration ))(* endif -*) +(* endif -*) diff --git a/patacrep/songs/chordpro/data/chordpro/content_chordlist b/patacrep/songs/chordpro/data/chordpro/content_chordlist new file mode 100644 index 00000000..8bcd3410 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_chordlist @@ -0,0 +1,6 @@ +[ + (*- for chord in content.chords -*) + (* if not loop.first *) (* endif -*) + (( render(chord) -)) + (* endfor -*) +] diff --git a/patacrep/songs/chordpro/data/chordpro/content_comment b/patacrep/songs/chordpro/data/chordpro/content_comment new file mode 100644 index 00000000..07381cdf --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_comment @@ -0,0 +1 @@ +{comment: (( content.argument ))} diff --git a/patacrep/songs/chordpro/data/chordpro/content_define b/patacrep/songs/chordpro/data/chordpro/content_define new file mode 100644 index 00000000..47a93abf --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_define @@ -0,0 +1,25 @@ +{define: (( render(content.key) )) +(*- if content.basefret *) + base-fret ((content.basefret)) +(*- endif *) + frets +(*- for string in content.frets -*) + (( " " -)) + (*- if string is none -*) + x + (*- else -*) + (( string -)) + (*- endif -*) +(*- endfor -*) +(* if content.fingers *) + fingers + (*- for finger in content.fingers -*) + (( " " -)) + (* if finger is none -*) + - + (*- else -*) + (( finger -)) + (* endif -*) + (* endfor -*) +(* endif -*) +} diff --git a/patacrep/songs/chordpro/data/chordpro/content_error b/patacrep/songs/chordpro/data/chordpro/content_error new file mode 100644 index 00000000..bbdb95fd --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_error @@ -0,0 +1,3 @@ + +ERROR : Template not found for "(( content.__class__.__name__ ))". See the logs for details. + diff --git a/patacrep/songs/chordpro/data/chordpro/content_guitar_comment b/patacrep/songs/chordpro/data/chordpro/content_guitar_comment new file mode 100644 index 00000000..1ca0c269 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_guitar_comment @@ -0,0 +1 @@ +{guitar_comment: (( content.argument ))} diff --git a/patacrep/songs/chordpro/data/chordpro/content_image b/patacrep/songs/chordpro/data/chordpro/content_image new file mode 100644 index 00000000..58e7f904 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_image @@ -0,0 +1 @@ +{image: (( content.argument ))} diff --git a/patacrep/songs/chordpro/data/chordpro/content_line b/patacrep/songs/chordpro/data/chordpro/content_line new file mode 100644 index 00000000..03ca80b7 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_line @@ -0,0 +1,3 @@ +(* for item in content.line -*) + (( render(item) )) +(*- endfor *) diff --git a/patacrep/songs/chordpro/data/chordpro/content_newline b/patacrep/songs/chordpro/data/chordpro/content_newline new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_newline @@ -0,0 +1,2 @@ + + diff --git a/patacrep/songs/chordpro/data/chordpro/content_partition b/patacrep/songs/chordpro/data/chordpro/content_partition new file mode 100644 index 00000000..362c4f64 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_partition @@ -0,0 +1 @@ +{partition: ((content.argument))} diff --git a/patacrep/songs/chordpro/data/chordpro/content_space b/patacrep/songs/chordpro/data/chordpro/content_space new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_space @@ -0,0 +1 @@ + diff --git a/patacrep/songs/chordpro/data/chordpro/content_tablature b/patacrep/songs/chordpro/data/chordpro/content_tablature new file mode 100644 index 00000000..d8924b00 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_tablature @@ -0,0 +1,5 @@ +{start_of_tab} + (* for foo in content.content *) + (( foo )) + (* endfor *) +{end_of_tab} diff --git a/patacrep/songs/chordpro/data/chordpro/content_verse b/patacrep/songs/chordpro/data/chordpro/content_verse new file mode 100644 index 00000000..465e7697 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_verse @@ -0,0 +1,5 @@ +{start_of_(( content.type ))} + (* for line in content.lines *) + (( render(line) )) + (* endfor *) +{end_of_(( content.type ))} diff --git a/patacrep/songs/chordpro/data/chordpro/content_word b/patacrep/songs/chordpro/data/chordpro/content_word new file mode 100644 index 00000000..d9dd7a30 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/content_word @@ -0,0 +1 @@ +(( content.value )) diff --git a/patacrep/songs/chordpro/data/chordpro/song b/patacrep/songs/chordpro/data/chordpro/song new file mode 100644 index 00000000..95a5e492 --- /dev/null +++ b/patacrep/songs/chordpro/data/chordpro/song @@ -0,0 +1,34 @@ +(* if language is defined -*) + {language: (( language ))} +(* endif *) +(* if metadata.columns is defined -*) + {columns: (( metadata.columns ))} +(* endif *) +(* if metadata.capo is defined -*) + {capo: (( metadata.capo ))} +(* endif *) + +(*- for title in titles -*) + {title: (( title ))} +(* endfor -*) +(* for author in authors -*) + {artist: (( author[1] )) (( author[0] ))} +(* endfor *) + +(*- for key in ['album', 'copyright', 'cov', 'vcov', 'tag'] *) + (* if key in metadata -*) + {(( key )): (( metadata[key] ))} + (* endif *) +(* endfor *) + +(*- for key in metadata.keys -*) + {key: (( key.keyword )): (( key.argument ))} +(* endfor *) + +(*- for chord in metadata['define'] *) + ((- render(chord) )) +(* endfor *) + +(* for item in content -*) + (( render(item) )) +(* endfor *) diff --git a/patacrep/songs/chordpro/data/latex/content_error b/patacrep/songs/chordpro/data/latex/content_error index a41faeb5..cee78a38 100644 --- a/patacrep/songs/chordpro/data/latex/content_error +++ b/patacrep/songs/chordpro/data/latex/content_error @@ -1,3 +1,3 @@ -ERROR : Template not found for \verb+(( content.__class__))+. See the logs for details. +ERROR : Template not found for \verb+(( content.__class__.__name__ ))+. See the logs for details. diff --git a/patacrep/songs/chordpro/test/00.txt b/patacrep/songs/chordpro/test/00.txt index 8b137891..3e2185b7 100644 --- a/patacrep/songs/chordpro/test/00.txt +++ b/patacrep/songs/chordpro/test/00.txt @@ -1 +1 @@ - +{language: english} diff --git a/patacrep/songs/chordpro/test/01.txt b/patacrep/songs/chordpro/test/01.txt index 9665cac0..ae7eabc4 100644 --- a/patacrep/songs/chordpro/test/01.txt +++ b/patacrep/songs/chordpro/test/01.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_verse} - A verse line + A verse line {end_of_verse} diff --git a/patacrep/songs/chordpro/test/02.txt b/patacrep/songs/chordpro/test/02.txt index ef03158b..2a8629e0 100644 --- a/patacrep/songs/chordpro/test/02.txt +++ b/patacrep/songs/chordpro/test/02.txt @@ -1,2 +1,3 @@ +{language: english} {title: A directive} diff --git a/patacrep/songs/chordpro/test/03.txt b/patacrep/songs/chordpro/test/03.txt index 8b137891..341c9bd4 100644 --- a/patacrep/songs/chordpro/test/03.txt +++ b/patacrep/songs/chordpro/test/03.txt @@ -1 +1,2 @@ +{language: english} diff --git a/patacrep/songs/chordpro/test/04.txt b/patacrep/songs/chordpro/test/04.txt index 9e9932a3..e9c2a952 100644 --- a/patacrep/songs/chordpro/test/04.txt +++ b/patacrep/songs/chordpro/test/04.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_chorus} - A one line chorus + A one line chorus {end_of_chorus} diff --git a/patacrep/songs/chordpro/test/05.txt b/patacrep/songs/chordpro/test/05.txt index b7736212..9bc7f016 100644 --- a/patacrep/songs/chordpro/test/05.txt +++ b/patacrep/songs/chordpro/test/05.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_bridge} - A one line bridge + A one line bridge {end_of_bridge} diff --git a/patacrep/songs/chordpro/test/06.txt b/patacrep/songs/chordpro/test/06.txt index 8b137891..341c9bd4 100644 --- a/patacrep/songs/chordpro/test/06.txt +++ b/patacrep/songs/chordpro/test/06.txt @@ -1 +1,2 @@ +{language: english} diff --git a/patacrep/songs/chordpro/test/07.txt b/patacrep/songs/chordpro/test/07.txt index 3c45010c..741fee4a 100644 --- a/patacrep/songs/chordpro/test/07.txt +++ b/patacrep/songs/chordpro/test/07.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_tab} - A tab + A tab {end_of_tab} diff --git a/patacrep/songs/chordpro/test/08.txt b/patacrep/songs/chordpro/test/08.txt index d224789c..61224d41 100644 --- a/patacrep/songs/chordpro/test/08.txt +++ b/patacrep/songs/chordpro/test/08.txt @@ -1,4 +1,7 @@ +{language: english} + + {start_of_verse} - A lot of new lines + A lot of new lines {end_of_verse} diff --git a/patacrep/songs/chordpro/test/09.txt b/patacrep/songs/chordpro/test/09.txt index 6d19ba36..942a91e1 100644 --- a/patacrep/songs/chordpro/test/09.txt +++ b/patacrep/songs/chordpro/test/09.txt @@ -1,5 +1,8 @@ +{language: english} {title: and a directive} + + {start_of_verse} - A lot of new lines + A lot of new lines {end_of_verse} diff --git a/patacrep/songs/chordpro/test/10.txt b/patacrep/songs/chordpro/test/10.txt index c289fda9..23bce4fa 100644 --- a/patacrep/songs/chordpro/test/10.txt +++ b/patacrep/songs/chordpro/test/10.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_verse} - A line[A] with a chord + A line[A] with a chord {end_of_verse} diff --git a/patacrep/songs/chordpro/test/11.txt b/patacrep/songs/chordpro/test/11.txt index ccf1d520..79d44702 100644 --- a/patacrep/songs/chordpro/test/11.txt +++ b/patacrep/songs/chordpro/test/11.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_verse} - A line ending with a chord[A] + A line ending with a chord[A] {end_of_verse} diff --git a/patacrep/songs/chordpro/test/12.txt b/patacrep/songs/chordpro/test/12.txt index 72a5b745..6afb5bf8 100644 --- a/patacrep/songs/chordpro/test/12.txt +++ b/patacrep/songs/chordpro/test/12.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_verse} - [A]A line starting with a chord + [A]A line starting with a chord {end_of_verse} diff --git a/patacrep/songs/chordpro/test/13.txt b/patacrep/songs/chordpro/test/13.txt index b2f0526f..a2b60a5e 100644 --- a/patacrep/songs/chordpro/test/13.txt +++ b/patacrep/songs/chordpro/test/13.txt @@ -1,6 +1,7 @@ +{language: english} {start_of_tab} - A table - wit many # weir [ - [ symbols + A table + wit many # weir [ + [ symbols {end_of_tab} diff --git a/patacrep/songs/chordpro/test/21.txt b/patacrep/songs/chordpro/test/21.txt index 9665cac0..ae7eabc4 100644 --- a/patacrep/songs/chordpro/test/21.txt +++ b/patacrep/songs/chordpro/test/21.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_verse} - A verse line + A verse line {end_of_verse} diff --git a/patacrep/songs/chordpro/test/22.txt b/patacrep/songs/chordpro/test/22.txt index ef03158b..2a8629e0 100644 --- a/patacrep/songs/chordpro/test/22.txt +++ b/patacrep/songs/chordpro/test/22.txt @@ -1,2 +1,3 @@ +{language: english} {title: A directive} diff --git a/patacrep/songs/chordpro/test/23.txt b/patacrep/songs/chordpro/test/23.txt index 8b137891..3e2185b7 100644 --- a/patacrep/songs/chordpro/test/23.txt +++ b/patacrep/songs/chordpro/test/23.txt @@ -1 +1 @@ - +{language: english} diff --git a/patacrep/songs/chordpro/test/24.txt b/patacrep/songs/chordpro/test/24.txt index 9e9932a3..e9c2a952 100644 --- a/patacrep/songs/chordpro/test/24.txt +++ b/patacrep/songs/chordpro/test/24.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_chorus} - A one line chorus + A one line chorus {end_of_chorus} diff --git a/patacrep/songs/chordpro/test/25.txt b/patacrep/songs/chordpro/test/25.txt index b7736212..9bc7f016 100644 --- a/patacrep/songs/chordpro/test/25.txt +++ b/patacrep/songs/chordpro/test/25.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_bridge} - A one line bridge + A one line bridge {end_of_bridge} diff --git a/patacrep/songs/chordpro/test/26.txt b/patacrep/songs/chordpro/test/26.txt index 8b137891..341c9bd4 100644 --- a/patacrep/songs/chordpro/test/26.txt +++ b/patacrep/songs/chordpro/test/26.txt @@ -1 +1,2 @@ +{language: english} diff --git a/patacrep/songs/chordpro/test/27.txt b/patacrep/songs/chordpro/test/27.txt index 3c45010c..741fee4a 100644 --- a/patacrep/songs/chordpro/test/27.txt +++ b/patacrep/songs/chordpro/test/27.txt @@ -1,4 +1,5 @@ +{language: english} {start_of_tab} - A tab + A tab {end_of_tab} diff --git a/patacrep/songs/chordpro/test/28.txt b/patacrep/songs/chordpro/test/28.txt index d224789c..61224d41 100644 --- a/patacrep/songs/chordpro/test/28.txt +++ b/patacrep/songs/chordpro/test/28.txt @@ -1,4 +1,7 @@ +{language: english} + + {start_of_verse} - A lot of new lines + A lot of new lines {end_of_verse} diff --git a/patacrep/songs/chordpro/test/29.txt b/patacrep/songs/chordpro/test/29.txt index 6d19ba36..942a91e1 100644 --- a/patacrep/songs/chordpro/test/29.txt +++ b/patacrep/songs/chordpro/test/29.txt @@ -1,5 +1,8 @@ +{language: english} {title: and a directive} + + {start_of_verse} - A lot of new lines + A lot of new lines {end_of_verse} diff --git a/patacrep/songs/chordpro/test/chords.txt b/patacrep/songs/chordpro/test/chords.txt index 2a98ce94..955f44d6 100644 --- a/patacrep/songs/chordpro/test/chords.txt +++ b/patacrep/songs/chordpro/test/chords.txt @@ -1,16 +1,17 @@ +{language: english} {start_of_verse} - [A]Simple - [Bb]Bémol - [C#]Dièse - [Adim]dim - [Dmaj]maj - [Em3]m chiffre - [G4]Nombre - [Emaj3]maj et nombre - [Absus8]bémol, sus et nombre - [A/A]Deux notes - [F/Fb]Deux notes, bémol - [B/C#]Deux notes, dièse - [Ab B#/A]Plusieurs notes à la suite + [A]Simple + [Bb]Bémol + [C#]Dièse + [Adim]dim + [Dmaj]maj + [Em3]m chiffre + [G4]Nombre + [Emaj3]maj et nombre + [Absus8]bémol, sus et nombre + [A/A]Deux notes + [F/Fb]Deux notes, bémol + [B/C#]Deux notes, dièse + [Ab B#/A]Plusieurs notes à la suite {end_of_verse} diff --git a/patacrep/songs/chordpro/test/customchords.txt b/patacrep/songs/chordpro/test/customchords.txt index 52c9f0e3..1148a901 100644 --- a/patacrep/songs/chordpro/test/customchords.txt +++ b/patacrep/songs/chordpro/test/customchords.txt @@ -1,3 +1,3 @@ +{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 - -} - diff --git a/patacrep/songs/chordpro/test/greensleeves.txt b/patacrep/songs/chordpro/test/greensleeves.txt index 538a146d..98248e83 100644 --- a/patacrep/songs/chordpro/test/greensleeves.txt +++ b/patacrep/songs/chordpro/test/greensleeves.txt @@ -1,52 +1,60 @@ +{language: english} +{columns: 2} {title: Greensleeves} {title: Un autre sous-titre} {title: Un sous titre} -{by: Traditionnel} -{language: english} -{columns: 2} -{cov: DIRNAME/traditionnel} +{artist: Traditionnel} {album: Angleterre} +{cov: DIRNAME/traditionnel} + + {partition: DIRNAME/greensleeves.ly} + {start_of_verse} - A[Am]las, my love, ye [G]do me wrong - To [Am]cast me oft dis[E]curteously - And [Am]I have loved [G]you so long - De[Am]lighting [E]in your [Am]companie + A[Am]las, my love, ye [G]do me wrong + To [Am]cast me oft dis[E]curteously + And [Am]I have loved [G]you so long + De[Am]lighting [E]in your [Am]companie {end_of_verse} + {start_of_chorus} - [C]Green[B]sleeves was [G]all my joy - [Am]Greensleeves was [E]my delight - [C]Greensleeves was my [G]heart of gold - And [Am]who but [E]Ladie [Am]Greensleeves + [C]Green[B]sleeves was [G]all my joy + [Am]Greensleeves was [E]my delight + [C]Greensleeves was my [G]heart of gold + And [Am]who but [E]Ladie [Am]Greensleeves {end_of_chorus} + {start_of_verse} - I [Am]have been ready [G]at your hand - To [Am]grant what ever [E]you would crave - I [Am]have both waged [G]life and land - Your [Am]love and [E]good will [Am]for to have + I [Am]have been ready [G]at your hand + To [Am]grant what ever [E]you would crave + I [Am]have both waged [G]life and land + Your [Am]love and [E]good will [Am]for to have {end_of_verse} + {start_of_verse} - I [Am]bought thee kerchers [G]to thy head - That [Am]were wrought fine and [E]gallantly - I [Am]kept thee both at [G]boord and bed - Which [Am]cost my [E]purse well [Am]favouredly + I [Am]bought thee kerchers [G]to thy head + That [Am]were wrought fine and [E]gallantly + I [Am]kept thee both at [G]boord and bed + Which [Am]cost my [E]purse well [Am]favouredly {end_of_verse} + {start_of_verse} - I [Am]bought thee peticotes [G]of the best - The [Am]cloth so fine as [E]fine might be - I [Am]gave thee jewels [G]for thy chest - And [Am]all this [E]cost I [Am]spent on thee + I [Am]bought thee peticotes [G]of the best + The [Am]cloth so fine as [E]fine might be + I [Am]gave thee jewels [G]for thy chest + And [Am]all this [E]cost I [Am]spent on thee {end_of_verse} + {start_of_verse} - Thy [Am]smock of silke, both [G]faire and white - With [Am]gold embrodered [E]gorgeously - Thy [Am]peticote of [G]sendall right - And [Am]this I [E]bought thee [Am]gladly + Thy [Am]smock of silke, both [G]faire and white + With [Am]gold embrodered [E]gorgeously + Thy [Am]peticote of [G]sendall right + And [Am]this I [E]bought thee [Am]gladly {end_of_verse} diff --git a/patacrep/songs/chordpro/test/invalid_chord.txt b/patacrep/songs/chordpro/test/invalid_chord.txt index e72a02d0..2a17e6e7 100644 --- a/patacrep/songs/chordpro/test/invalid_chord.txt +++ b/patacrep/songs/chordpro/test/invalid_chord.txt @@ -1,6 +1,7 @@ +{language: english} {start_of_verse} - This is invalid. - This [A]too. - And []as well. + This is invalid. + This [A]too. + And []as well. {end_of_verse} diff --git a/patacrep/songs/chordpro/test/invalid_customchord.txt b/patacrep/songs/chordpro/test/invalid_customchord.txt index e69de29b..341c9bd4 100644 --- a/patacrep/songs/chordpro/test/invalid_customchord.txt +++ b/patacrep/songs/chordpro/test/invalid_customchord.txt @@ -0,0 +1,2 @@ +{language: english} + diff --git a/patacrep/songs/chordpro/test/metadata.sgc b/patacrep/songs/chordpro/test/metadata.sgc index eee1bf9d..6e221446 100644 --- a/patacrep/songs/chordpro/test/metadata.sgc +++ b/patacrep/songs/chordpro/test/metadata.sgc @@ -8,7 +8,7 @@ {language: english} {by: Author1} {artist: Author2} -{album: Albom} +{album: Album} {copyright: Copyright} {cover: Cover} {vcover: VCover} diff --git a/patacrep/songs/chordpro/test/metadata.txt b/patacrep/songs/chordpro/test/metadata.txt index 77b9d08b..45509d2d 100644 --- a/patacrep/songs/chordpro/test/metadata.txt +++ b/patacrep/songs/chordpro/test/metadata.txt @@ -1,19 +1,18 @@ +{language: french} +{capo: Capo} {title: Title} {title: Subtitle1} {title: Subtitle2} {title: Subtitle3} {title: Subtitle4} {title: Subtitle5} -{by: Author1} -{by: Author2} -{key: {foo: Foo}} -{language: french} -{language: english} -{album: Albom} +{artist: Author1} +{artist: Author2} +{album: Album} {copyright: Copyright} {cov: DIRNAME/Cover} {vcov: VCover} -{capo: Capo} +{key: foo: Foo} {comment: Comment} {guitar_comment: GuitarComment} diff --git a/patacrep/songs/chordpro/test/test_parser.py b/patacrep/songs/chordpro/test/test_parser.py index ff2b628f..c82338b3 100644 --- a/patacrep/songs/chordpro/test/test_parser.py +++ b/patacrep/songs/chordpro/test/test_parser.py @@ -6,7 +6,8 @@ import glob import os import unittest -from patacrep.songs.chordpro import syntax as chordpro +from patacrep.build import DEFAULT_CONFIG +from patacrep.songs.chordpro import ChordproSong class ParserTxtRenderer(unittest.TestCase): """Test parser, and renderer as a txt file.""" @@ -26,15 +27,17 @@ class ParserTxtRenderer(unittest.TestCase): if self.basename is None: return - with open("{}.sgc".format(self.basename), 'r', encoding='utf8') as sourcefile: - with open("{}.txt".format(self.basename), 'r', encoding='utf8') as expectfile: - self.assertMultiLineEqual( - chordpro.parse_song( - sourcefile.read(), - os.path.abspath(sourcefile.name), - ).chordpro().strip(), - expectfile.read().strip().replace("DIRNAME", os.path.dirname(self.basename)), - ) + config = DEFAULT_CONFIG.copy() + config.update({ + 'encoding': 'utf8', + '_compiled_authwords': {}, + }) + with open("{}.txt".format(self.basename), 'r', encoding='utf8') as expectfile: + chordproname = "{}.sgc".format(self.basename) + self.assertMultiLineEqual( + ChordproSong(None, chordproname, config).render(output=chordproname, output_format="chordpro").strip(), + expectfile.read().strip().replace("DIRNAME", os.path.dirname(self.basename)).strip(), + ) def load_tests(__loader, tests, __pattern): """Load several tests given test files present in the directory.""" diff --git a/patacrep/songs/syntax.py b/patacrep/songs/syntax.py index 00768019..7f019374 100644 --- a/patacrep/songs/syntax.py +++ b/patacrep/songs/syntax.py @@ -21,13 +21,18 @@ class Parser: return column @staticmethod - def error(*, line, column=None, message=""): + def error(*, line=None, column=None, message=""): """Display an error message""" - text = "Line {}".format(line) + coordinates = [] + if line is not None: + coordinates.append("line {}".format(line)) if column is not None: - text += ", column {}".format(column) - if message: + coordinates.append("column {}".format(column)) + text = ", ".join(coordinates) + if message and text: text += ": " + message + elif message: + text += message else: text += "." LOGGER.error(text) @@ -36,7 +41,6 @@ class Parser: """Manage parsing errors.""" if token is None: self.error( - line=token.lineno, message="Unexpected end of file.", ) else: