Commit 24cdbff2 authored by Stefan Behnel's avatar Stefan Behnel

make the parser correctly understand obj[1,] as passing a tuple as key

--HG--
extra : transplant_source : %5D%AE%1EG%B0%F9%A2%C2%1A%FB5%A6%A65%A5%EE%C4%AC%C4%AD
parent 15dce275
......@@ -13,6 +13,8 @@ Features added
Bugs fixed
----------
* "obj[1,]" passed a single integer into the item getter instead of a tuple.
* Cyclic imports at module init time did not work in Py3.
* The names of C++ destructors for template classes were built incorrectly.
......
......@@ -49,7 +49,7 @@ cpdef p_call_parse_args(PyrexScanner s, bint allow_genexp = *)
cdef p_call_build_packed_args(pos, positional_args, keyword_args, star_arg, starstar_arg)
cdef p_call(PyrexScanner s, function)
cdef p_index(PyrexScanner s, base)
cdef p_subscript_list(PyrexScanner s)
cdef tuple p_subscript_list(PyrexScanner s)
cdef p_subscript(PyrexScanner s)
cdef p_slice_element(PyrexScanner s, follow_set)
cdef expect_ellipsis(PyrexScanner s)
......
......@@ -503,14 +503,14 @@ def p_index(s, base):
# s.sy == '['
pos = s.position()
s.next()
subscripts = p_subscript_list(s)
if len(subscripts) == 1 and len(subscripts[0]) == 2:
subscripts, is_single_value = p_subscript_list(s)
if is_single_value and len(subscripts[0]) == 2:
start, stop = subscripts[0]
result = ExprNodes.SliceIndexNode(pos,
base = base, start = start, stop = stop)
else:
indexes = make_slice_nodes(pos, subscripts)
if len(indexes) == 1:
if is_single_value:
index = indexes[0]
else:
index = ExprNodes.TupleNode(pos, args = indexes)
......@@ -520,13 +520,15 @@ def p_index(s, base):
return result
def p_subscript_list(s):
is_single_value = True
items = [p_subscript(s)]
while s.sy == ',':
is_single_value = False
s.next()
if s.sy == ']':
break
items.append(p_subscript(s))
return items
return items, is_single_value
#subscript: '.' '.' '.' | test | [test] ':' [test] [':' [test]]
......@@ -2112,7 +2114,7 @@ def p_memoryviewslice_access(s, base_type_node):
# s.sy == '['
pos = s.position()
s.next()
subscripts = p_subscript_list(s)
subscripts, _ = p_subscript_list(s)
# make sure each entry in subscripts is a slice
for subscript in subscripts:
if len(subscript) < 2:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment