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
This commit is contained in:
Jeremy Hylton 2001-09-17 19:33:48 +00:00
parent c299fc16f2
commit 2e4cc7e0d8
6 changed files with 20 additions and 10 deletions

View file

@ -49,7 +49,7 @@ def compile(filename, display=0):
try:
mod.compile(display)
except SyntaxError, err:
print "SyntaxError:", err
raise
else:
f = open(filename + "c", "wb")
mod.dump(f)

View file

@ -39,7 +39,8 @@ def error(self, node, msg):
def visitAssign(self, node):
# the transformer module handles many of these
for target in node.nodes:
if isinstance(target, ast.AssList):
if target.lineno is None:
target.lineno = node.lineno
self.error(target, "can't assign to list comprehension")
pass
## if isinstance(target, ast.AssList):
## if target.lineno is None:
## target.lineno = node.lineno
## self.error(target, "can't assign to list comprehension")

View file

@ -943,6 +943,10 @@ def com_assign_tuple(self, node, assigning):
def com_assign_list(self, node, assigning):
assigns = []
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))
return AssList(assigns)

View file

@ -49,7 +49,7 @@ def compile(filename, display=0):
try:
mod.compile(display)
except SyntaxError, err:
print "SyntaxError:", err
raise
else:
f = open(filename + "c", "wb")
mod.dump(f)

View file

@ -39,7 +39,8 @@ def error(self, node, msg):
def visitAssign(self, node):
# the transformer module handles many of these
for target in node.nodes:
if isinstance(target, ast.AssList):
if target.lineno is None:
target.lineno = node.lineno
self.error(target, "can't assign to list comprehension")
pass
## if isinstance(target, ast.AssList):
## if target.lineno is None:
## target.lineno = node.lineno
## self.error(target, "can't assign to list comprehension")

View file

@ -943,6 +943,10 @@ def com_assign_tuple(self, node, assigning):
def com_assign_list(self, node, assigning):
assigns = []
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))
return AssList(assigns)