Arian Sameni
unread,Nov 18, 2009, 9:30:59 AM11/18/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ply-hack
Hi everyone,
Just joined the group. I'm using PLY, and wanted to make a proposition
(actually a very little but useful one).
I have modified ply/lex.py to be able to know in which column the
lexer is working, so, in case of error, we can display a more specific
message, like "An error ocurred on line X, column Y".
I added an attribute to class Lexer (ply/lex.py). Line 139 now looks
like:
self.current = -1
Then, in the "new line" rule (lexer implementation file, something
like my_lexer.py), we update the value of lexer.current:
t.lexer.lineno += len(t.value) # Just like before
t.lexer.current = t.lexer.lexpos - 1 # Added new
And when error (error rule):
print 'ERROR: line ' + str(t.lexer.lineno) + \
', column: ' + str(t.lexer.lexpos - t.lexer.current) +
\
'. Character not recognised: ' + t.value[0]
t.lexer.skip(1)
It's quite simple, but I didn't find any column track in the lexer, so
I just wanted to share my trick with you. I hope its clear.
Best regards :D and nice job!!