added raise statements

This commit is contained in:
Anthony Scopatz 2015-01-26 01:42:23 -06:00
parent f521cef0bf
commit 7130476e15
3 changed files with 23 additions and 4 deletions

View file

@ -513,6 +513,12 @@ def test_del_two_comma():
def test_raise():
yield check_stmts, 'raise', False
def test_raise_x():
yield check_stmts, 'raise TypeError', False
def test_raise_x_from():
yield check_stmts, 'raise TypeError from x', False
#DEBUG_LEVEL = 1
#DEBUG_LEVEL = 100

View file

@ -6,4 +6,4 @@ from ast import Module, Num, Expr, Str, Bytes, UnaryOp, UAdd, USub, Invert, \
Index, Load, Slice, List, Tuple, Set, Dict, AST, NameConstant, Ellipsis, \
Name, GeneratorExp, Store, comprehension, ListComp, SetComp, DictComp, \
Assign, AugAssign, BitXor, BitAnd, BitOr, LShift, RShift, Assert, Delete, \
Del, Pass
Del, Pass, Raise

View file

@ -559,10 +559,23 @@ class Parser(object):
def p_raise_stmt(self, p):
"""raise_stmt : RAISE
| test
| test FROM test
| RAISE test
| RAISE test FROM test
"""
p[0] = p[1:]
lenp = len(p)
cause = None
if lenp == 2:
exc = None
elif lenp == 3:
exc = p[2]
elif lenp == 5:
exc = p[2]
cause = p[4]
else:
assert False
p0 = ast.Raise(exc=exc, cause=cause, lineno=self.lineno,
col_offset=self.col)
p[0] = p0
def p_import_stmt(self, p):
"""import_stmt : import_name