Commit 0bc6a335 authored by Stefan Behnel's avatar Stefan Behnel

allow multiple __future__ imports in separate statements

parent 5b5613fa
...@@ -1660,15 +1660,27 @@ def p_simple_statement_list(s, ctx, first_statement = 0): ...@@ -1660,15 +1660,27 @@ def p_simple_statement_list(s, ctx, first_statement = 0):
# Parse a series of simple statements on one line # Parse a series of simple statements on one line
# separated by semicolons. # separated by semicolons.
stat = p_simple_statement(s, first_statement = first_statement) stat = p_simple_statement(s, first_statement = first_statement)
if s.sy == ';': pos = stat.pos
stats = [stat] stats = []
while s.sy == ';': if not isinstance(stat, Nodes.PassStatNode):
#print "p_simple_statement_list: maybe more to follow" ### stats.append(stat)
s.next() while s.sy == ';':
if s.sy in ('NEWLINE', 'EOF'): #print "p_simple_statement_list: maybe more to follow" ###
break s.next()
stats.append(p_simple_statement(s)) if s.sy in ('NEWLINE', 'EOF'):
stat = Nodes.StatListNode(stats[0].pos, stats = stats) 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") s.expect_newline("Syntax error in simple statement list")
return stat return stat
...@@ -1805,9 +1817,14 @@ def p_statement_list(s, ctx, first_statement = 0): ...@@ -1805,9 +1817,14 @@ def p_statement_list(s, ctx, first_statement = 0):
pos = s.position() pos = s.position()
stats = [] stats = []
while s.sy not in ('DEDENT', 'EOF'): while s.sy not in ('DEDENT', 'EOF'):
stats.append(p_statement(s, ctx, first_statement = first_statement)) stat = p_statement(s, ctx, first_statement = first_statement)
first_statement = 0 if isinstance(stat, Nodes.PassStatNode):
if len(stats) == 1: continue
stats.append(stat)
first_statement = False
if not stats:
return Nodes.PassStatNode(pos)
elif len(stats) == 1:
return stats[0] return stats[0]
else: else:
return Nodes.StatListNode(pos, stats = stats) return Nodes.StatListNode(pos, stats = stats)
......
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