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!!
--
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en.