In the GIT repository for PLY, I refactored a bit of the error
handling code to simplify a few things, but I think I could be
convinced to expand it a bit more.    Let me think about how I would
handle it.   Perhaps p_error() handling could be expanded to support
an optional second argument in which the parser instance would be
passed.   Certainly open to design ideas on this.
Cheers,Dave

----- Original Message -----
From: [email protected]
To:
Cc:
Sent:Sun, 28 Oct 2012 19:15:14 -0700 (PDT)
Subject:p_error parameters lack information

 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 [1], p.value) [2]

     #Ugly hack since Ply doesn't provide any useful error
information
     import inspect
     frame = inspect.currentframe() [3]
     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 [email protected] [4].
 To unsubscribe from this group, send email to
[email protected] [5].
 To view this discussion on the web visit
https://groups.google.com/d/msg/ply-hack/-/lohTjGaPdqgJ [6].
 For more options, visit https://groups.google.com/groups/opt_out
[7].
  
  


Links:
------
[1] http://p.lineno
[2] http://sitemail.hostway.com/http:
[3] http://sitemail.hostway.com/http:
[4] mailto:[email protected]
[5] mailto:[email protected]
[6] https://groups.google.com/d/msg/ply-hack/-/lohTjGaPdqgJ
[7] 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to