Browse Source

[WIP] Escaped characters are correctly parsed. They now have to be correctly rendered

[ci skip]
pull/213/head
Louis 8 years ago
parent
commit
da9215aacd
  1. 22
      patacrep/songs/chordpro/lexer.py
  2. 15
      patacrep/songs/chordpro/syntax.py
  3. 10
      test/test_song/latex.csg

22
patacrep/songs/chordpro/lexer.py

@ -30,8 +30,6 @@ tokens = (
'EE',
)
literals = [ '{', '}', "\\", ' ' ]
class ChordProLexer:
"""ChordPro Lexer class"""
# pylint: disable=too-many-public-methods
@ -51,7 +49,7 @@ class ChordProLexer:
t_directive_SPACE = r'[ \t]+'
t_directive_KEYWORD = r'[a-zA-Z_]+'
t_directiveargument_TEXT = r'[^}]+'
t_directiveargument_TEXT = r'[^\\}]+'
@staticmethod
def t_SOC(token):
@ -120,7 +118,7 @@ class ChordProLexer:
@staticmethod
def t_WORD(token):
r'[^{}\r\n\]\[\t ]+'
r'[^{}\\\r\n\]\[\t ]+'
return token
def t_LBRACKET(self, __token):
@ -153,10 +151,18 @@ class ChordProLexer:
return token
@staticmethod
def t_literal(token):
r'\[{} \#]'
t.type = t.type[1]
return t
def t_ESCAPED(token):
r'\\[{} #\\]'
token.value = token.value[1]
token.type = "WORD"
return token
@staticmethod
def t_directiveargument_ESCAPED(token):
r'\\[{} #\\]'
token.value = token.value[1]
token.type = "TEXT"
return token
def error(self, token, more=""):
"""Display error message, and skip illegal token."""

15
patacrep/songs/chordpro/syntax.py

@ -182,9 +182,8 @@ class ChordproParser(Parser):
@staticmethod
def p_directive_next(symbols):
"""directive_next : SPACE COLON TEXT
| COLON TEXT
| COLON
"""directive_next : SPACE COLON directive_argument
| COLON directive_argument
| empty
"""
if len(symbols) == 3:
@ -196,6 +195,16 @@ class ChordproParser(Parser):
else:
symbols[0] = None
@staticmethod
def p_directive_argument(symbols):
"""directive_argument : TEXT directive_argument
| empty
"""
if len(symbols) == 3:
symbols[0] = symbols[1] + symbols[2]
else:
symbols[0] = ""
def p_line_error(self, symbols):
"""line_error : error directive"""
self.error(

10
test/test_song/latex.csg

@ -0,0 +1,10 @@
{lang: en}
{title: & $ % # _ \} \{ ~ ^ \\}
{artist: & $ % # _ \} \{ ~ ^ \\}
{album: & $ % # _ \} \{ ~ ^ \\}
& $ % \# _ \} \{ ~ ^ \\
{start_of_chorus}
& $ % \# _ \} \{ ~ ^ \\
{end_of_chorus}
Loading…
Cancel
Save