From 305e7ba8b5fb93c80f31937652b620c726d869d8 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 29 Oct 2010 17:17:39 +0200 Subject: [PATCH] Index: Cython/Compiler/Parsing.py --- Cython/Compiler/Parsing.py | 27 +++++++++++++-------------- tests/compile/ellipsis_T488.pyx | 6 ++++++ tests/run/ellipsis_T488.pyx | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 tests/compile/ellipsis_T488.pyx create mode 100644 tests/run/ellipsis_T488.pyx diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 8c331b76..4903bd6b 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -497,20 +497,16 @@ def p_subscript(s): # 1, 2 or 3 ExprNodes, depending on how # many slice elements were encountered. pos = s.position() - if s.sy == '.': - expect_ellipsis(s) - return [ExprNodes.EllipsisNode(pos)] - else: - start = p_slice_element(s, (':',)) - if s.sy != ':': - return [start] - s.next() - stop = p_slice_element(s, (':', ',', ']')) - if s.sy != ':': - return [start, stop] - s.next() - step = p_slice_element(s, (':', ',', ']')) - return [start, stop, step] + start = p_slice_element(s, (':',)) + if s.sy != ':': + return [start] + s.next() + stop = p_slice_element(s, (':', ',', ']')) + if s.sy != ':': + return [start, stop] + s.next() + step = p_slice_element(s, (':', ',', ']')) + return [start, stop, step] def p_slice_element(s, follow_set): # Simple expression which may be missing iff @@ -569,6 +565,9 @@ def p_atom(s): return p_dict_or_set_maker(s) elif sy == '`': return p_backquote_expr(s) + elif sy == '.': + expect_ellipsis(s) + return ExprNodes.EllipsisNode(pos) elif sy == 'INT': value = s.systring s.next() diff --git a/tests/compile/ellipsis_T488.pyx b/tests/compile/ellipsis_T488.pyx new file mode 100644 index 00000000..a745112e --- /dev/null +++ b/tests/compile/ellipsis_T488.pyx @@ -0,0 +1,6 @@ +#from ... import foo + +print ... +def test(): + x = ... + assert x is Ellipsis diff --git a/tests/run/ellipsis_T488.pyx b/tests/run/ellipsis_T488.pyx new file mode 100644 index 00000000..909ee608 --- /dev/null +++ b/tests/run/ellipsis_T488.pyx @@ -0,0 +1,20 @@ +""" +>>> test() +""" +def test(): + x = ... + assert x is Ellipsis + + d = {} + d[...] = 1 + assert d[...] == 1 + del d[...] + assert ... not in d + + d[..., ...] = 1 + assert d[..., ...] == 1 + assert d[..., Ellipsis] == 1 + assert (Ellipsis, Ellipsis) in d + del d[..., ...] + assert (Ellipsis, Ellipsis) not in d + -- 2.26.2