I have defined a p_error(p) function. For some parse errors, p (a
LexToken) has a 'lexer' attribute. For other parse errors, p (still a
LexToken) does not have a 'lexer' attribute. If I set a break point
with pdb within p_error(), the stack traces look the same for both
types of parse errors.
Any idea why the LexToken argument to p_error() would lack the 'lexer'
attribute at times?
--- ./lex.py.orig 2008-09-24 09:51:26.000000000 -0600
+++ ./lex.py 2008-09-24 09:52:32.000000000 -0600
@@ -281,6 +281,7 @@
# Create a token for return
tok = LexToken()
+ tok.lexer = self
tok.value = m.group()
tok.lineno = self.lineno
tok.lexpos = lexpos
@@ -305,7 +306,7 @@
# If token is processed by a function, call it
- tok.lexer = self # Set additional attributes
useful in token rules
+ # Set additional attributes useful in token rules
self.lexmatch = m
self.lexpos = lexpos
@@ -329,6 +330,7 @@
# No match, see if in literals
if lexdata[lexpos] in self.lexliterals:
tok = LexToken()
+ tok.lexer = self
tok.value = lexdata[lexpos]
tok.lineno = self.lineno
tok.type = tok.value