how does ' ' match empty string?

49 views
Skip to first unread message

inhahe

unread,
Apr 28, 2008, 6:39:33 AM4/28/08
to ply-hack
hi, i'm getting an error in ply (the lexer) that i don't understand.

pylex.py:54: Regular expression for rule 't_SPACE' matches empty
string.

here's t_SPACE:

def t_SPACE(t):
' '
if t.lexer.lexdata[t.lexer.lastlf:t.lexer.lexpos].strip()=='':
t.lexer.indent = t.lexer.lexpos-t.lastlf


so my question is.. how does ' ' match ''?

first guess is maybe it has something do do the parser only caring
about everything but spaces and perhaps treating spaces idempotently

but i don't know how to do what i want.

David Beazley

unread,
Apr 28, 2008, 8:55:04 AM4/28/08
to ply-hack, inhahe
The regular expression that gets compiled by PLY is compiled with the re.VERBOSE flag turned on. If you want to match spaces, you'll need to use a different regular
expression than simply enclosing a space in quotes. For example:

def t_SPACE(t):
r'[ ]'
...


Cheers,
Dave


On Mon 28/04/08 6:39 AM , inhahe inh...@gmail.com sent:

Reply all
Reply to author
Forward
0 new messages