Browse Source

Merge pull request #205 from patacrep/echo_support

Support of echo with chords inside

Closes #119.
pull/209/head
Louis 9 years ago
parent
commit
d03b42b5c6
  1. 3
      patacrep/data/templates/songs/chordpro/chordpro/content_echo
  2. 3
      patacrep/data/templates/songs/chordpro/latex/content_echo
  3. 9
      patacrep/songs/chordpro/ast.py
  4. 12
      patacrep/songs/chordpro/lexer.py
  5. 7
      patacrep/songs/chordpro/syntax.py
  6. 29
      test/test_song/echo.csg
  7. 20
      test/test_song/echo.csg.source
  8. 49
      test/test_song/echo.tsg

3
patacrep/data/templates/songs/chordpro/chordpro/content_echo

@ -0,0 +1,3 @@
{start_(( content.type ))}
((- render(content.line) -))
{end_(( content.type ))}

3
patacrep/data/templates/songs/chordpro/latex/content_echo

@ -0,0 +1,3 @@
\echo{
((- render(content.line) -))
}

9
patacrep/songs/chordpro/ast.py

@ -122,6 +122,15 @@ class Line(AST):
"""Return `True` iff line is empty.""" """Return `True` iff line is empty."""
return len(self.strip().line) == 0 return len(self.strip().line) == 0
class Echo(AST):
"""An inline echo"""
_template = "echo"
type = 'echo'
def __init__(self, line):
super().__init__()
self.line = line
class LineElement(AST): class LineElement(AST):
"""Something present on a line.""" """Something present on a line."""
# pylint: disable=abstract-method # pylint: disable=abstract-method

12
patacrep/songs/chordpro/lexer.py

@ -26,6 +26,8 @@ tokens = (
'EOB', 'EOB',
'SOT', 'SOT',
'EOT', 'EOT',
'SE',
'EE',
) )
class ChordProLexer: class ChordProLexer:
@ -69,6 +71,16 @@ class ChordProLexer:
r'{(eob|end_of_bridge)}' r'{(eob|end_of_bridge)}'
return token return token
@staticmethod
def t_SE(token):
r'{(se|start_echo)}'
return token
@staticmethod
def t_EE(token):
r'{(ee|end_echo)}'
return token
def t_SOT(self, token): def t_SOT(self, token):
r'{(sot|start_of_tab)}' r'{(sot|start_of_tab)}'
self.lexer.push_state('tablature') self.lexer.push_state('tablature')

7
patacrep/songs/chordpro/syntax.py

@ -208,6 +208,7 @@ class ChordproParser(Parser):
def p_line(symbols): def p_line(symbols):
"""line : word line_next """line : word line_next
| chord line_next | chord line_next
| echo line_next
| directive maybespace | directive maybespace
""" """
if isinstance(symbols[2], ast.Line): if isinstance(symbols[2], ast.Line):
@ -227,6 +228,7 @@ class ChordproParser(Parser):
"""line_next : word line_next """line_next : word line_next
| space line_next | space line_next
| chord line_next | chord line_next
| echo line_next
| empty | empty
""" """
if len(symbols) == 2: if len(symbols) == 2:
@ -289,6 +291,11 @@ class ChordproParser(Parser):
else: else:
symbols[0] = symbols[3].prepend(symbols[1]) symbols[0] = symbols[3].prepend(symbols[1])
@staticmethod
def p_echo(symbols):
"""echo : SE line_next EE
"""
symbols[0] = ast.Echo(symbols[2])
@staticmethod @staticmethod
def p_tab(symbols): def p_tab(symbols):

29
test/test_song/echo.csg

@ -0,0 +1,29 @@
{lang: en}
Soon an echo {start_echo}with chords: [C]cool [A]isn't it?{end_echo}
Second example {start_echo} surrounded with spaces {end_echo} continuing
Third example {start_echo} on{end_echo}
{start_echo}multiple lines ! {end_echo} continuing
{start_echo}Fourth example starting line {end_echo} continuing
Fifth example at the {start_echo}end{end_echo}
{start_echo}Sixth example: only me!{end_echo}
{start_of_chorus}
{start_echo}Seventh example in a chorus{end_echo}
{end_of_chorus}
{start_of_bridge}
And in a {start_echo}bridge{end_echo}
{end_of_bridge}

20
test/test_song/echo.csg.source

@ -0,0 +1,20 @@
Soon an echo {start_echo}with chords: [C]cool [A]isn't it?{end_echo}
Second example {start_echo} surrounded with spaces {end_echo} continuing
Third example {start_echo} on{end_echo}
{start_echo}multiple lines ! {end_echo} continuing
{start_echo}Fourth example starting line {end_echo} continuing
Fifth example at the {start_echo}end{end_echo}
{start_echo}Sixth example: only me!{end_echo}
{soc}
{start_echo}Seventh example in a chorus{end_echo}
{eoc}
{sob}
And in a {start_echo}bridge{end_echo}
{eob}

49
test/test_song/echo.tsg

@ -0,0 +1,49 @@
\selectlanguage{english}
\beginsong{}[
by={
},
]
\begin{verse}
Soon an echo \echo{with chords: \[C]cool \[A]isn't it?}
\end{verse}
\begin{verse}
Second example \echo{ surrounded with spaces } continuing
\end{verse}
\begin{verse}
Third example \echo{ on}
\echo{multiple lines ! } continuing
\end{verse}
\begin{verse}
\echo{Fourth example starting line } continuing
\end{verse}
\begin{verse}
Fifth example at the \echo{end}
\end{verse}
\begin{verse}
\echo{Sixth example: only me!}
\end{verse}
\begin{chorus}
\echo{Seventh example in a chorus}
\end{chorus}
\begin{bridge}
And in a \echo{bridge}
\end{bridge}
\endsong
Loading…
Cancel
Save