Browse Source

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

[ci skip]
pull/213/head
Louis 9 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', 'EE',
) )
literals = [ '{', '}', "\\", ' ' ]
class ChordProLexer: class ChordProLexer:
"""ChordPro Lexer class""" """ChordPro Lexer class"""
# pylint: disable=too-many-public-methods # pylint: disable=too-many-public-methods
@ -51,7 +49,7 @@ class ChordProLexer:
t_directive_SPACE = r'[ \t]+' t_directive_SPACE = r'[ \t]+'
t_directive_KEYWORD = r'[a-zA-Z_]+' t_directive_KEYWORD = r'[a-zA-Z_]+'
t_directiveargument_TEXT = r'[^}]+' t_directiveargument_TEXT = r'[^\\}]+'
@staticmethod @staticmethod
def t_SOC(token): def t_SOC(token):
@ -120,7 +118,7 @@ class ChordProLexer:
@staticmethod @staticmethod
def t_WORD(token): def t_WORD(token):
r'[^{}\r\n\]\[\t ]+' r'[^{}\\\r\n\]\[\t ]+'
return token return token
def t_LBRACKET(self, __token): def t_LBRACKET(self, __token):
@ -153,10 +151,18 @@ class ChordProLexer:
return token return token
@staticmethod @staticmethod
def t_literal(token): def t_ESCAPED(token):
r'\[{} \#]' r'\\[{} #\\]'
t.type = t.type[1] token.value = token.value[1]
return t 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=""): def error(self, token, more=""):
"""Display error message, and skip illegal token.""" """Display error message, and skip illegal token."""

15
patacrep/songs/chordpro/syntax.py

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