This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge branch 'perlgov-omnibus-amendments' into blead
[perl5.git] / perly.y
diff --git a/perly.y b/perly.y
index ab6f395..18ed6e8 100644 (file)
--- a/perly.y
+++ b/perly.y
 %token <ival> PERLY_BRACKET_OPEN
 %token <ival> PERLY_BRACKET_CLOSE
 %token <ival> PERLY_COMMA
+%token <ival> PERLY_DOLLAR
 %token <ival> PERLY_DOT
 %token <ival> PERLY_EQUAL_SIGN
 %token <ival> PERLY_MINUS
 %token <ival> PERLY_PERCENT_SIGN
 %token <ival> PERLY_PLUS
 %token <ival> PERLY_SEMICOLON
+%token <ival> PERLY_SLASH
 %token <ival> PERLY_SNAIL
+%token <ival> PERLY_STAR
 
 %token <opval> BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
@@ -66,6 +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> LOOPEX DOTDOT YADAYADA
 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
 %token <ival> MULOP ADDOP
@@ -73,6 +77,7 @@
 %token <ival> LOCAL MY REQUIRE
 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
 %token <ival> SUBLEXSTART SUBLEXEND
+%token <ival> DEFER
 
 %type <ival> grammar remember mremember
 %type <ival>  startsub startanonsub startformsub
 %nonassoc <ival> PREC_LOW
 %nonassoc LOOPEX
 
-%left <ival> OROP DOROP
+%left <ival> OROP
 %left <ival> ANDOP
 %right <ival> NOTOP
 %nonassoc LSTOP LSTOPSUB
@@ -228,7 +233,7 @@ formblock:  PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERL
                        }
        ;
 
-remember:      /* NULL */      /* start a full lexical scope */
+remember:      %empty  /* start a full lexical scope */
                        { $$ = block_start(TRUE);
                          parser->parsed_sub = 0; }
        ;
@@ -240,13 +245,13 @@ mblock    :       PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
                        }
        ;
 
-mremember:     /* NULL */      /* start a partial lexical scope */
+mremember:     %empty  /* start a partial lexical scope */
                        { $$ = block_start(FALSE);
                          parser->parsed_sub = 0; }
        ;
 
 /* A sequence of statements in the program */
-stmtseq        :       /* NULL */
+stmtseq        :       %empty
                        { $$ = NULL; }
        |       stmtseq[list] fullstmt
                        {   $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
@@ -257,7 +262,7 @@ stmtseq     :       /* NULL */
        ;
 
 /* A sequence of format lines */
-formstmtseq:   /* NULL */
+formstmtseq:   %empty
                        { $$ = NULL; }
        |       formstmtseq[list] formline
                        {   $$ = op_append_list(OP_LINESEQ, $list, $formline);
@@ -456,6 +461,16 @@ barestmt:  PLUGSTMT
                                  newFOROP(0, NULL, $mexpr, $mblock, $cont));
                          parser->copline = (line_t)$FOR;
                        }
+       |       TRY mblock[try] CATCH PERLY_PAREN_OPEN 
+                       { parser->in_my = 1; }
+               remember scalar 
+                       { parser->in_my = 0; intro_my(); }
+               PERLY_PAREN_CLOSE mblock[catch]
+                       {
+                         $$ = newTRYCATCHOP(0,
+                                 $try, $scalar, block_end($remember, op_scope($catch)));
+                         parser->copline = (line_t)$TRY;
+                       }
        |       block cont
                        {
                          /* a block is a loop that happens once */
@@ -481,6 +496,10 @@ barestmt:  PLUGSTMT
                        {
                          $$ = $sideff;
                        }
+       |       DEFER mblock
+                       {
+                         $$ = newDEFEROP(0, op_scope($2));
+                       }
        |       YADAYADA PERLY_SEMICOLON
                        {
                          $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
@@ -511,7 +530,7 @@ formline:   THING formarg
                        }
        ;
 
-formarg        :       /* NULL */
+formarg        :       %empty
                        { $$ = NULL; }
        |       FORMLBRACK stmtseq FORMRBRACK
                        { $$ = op_unscope($stmtseq); }
@@ -541,7 +560,7 @@ sideff      :       error
        ;
 
 /* else and elsif blocks */
-else   :       /* NULL */
+else   :       %empty
                        { $$ = NULL; }
        |       ELSE mblock
                        {
@@ -558,26 +577,26 @@ else      :       /* NULL */
        ;
 
 /* Continue blocks */
-cont   :       /* NULL */
+cont   :       %empty
                        { $$ = NULL; }
        |       CONTINUE block
                        { $$ = op_scope($block); }
        ;
 
 /* determine whether there are any new my declarations */
-mintro :       /* NULL */
+mintro :       %empty
                        { $$ = (PL_min_intro_pending &&
                            PL_max_intro_pending >=  PL_min_intro_pending);
                          intro_my(); }
 
 /* Normal expression */
-nexpr  :       /* NULL */
+nexpr  :       %empty
                        { $$ = NULL; }
        |       sideff
        ;
 
 /* Boolean expression */
-texpr  :       /* NULL means true */
+texpr  :       %empty /* NULL means true */
                        { YYSTYPE tmplval;
                          (void)scan_num("1", &tmplval);
                          $$ = tmplval.opval; }
@@ -599,21 +618,21 @@ mnexpr    :       nexpr
        ;
 
 formname:      BAREWORD        { $$ = $BAREWORD; }
-       |       /* NULL */      { $$ = NULL; }
+       |       %empty  { $$ = NULL; }
        ;
 
-startsub:      /* NULL */      /* start a regular subroutine scope */
+startsub:      %empty  /* start a regular subroutine scope */
                        { $$ = start_subparse(FALSE, 0);
                            SAVEFREESV(PL_compcv); }
 
        ;
 
-startanonsub:  /* NULL */      /* start an anonymous subroutine scope */
+startanonsub:  %empty  /* start an anonymous subroutine scope */
                        { $$ = start_subparse(FALSE, CVf_ANON);
                            SAVEFREESV(PL_compcv); }
        ;
 
-startformsub:  /* NULL */      /* start a format subroutine scope */
+startformsub:  %empty  /* start a format subroutine scope */
                        { $$ = start_subparse(TRUE, 0);
                            SAVEFREESV(PL_compcv); }
        ;
@@ -624,13 +643,13 @@ subname   :       BAREWORD
        ;
 
 /* Subroutine prototype */
-proto  :       /* NULL */
+proto  :       %empty
                        { $$ = NULL; }
        |       THING
        ;
 
 /* Optional list of subroutine attributes */
-subattrlist:   /* NULL */
+subattrlist:   %empty
                        { $$ = NULL; }
        |       COLONATTR THING
                        { $$ = $THING; }
@@ -652,7 +671,7 @@ myattrlist: COLONATTR THING
  */
 
 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable  */
-sigvarname:     /* NULL */
+sigvarname:     %empty
                        { parser->in_my = 0; $$ = NULL; }
         |       PRIVATEREF
                         { parser->in_my = 0; $$ = $PRIVATEREF; }
@@ -684,7 +703,7 @@ sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
        ;
 
 /* default part of sub signature scalar element: i.e. '= default_expr' */
-sigdefault:    /* NULL */
+sigdefault:    %empty
                        { $$ = NULL; }
         |       ASSIGNOP
                         { $$ = newOP(OP_NULL, 0); }
@@ -694,7 +713,7 @@ sigdefault: /* NULL */
 
 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
 sigscalarelem:
-                '$' sigvarname sigdefault
+                PERLY_DOLLAR sigvarname sigdefault
                         {
                             OP *var     = $sigvarname;
                             OP *defexpr = $sigdefault;
@@ -778,13 +797,13 @@ siglist:
        ;
 
 /* () or (....) */
-siglistornull:         /* NULL */
+siglistornull:         %empty
                        { $$ = NULL; }
        |       siglist
                        { $$ = $siglist; }
 
 /* optional subroutine signature */
-optsubsignature:       /* NULL */
+optsubsignature:       %empty
                        { $$ = NULL; }
        |       subsignature
                        { $$ = $subsignature; }
@@ -898,8 +917,6 @@ expr        :       expr[lhs] ANDOP expr[rhs]
                        { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
        |       expr[lhs] OROP[operator] expr[rhs]
                        { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
-       |       expr[lhs] DOROP expr[rhs]
-                       { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
        |       listexpr %prec PREC_LOW
        ;
 
@@ -1245,16 +1262,16 @@ term[product]   :       termbinop
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                            op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
                        }
-       |       term[operand] ARROW '$' '*'
+       |       term[operand] ARROW PERLY_DOLLAR PERLY_STAR
                        { $$ = newSVREF($operand); }
-       |       term[operand] ARROW PERLY_SNAIL '*'
+       |       term[operand] ARROW PERLY_SNAIL PERLY_STAR
                        { $$ = newAVREF($operand); }
-       |       term[operand] ARROW PERLY_PERCENT_SIGN '*'
+       |       term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
                        { $$ = newHVREF($operand); }
-       |       term[operand] ARROW PERLY_AMPERSAND '*'
+       |       term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
                        { $$ = newUNOP(OP_ENTERSUB, 0,
                                       scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
-       |       term[operand] ARROW '*' '*'     %prec PERLY_PAREN_OPEN
+       |       term[operand] ARROW PERLY_STAR PERLY_STAR       %prec PERLY_PAREN_OPEN
                        { $$ = newGVREF(0,$operand); }
        |       LOOPEX  /* loop exiting command (goto, last, dump, etc) */
                        { $$ = newOP($LOOPEX, OPf_SPECIAL);
@@ -1336,21 +1353,21 @@ myterm  :       PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
        ;
 
 /* Basic list expressions */
-optlistexpr:   /* NULL */ %prec PREC_LOW
+optlistexpr:   %empty %prec PREC_LOW
                        { $$ = NULL; }
        |       listexpr    %prec PREC_LOW
                        { $$ = $listexpr; }
        ;
 
-optexpr:       /* NULL */
+optexpr:       %empty
                        { $$ = NULL; }
        |       expr
                        { $$ = $expr; }
        ;
 
-optrepl:       /* NULL */
+optrepl:       %empty
                        { $$ = NULL; }
-       |       '/' expr
+       |       PERLY_SLASH expr
                        { $$ = $expr; }
        ;
 
@@ -1377,7 +1394,7 @@ amper     :       PERLY_AMPERSAND indirob
                        { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
        ;
 
-scalar :       '$' indirob
+scalar :       PERLY_DOLLAR indirob
                        { $$ = newSVREF($indirob); }
        ;
 
@@ -1395,11 +1412,11 @@ hsh     :       PERLY_PERCENT_SIGN indirob
 
 arylen :       DOLSHARP indirob
                        { $$ = newAVREF($indirob); }
-       |       term ARROW DOLSHARP '*'
+       |       term ARROW DOLSHARP PERLY_STAR
                        { $$ = newAVREF($term); }
        ;
 
-star   :       '*' indirob
+star   :       PERLY_STAR indirob
                        { $$ = newGVREF(0,$indirob); }
        ;
 
@@ -1414,7 +1431,7 @@ kvslice   :       hsh
        ;
 
 gelem  :       star
-       |       term ARROW '*'
+       |       term ARROW PERLY_STAR
                        { $$ = newGVREF(0,$term); }
        ;