Index: t/00-parrot/12-try.t =================================================================== --- t/00-parrot/12-try.t (revision 0) +++ t/00-parrot/12-try.t (revision 0) @@ -0,0 +1,47 @@ +#!./parrot pynie.pbc + +print '1..5' + +try: + x = 1 + raise Exception +except: + x = 2 +if x == 2: print 'ok 1' +else: print 'not ok 1' + +try: + x = 1 +except: + x = 2 +if x == 1: print 'ok 2' +else: print 'not ok 2' + +# make sure asserts are on +# XXX in real Python, you can't set __debug__ +__debug__ = 1 + +try: + x = 1 + assert 0 +except: + x = 2 +if x == 2: print 'ok 3' +else: print 'not ok 3' + +try: + x = 1 + assert 1 +except: + x = 2 +if x == 1: print 'ok 4' +else: print 'not ok 4' + +__debug__ = 0 +try: + x = 1 + assert 0 +except: + x = 2 +if x == 1: print 'ok 5' +else: print 'not ok 5' Index: src/parser/Grammar.pg =================================================================== --- src/parser/Grammar.pg (revision 31242) +++ src/parser/Grammar.pg (working copy) @@ -59,7 +59,7 @@ | {*} #= if_stmt | {*} #= while_stmt | - | + | {*} #= try_stmt | | {*} #= funcdef | {*} #= classdef @@ -84,15 +84,17 @@ } rule try_stmt { - | + | {*} #= try1_stmt | } rule try1_stmt { - 'try' ':' - [ 'except' [ [ ',' ]? ]? ':' ]+ - [ 'else' ':' ]? - [ 'finally' ':' ]? + 'try' ':' + 'except' ':' +# 'except' [ [ ',' ]? ]? ':' +# [ 'else' ':' ]? +# [ 'finally' ':' ]? + {*} } rule try2_stmt { Index: src/parser/Actions.pm =================================================================== --- src/parser/Actions.pm (revision 31242) +++ src/parser/Actions.pm (working copy) @@ -346,6 +346,21 @@ make $past; } +method try_stmt($/, $key) { + make $( $/{$key} ); +} + +method try1_stmt($/) { + # XXX implement except params, else, finally + my $try := $($); + my $handler := $($); + my $past := PAST::Op.new( $try, + $handler, + :pasttype('try'), + :node($/) ); + make $past; +} + method simple_stmt($/, $key) { make $( $/{$key} ); }