Browse Source

Support of echo with chords inside

pull/205/head
Oliverpool 8 years ago
parent
commit
536c0247ac
  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 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):
"""Something present on a line."""
# pylint: disable=abstract-method

12
patacrep/songs/chordpro/lexer.py

@ -26,6 +26,8 @@ tokens = (
'EOB',
'SOT',
'EOT',
'SE',
'EE',
)
class ChordProLexer:
@ -69,6 +71,16 @@ class ChordProLexer:
r'{(eob|end_of_bridge)}'
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):
r'{(sot|start_of_tab)}'
self.lexer.push_state('tablature')

7
patacrep/songs/chordpro/syntax.py

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