diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2021-12-16 22:12:27 +0000 |
---|---|---|
committer | ℕicolas ℝ <nicolas@atoomic.org> | 2022-01-20 11:41:09 -0700 |
commit | 01f2495abc9e260d9670274d77cfbe2912b2f8e8 (patch) | |
tree | e75d2fbb26b791ee1c8880f0fc464e46d36b61be /perly.y | |
parent | 1a7eed135c20f2515b61b6960de09800d80ca9cd (diff) | |
download | perl-01f2495abc9e260d9670274d77cfbe2912b2f8e8.tar.gz |
Implement and test try/catch/finally syntax
Diffstat (limited to 'perly.y')
-rw-r--r-- | perly.y | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -69,7 +69,7 @@ %token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR %token <ival> GIVEN WHEN DEFAULT -%token <ival> TRY CATCH +%token <ival> TRY CATCH FINALLY %token <ival> LOOPEX DOTDOT YADAYADA %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP %token <ival> MULOP ADDOP @@ -84,7 +84,7 @@ %type <ival> mintro -%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else +%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else finally %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff %type <opval> condition %type <opval> sliceme kvslice gelem @@ -470,10 +470,12 @@ barestmt: PLUGSTMT { parser->in_my = 1; } remember scalar { parser->in_my = 0; intro_my(); } - PERLY_PAREN_CLOSE mblock[catch] + PERLY_PAREN_CLOSE mblock[catch] finally { $$ = newTRYCATCHOP(0, $try, $scalar, block_end($remember, op_scope($catch))); + if($finally) + $$ = op_wrap_finally($$, $finally); parser->copline = (line_t)$TRY; } | block cont @@ -588,6 +590,13 @@ cont : %empty { $$ = op_scope($block); } ; +/* Finally blocks */ +finally : %empty + { $$ = NULL; } + | FINALLY block + { $$ = op_scope($block); } + ; + /* determine whether there are any new my declarations */ mintro : %empty { $$ = (PL_min_intro_pending && |