From e77243decd22d687557bb7f38039244a2bb3f66a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 21 Apr 2011 09:24:43 +0200 Subject: [PATCH] allow multiple __future__ imports in separate statements --- Cython/Compiler/Parsing.py | 41 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 7490e15d..4f844aac 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -1660,15 +1660,27 @@ def p_simple_statement_list(s, ctx, first_statement = 0): # Parse a series of simple statements on one line # separated by semicolons. stat = p_simple_statement(s, first_statement = first_statement) - if s.sy == ';': - stats = [stat] - while s.sy == ';': - #print "p_simple_statement_list: maybe more to follow" ### - s.next() - if s.sy in ('NEWLINE', 'EOF'): - break - stats.append(p_simple_statement(s)) - stat = Nodes.StatListNode(stats[0].pos, stats = stats) + pos = stat.pos + stats = [] + if not isinstance(stat, Nodes.PassStatNode): + stats.append(stat) + while s.sy == ';': + #print "p_simple_statement_list: maybe more to follow" ### + s.next() + if s.sy in ('NEWLINE', 'EOF'): + break + stat = p_simple_statement(s, first_statement = first_statement) + if isinstance(stat, Nodes.PassStatNode): + continue + stats.append(stat) + first_statement = False + + if not stats: + stat = Nodes.PassStatNode(pos) + elif len(stats) == 1: + stat = stats[0] + else: + stat = Nodes.StatListNode(pos, stats = stats) s.expect_newline("Syntax error in simple statement list") return stat @@ -1805,9 +1817,14 @@ def p_statement_list(s, ctx, first_statement = 0): pos = s.position() stats = [] while s.sy not in ('DEDENT', 'EOF'): - stats.append(p_statement(s, ctx, first_statement = first_statement)) - first_statement = 0 - if len(stats) == 1: + stat = p_statement(s, ctx, first_statement = first_statement) + if isinstance(stat, Nodes.PassStatNode): + continue + stats.append(stat) + first_statement = False + if not stats: + return Nodes.PassStatNode(pos) + elif len(stats) == 1: return stats[0] else: return Nodes.StatListNode(pos, stats = stats) -- 2.26.2