diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-09-01 20:33:26 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-09-01 20:33:26 (GMT) |
commit | 2051608616178ca6b73d5d59d887ddd67c5835e3 (patch) | |
tree | d7a04d3c59976fcd173c48e66e93f15faf826f64 /Lib/compiler/transformer.py | |
parent | 7527e00058bcfeb21c56386769a83ddff2005754 (diff) | |
download | cpython-2051608616178ca6b73d5d59d887ddd67c5835e3.zip cpython-2051608616178ca6b73d5d59d887ddd67c5835e3.tar.gz cpython-2051608616178ca6b73d5d59d887ddd67c5835e3.tar.bz2 |
Update magic number.
Fix import support to work with import as variant of Python 2.0. The
grammar for import changed, requiring changes in transformer and code
generator, even to handle compilation of imports with as.
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r-- | Lib/compiler/transformer.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index 16d1d8b..9562aa6 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -402,19 +402,20 @@ class Transformer: return n def import_stmt(self, nodelist): - # import: dotted_name (',' dotted_name)* | - # from: dotted_name 'import' ('*' | NAME (',' NAME)*) - names = [ ] - if nodelist[0][1][0] == 'f': + # import_stmt: 'import' dotted_as_name (',' dotted_as_name)* | + # from: 'from' dotted_name 'import' + # ('*' | import_as_name (',' import_as_name)*) + names = [] + is_as = 0 + if nodelist[0][1] == 'from': for i in range(3, len(nodelist), 2): - # note: nodelist[i] could be (token.STAR, '*') or (token.NAME, name) - names.append(nodelist[i][1]) + names.append(self.com_import_as_name(nodelist[i][1])) n = Node('from', self.com_dotted_name(nodelist[1]), names) n.lineno = nodelist[0][2] return n for i in range(1, len(nodelist), 2): - names.append(self.com_dotted_name(nodelist[i])) + names.append(self.com_dotted_as_name(nodelist[i])) n = Node('import', names) n.lineno = nodelist[0][2] return n @@ -738,6 +739,7 @@ class Transformer: if node[0] not in _legal_node_types: raise error, 'illegal node passed to com_node: %s' % node[0] +# print "dispatch", self._dispatch[node[0]].__name__, node return self._dispatch[node[0]](node[1:]) def com_arglist(self, nodelist): @@ -814,6 +816,22 @@ class Transformer: name = name + n[1] + '.' return name[:-1] + def com_dotted_as_name(self, node): + dot = self.com_dotted_name(node[1]) + if len(node) == 2: + return dot, None + assert node[2][1] == 'as' + assert node[3][0] == token.NAME + return dot, node[3][1] + + def com_import_as_name(self, node): + 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] + def com_bases(self, node): bases = [ ] for i in range(1, len(node), 2): |