summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-04-09 04:27:12 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-04-09 04:27:12 (GMT)
commit42a083071353f80215715437fdcb6b49cc431169 (patch)
tree80e9e2e82e0b36da765bc132cf87ecac2665f527 /Lib
parenta384f737cc4f7cd90b5e2df8ac99d458522be156 (diff)
downloadcpython-42a083071353f80215715437fdcb6b49cc431169.zip
cpython-42a083071353f80215715437fdcb6b49cc431169.tar.gz
cpython-42a083071353f80215715437fdcb6b49cc431169.tar.bz2
Fix "import as" (has always skipping the as name)
Fix com_NEWLINE() so that is accepts arguments, which occurs for lines like: stmt; # note trailing semicolon Add XXX about checking for assignment to list comps
Diffstat (limited to 'Lib')
-rw-r--r--Lib/compiler/transformer.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 348736c..d32812a 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -367,7 +367,7 @@ class Transformer:
names.append((nodelist[i][1], None))
else:
for i in range(3, len(nodelist), 2):
- names.append(self.com_import_as_name(nodelist[i][1]))
+ names.append(self.com_import_as_name(nodelist[i]))
n = From(self.com_dotted_name(nodelist[1]), names)
n.lineno = nodelist[0][2]
return n
@@ -692,7 +692,7 @@ class Transformer:
# We'll just dispatch them.
return self._dispatch[node[0]](node[1:])
- def com_NEWLINE(self):
+ def com_NEWLINE(self, *args):
# A ';' at the end of a line can make a NEWLINE token appear
# here, Render it harmless. (genc discards ('discard',
# ('const', xxxx)) Nodes)
@@ -784,14 +784,17 @@ class Transformer:
return dot, node[3][1]
def com_import_as_name(self, node):
- if node == '*':
+ if node[0] == token.STAR:
return '*', None
- if node[0] == token.NAME:
- return node[1], None
- assert len(node) == 4
- assert node[2][1] == 'as'
- assert node[3][0] == token.NAME
- return node[1][1], node[3][1]
+ assert node[0] == symbol.import_as_name
+ node = node[1:]
+ if len(node) == 1:
+ assert node[0][0] == token.NAME
+ return node[0][1], None
+
+ assert node[1][1] == 'as', node
+ assert node[2][0] == token.NAME
+ return node[0][1], node[2][1]
def com_bases(self, node):
bases = []
@@ -963,6 +966,9 @@ class Transformer:
# list_iter: list_for | list_if
# list_for: 'for' exprlist 'in' testlist [list_iter]
# list_if: 'if' test [list_iter]
+
+ # XXX should raise SyntaxError for assignment
+
lineno = node[1][2]
fors = []
while node: