diff options
author | Guido van Rossum <guido@python.org> | 2006-02-28 00:32:16 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-02-28 00:32:16 (GMT) |
commit | 7ad94f011ef03945c2d9475679f503f5677c4f6d (patch) | |
tree | c063d08e197436d551a78107ad9c5bd24fe339e4 /Lib/compiler/transformer.py | |
parent | 40d8459dbfbe2e2fbd2071a101edf0d47d668901 (diff) | |
download | cpython-7ad94f011ef03945c2d9475679f503f5677c4f6d.zip cpython-7ad94f011ef03945c2d9475679f503f5677c4f6d.tar.gz cpython-7ad94f011ef03945c2d9475679f503f5677c4f6d.tar.bz2 |
Update the compiler package to compile the with-statement.
Jeremy, please review!
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r-- | Lib/compiler/transformer.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index ae9b819..eed9ce9 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -536,6 +536,12 @@ class Transformer: return self.com_try_except(nodelist) + def with_stmt(self, nodelist): + return self.com_with(nodelist) + + def with_var(self, nodelist): + return self.com_with_var(nodelist) + def suite(self, nodelist): # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT if len(nodelist) == 1: @@ -926,6 +932,20 @@ class Transformer: return TryExcept(self.com_node(nodelist[2]), clauses, elseNode, lineno=nodelist[0][2]) + def com_with(self, nodelist): + # with_stmt: 'with' expr [with_var] ':' suite + expr = self.com_node(nodelist[1]) + body = self.com_node(nodelist[-1]) + if nodelist[2][0] == token.COLON: + var = None + else: + var = self.com_node(nodelist[2]) + return With(expr, var, body, lineno=nodelist[0][2]) + + def com_with_var(self, nodelist): + # with_var: 'as' expr + return self.com_node(nodelist[1]) + def com_augassign_op(self, node): assert node[0] == symbol.augassign return node[1] @@ -1390,6 +1410,7 @@ _legal_node_types = [ symbol.while_stmt, symbol.for_stmt, symbol.try_stmt, + symbol.with_stmt, symbol.suite, symbol.testlist, symbol.testlist_safe, |