|
@ -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.""" |
|
|