haoxiang47 / ply

Automatically exported from code.google.com/p/ply
0 stars 0 forks source link

Negative indexes no longer work in PLY #23

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use a query production like:

def p_query(p):
    '''query : query_part'''
    p[0] = Query(p[-1])

What is the expected output? What do you see instead?
This used to work in PLY 2.5.  I found that it no longer works in PLY 3.3 when 
I upgraded today.  Instead, I get the exception:
    AttributeError: YaccSymbol instance has no attribute 'value'

It is possible to use p[1] rather than p[-1], and perhaps this is actually a 
better way of doing it, but I thought it was worth noting since this was a 
change that broke existing code.

Original issue reported on code.google.com by jonmmor...@gmail.com on 31 Jul 2010 at 5:48

GoogleCodeExporter commented 8 years ago
What are you expecting to happen in this example?    If you are expecting p[-1] 
to refer to the query_part component, then this is wrong.   Negative indices 
are used to refer to symbols further down the parsing stack and are mainly used 
in the context of writing embedded actions.  See section 6.11 of the PLY docs.

I know that there was a bug in negative indices that was fixed in PLY-3.0 
(according to the CHANGES log anyways).

Original comment by dbeaz...@gmail.com on 31 Jul 2010 at 11:46

GoogleCodeExporter commented 8 years ago
It's quite possible it is a bug that was fixed: I inherited this code and don't 
know why it was written that way.  All I am saying is that behaviour changed, 
and I wasn't not sure whether it was intentional or not.  I think using p[1] 
makes much more sense, changed it to do that, and PLY 3.3 seems to work fine.

Original comment by jonmmor...@gmail.com on 31 Jul 2010 at 1:06