Kaydet (Commit) 2e4cc7e0 authored tarafından Jeremy Hylton's avatar Jeremy Hylton

Last set of change to get regression tests to pass

Remove the only test in the syntax module.  It ends up that the
transformer must handle this error case.

In the transformer, check for a list compression in com_assign_list()
by looking for a list_for node where a comma is expected.

In pycodegen.compile() re-raise the SyntaxError rather than catching
it and exiting
üst c299fc16
...@@ -49,7 +49,7 @@ def compile(filename, display=0): ...@@ -49,7 +49,7 @@ def compile(filename, display=0):
try: try:
mod.compile(display) mod.compile(display)
except SyntaxError, err: except SyntaxError, err:
print "SyntaxError:", err raise
else: else:
f = open(filename + "c", "wb") f = open(filename + "c", "wb")
mod.dump(f) mod.dump(f)
......
...@@ -39,7 +39,8 @@ class SyntaxErrorChecker: ...@@ -39,7 +39,8 @@ class SyntaxErrorChecker:
def visitAssign(self, node): def visitAssign(self, node):
# the transformer module handles many of these # the transformer module handles many of these
for target in node.nodes: for target in node.nodes:
if isinstance(target, ast.AssList): pass
if target.lineno is None: ## if isinstance(target, ast.AssList):
target.lineno = node.lineno ## if target.lineno is None:
self.error(target, "can't assign to list comprehension") ## target.lineno = node.lineno
## self.error(target, "can't assign to list comprehension")
...@@ -943,6 +943,10 @@ class Transformer: ...@@ -943,6 +943,10 @@ class Transformer:
def com_assign_list(self, node, assigning): def com_assign_list(self, node, assigning):
assigns = [] assigns = []
for i in range(1, len(node), 2): for i in range(1, len(node), 2):
if i + 1 < len(node):
if node[i + 1][0] == symbol.list_for:
raise SyntaxError, "can't assign to list comprehension"
assert node[i + 1][0] == token.COMMA, node[i + 1]
assigns.append(self.com_assign(node[i], assigning)) assigns.append(self.com_assign(node[i], assigning))
return AssList(assigns) return AssList(assigns)
......
...@@ -49,7 +49,7 @@ def compile(filename, display=0): ...@@ -49,7 +49,7 @@ def compile(filename, display=0):
try: try:
mod.compile(display) mod.compile(display)
except SyntaxError, err: except SyntaxError, err:
print "SyntaxError:", err raise
else: else:
f = open(filename + "c", "wb") f = open(filename + "c", "wb")
mod.dump(f) mod.dump(f)
......
...@@ -39,7 +39,8 @@ class SyntaxErrorChecker: ...@@ -39,7 +39,8 @@ class SyntaxErrorChecker:
def visitAssign(self, node): def visitAssign(self, node):
# the transformer module handles many of these # the transformer module handles many of these
for target in node.nodes: for target in node.nodes:
if isinstance(target, ast.AssList): pass
if target.lineno is None: ## if isinstance(target, ast.AssList):
target.lineno = node.lineno ## if target.lineno is None:
self.error(target, "can't assign to list comprehension") ## target.lineno = node.lineno
## self.error(target, "can't assign to list comprehension")
...@@ -943,6 +943,10 @@ class Transformer: ...@@ -943,6 +943,10 @@ class Transformer:
def com_assign_list(self, node, assigning): def com_assign_list(self, node, assigning):
assigns = [] assigns = []
for i in range(1, len(node), 2): for i in range(1, len(node), 2):
if i + 1 < len(node):
if node[i + 1][0] == symbol.list_for:
raise SyntaxError, "can't assign to list comprehension"
assert node[i + 1][0] == token.COMMA, node[i + 1]
assigns.append(self.com_assign(node[i], assigning)) assigns.append(self.com_assign(node[i], assigning))
return AssList(assigns) return AssList(assigns)
......
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