From 01f2495abc9e260d9670274d77cfbe2912b2f8e8 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Thu, 16 Dec 2021 22:12:27 +0000 Subject: Implement and test try/catch/finally syntax --- perly.y | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'perly.y') diff --git a/perly.y b/perly.y index 068df58b32..d4e803f037 100644 --- a/perly.y +++ b/perly.y @@ -69,7 +69,7 @@ %token FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE %token WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR %token GIVEN WHEN DEFAULT -%token TRY CATCH +%token TRY CATCH FINALLY %token LOOPEX DOTDOT YADAYADA %token FUNC0 FUNC1 FUNC UNIOP LSTOP %token MULOP ADDOP @@ -84,7 +84,7 @@ %type mintro -%type stmtseq fullstmt labfullstmt barestmt block mblock else +%type stmtseq fullstmt labfullstmt barestmt block mblock else finally %type expr term subscripted scalar ary hsh arylen star amper sideff %type condition %type 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 && -- cgit v1.2.1