Robert Grosse
2012-10-29 02:15:14 UTC
One can define a p_error function to handle syntax errors, but
unfortunately, Ply provides no useful information to the function. I've had
to resort to an ugly reflection hack just to provide meaningful error
messages. Would it be possible to improve the interface so that Ply
actually provides access to this information?
def p_error(p):
if p is None:
print "Syntax error: unexpected EOF"
else:
print "Syntax error at line {}: unexpected token
{}".format(p.lineno, p.value)
#Ugly hack since Ply doesn't provide any useful error information
import inspect
frame = inspect.currentframe()
cvars = frame.f_back.f_locals
print 'Expected:', ', '.join(cvars['actions'][cvars[
'state']].keys())
print 'Found:', cvars['ltype']
print 'Current stack:', cvars['symstack']
unfortunately, Ply provides no useful information to the function. I've had
to resort to an ugly reflection hack just to provide meaningful error
messages. Would it be possible to improve the interface so that Ply
actually provides access to this information?
def p_error(p):
if p is None:
print "Syntax error: unexpected EOF"
else:
print "Syntax error at line {}: unexpected token
{}".format(p.lineno, p.value)
#Ugly hack since Ply doesn't provide any useful error information
import inspect
frame = inspect.currentframe()
cvars = frame.f_back.f_locals
print 'Expected:', ', '.join(cvars['actions'][cvars[
'state']].keys())
print 'Found:', cvars['ltype']
print 'Current stack:', cvars['symstack']
--
You received this message because you are subscribed to the Google Groups "ply-hack" group.
To post to this group, send email to ply-***@googlegroups.com.
To unsubscribe from this group, send email to ply-hack+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/ply-hack/-/lohTjGaPdqgJ.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "ply-hack" group.
To post to this group, send email to ply-***@googlegroups.com.
To unsubscribe from this group, send email to ply-hack+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/ply-hack/-/lohTjGaPdqgJ.
For more options, visit https://groups.google.com/groups/opt_out.