User defined p_error() is not called.

11 views
Skip to first unread message

Bart Whiteley

unread,
Feb 15, 2008, 1:19:07 PM2/15/08
to ply-hack
I have defined a p_error(p) function, but it does not get called.  When a syntax error occurs, I see this instead:
  yacc: Syntax error at line ##, token=<token>

Does anyone have a suggestion about what I can do to determine why my p_error() is not called?

David Beazley

unread,
Feb 15, 2008, 2:24:09 PM2/15/08
to ply-...@googlegroups.com
What version of PLY is this?

-D

Bart Whiteley

unread,
Feb 15, 2008, 2:39:52 PM2/15/08
to ply-...@googlegroups.com
2.3

David Beazley

unread,
Feb 15, 2008, 2:44:15 PM2/15/08
to ply-...@googlegroups.com
I'll need some specifics to know what is wrong. What is the
definition of p_error? Has a corresponding t_error() function been
defined?

-D

Bart Whiteley

unread,
Feb 15, 2008, 3:51:24 PM2/15/08
to ply-...@googlegroups.com
# Error handling rule
def t_error(t):
    msg = "Illegal character '%s' " % t.value[0]
    msg+= "Line %d, col %d" % (t.lineno, _find_column(t.lexer.parser.mof, t))
    t.lexer.parser.log(msg)
    t.lexer.skip(1)

def p_error(p):
    print '*******GOT HERE'
    p.parser.log('Syntax Error in input!')
    p.parser.log(p)
    p.parser.log('column: '+ _find_column(p.lexer.parser.mof, p))

The full code can be found here:
http://pywbem.svn.sourceforge.net/viewvc/pywbem/pywbem/trunk/mof_compiler.py?view=markup

Bart Whiteley

unread,
Feb 19, 2008, 5:51:44 PM2/19/08
to ply-...@googlegroups.com
I observed that my user defined p_error() does get called if the parsetab.py needs to be generated.  If there is an up-to-date parsetab.py, my user defined p_error() is not called. 

I came up with the attached patch. 

yacc.py.diff
Reply all
Reply to author
Forward
0 new messages