Detect strings and end-of-lines.

This commit is contained in:
Jussi Pakkanen 2012-12-23 17:09:28 +02:00
parent 802d56d135
commit 57cbee2f33
1 changed files with 9 additions and 3 deletions

View File

@ -24,7 +24,10 @@ tokens = ['LPAREN',
'EQUALS',
'COMMA',
'DOT',
'STRING']
'STRING',
'EOL_CONTINUE',
'EOL',
]
t_EQUALS = '='
t_LPAREN = '\('
@ -34,8 +37,10 @@ t_COMMENT = '\#[^\n]*'
t_COMMA = ','
t_DOT = '\.'
t_STRING = "'[^']*'"
t_EOL_CONTINUE = r'\\\n'
t_EOL = r'\n'
t_ignore = ' \t\n'
t_ignore = ' \t'
def t_error(t):
print("Illegal character '%s'" % t.value[0])
@ -44,7 +49,8 @@ def t_error(t):
def test_lexer():
s = """hello = (something) # this = (that)
function(h)
obj.method(lll, 'string')
obj.method(lll, \\
'string')
"""
lexer = lex.lex()
lexer.input(s)