[pypy-svn] r59493 - in pypy/trunk/pypy/interpreter: pyparser test
fijal at codespeak.net
fijal at codespeak.net
Tue Oct 28 17:16:31 CET 2008
Author: fijal
Date: Tue Oct 28 17:16:30 2008
New Revision: 59493
Modified:
pypy/trunk/pypy/interpreter/pyparser/astbuilder.py
pypy/trunk/pypy/interpreter/pyparser/asthelper.py
pypy/trunk/pypy/interpreter/test/test_compiler.py
Log:
I *think* this is a proper try: except: finally: support (It doesn't introduce
new ast node though)
Modified: pypy/trunk/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/astbuilder.py (original)
+++ pypy/trunk/pypy/interpreter/pyparser/astbuilder.py Tue Oct 28 17:16:30 2008
@@ -982,8 +982,10 @@
def build_try_stmt(builder, nb):
"""
+
try_stmt: ('try' ':' suite (except_clause ':' suite)+ #diagram:break
- ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite)
+ ['else' ':' suite] ['finally' ':' suite]
+ | 'try' ':' suite 'finally' ':' suite)
# NB compile.c makes sure that the default except clause is last
except_clause: 'except' [test [',' test]]
@@ -1011,8 +1013,19 @@
if index < l:
token = atoms[index]
assert isinstance(token, TokenObject)
- assert token.get_value() == 'else'
- else_ = atoms[index+2] # skip ':'
+ if token.get_value() == 'else':
+ else_ = atoms[index+2] # skip ':'
+ index += 2
+ if index < l:
+ token = atoms[index]
+ assert isinstance(token, TokenObject)
+ if token.get_value() != 'finally':
+ raise SyntaxError("Finally expected, got %s" % token.get_value())
+ body1 = ast.TryExcept(body, handlers, else_, atoms[0].lineno)
+ res = ast.TryFinally(body1, atoms[index + 2],
+ atoms[0].lineno)
+ builder.push(res)
+ return
builder.push(ast.TryExcept(body, handlers, else_, atoms[0].lineno))
ASTRULES_Template = {
Modified: pypy/trunk/pypy/interpreter/pyparser/asthelper.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyparser/asthelper.py (original)
+++ pypy/trunk/pypy/interpreter/pyparser/asthelper.py Tue Oct 28 17:16:30 2008
@@ -15,7 +15,8 @@
while clause_length < len(tokens):
token = tokens[clause_length]
if isinstance(token, TokenObject) and \
- (token.get_value() == 'except' or token.get_value() == 'else'):
+ (token.get_value() == 'except' or token.get_value() == 'else'
+ or token.get_value() == 'finally'):
break
clause_length += 1
if clause_length == 3:
Modified: pypy/trunk/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_compiler.py (original)
+++ pypy/trunk/pypy/interpreter/test/test_compiler.py Tue Oct 28 17:16:30 2008
@@ -142,7 +142,6 @@
assert ex.match(self.space, self.space.w_SyntaxError)
def test_try_except_finally(self):
- py.test.skip("FAILS!")
s = py.code.Source("""
def f():
try:
@@ -659,6 +658,8 @@
self.space.config.objspace.pyversion = "2.4"
self.compiler = PythonAstCompiler(self.space, "2.4")
+ def test_try_except_finally(self):
+ py.test.skip("unsupported")
class AppTestOptimizer:
def test_constant_fold_add(self):
More information about the Pypy-commit
mailing list