Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of echo with chords inside #205

Merged
merged 1 commit into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions patacrep/data/templates/songs/chordpro/chordpro/content_echo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{start_(( content.type ))}
((- render(content.line) -))
{end_(( content.type ))}
3 changes: 3 additions & 0 deletions patacrep/data/templates/songs/chordpro/latex/content_echo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\echo{
((- render(content.line) -))
}
9 changes: 9 additions & 0 deletions patacrep/songs/chordpro/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ def is_empty(self):
"""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
Expand Down
12 changes: 12 additions & 0 deletions patacrep/songs/chordpro/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
'EOB',
'SOT',
'EOT',
'SE',
'EE',
)

class ChordProLexer:
Expand Down Expand Up @@ -69,6 +71,16 @@ def t_EOB(token):
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')
Expand Down
7 changes: 7 additions & 0 deletions patacrep/songs/chordpro/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def p_line_error(self, symbols):
def p_line(symbols):
"""line : word line_next
| chord line_next
| echo line_next
| directive maybespace
"""
if isinstance(symbols[2], ast.Line):
Expand All @@ -227,6 +228,7 @@ def p_line_next(symbols):
"""line_next : word line_next
| space line_next
| chord line_next
| echo line_next
| empty
"""
if len(symbols) == 2:
Expand Down Expand Up @@ -289,6 +291,11 @@ def p_bridge_content(symbols):
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):
Expand Down
29 changes: 29 additions & 0 deletions test/test_song/echo.csg
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions test/test_song/echo.csg.source
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions test/test_song/echo.tsg
Original file line number Diff line number Diff line change
@@ -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