From 148f5aafd05807ac681803b169497485643e1ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branislav=20Zahradn=C3=ADk?= Date: Thu, 23 Dec 2021 23:24:52 +0100 Subject: Introduce rule `empty` returning NULL to save few keystrokes ... --- perly.y | 63 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'perly.y') diff --git a/perly.y b/perly.y index 540c7ccb35..8aea09b00f 100644 --- a/perly.y +++ b/perly.y @@ -87,6 +87,7 @@ %type stmtseq fullstmt labfullstmt barestmt block mblock else finally %type expr term subscripted scalar ary hsh arylen star amper sideff %type condition +%type empty %type sliceme kvslice gelem %type listexpr nexpr texpr iexpr mexpr mnexpr %type optlistexpr optexpr optrepl indirob listop method @@ -225,6 +226,10 @@ block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE } ; +empty + : %empty { $$ = NULL; } + ; + /* format body */ formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN) @@ -251,8 +256,8 @@ mremember: %empty /* start a partial lexical scope */ ; /* A sequence of statements in the program */ -stmtseq : %empty - { $$ = NULL; } +stmtseq + : empty | stmtseq[list] fullstmt { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt); PL_pad_reset_pending = TRUE; @@ -262,8 +267,8 @@ stmtseq : %empty ; /* A sequence of format lines */ -formstmtseq: %empty - { $$ = NULL; } +formstmtseq + : empty | formstmtseq[list] formline { $$ = op_append_list(OP_LINESEQ, $list, $formline); PL_pad_reset_pending = TRUE; @@ -537,8 +542,8 @@ formline: THING formarg } ; -formarg : %empty - { $$ = NULL; } +formarg + : empty | FORMLBRACK stmtseq FORMRBRACK { $$ = op_unscope($stmtseq); } ; @@ -567,8 +572,8 @@ sideff : error ; /* else and elsif blocks */ -else : %empty - { $$ = NULL; } +else + : empty | ELSE mblock { ($mblock)->op_flags |= OPf_PARENS; @@ -584,8 +589,8 @@ else : %empty ; /* Continue blocks */ -cont : %empty - { $$ = NULL; } +cont + : empty | CONTINUE block { $$ = op_scope($block); } ; @@ -604,8 +609,8 @@ mintro : %empty intro_my(); } /* Normal expression */ -nexpr : %empty - { $$ = NULL; } +nexpr + : empty | sideff ; @@ -632,7 +637,7 @@ mnexpr : nexpr ; formname: BAREWORD { $$ = $BAREWORD; } - | %empty { $$ = NULL; } + | empty ; startsub: %empty /* start a regular subroutine scope */ @@ -657,14 +662,14 @@ subname : BAREWORD ; /* Subroutine prototype */ -proto : %empty - { $$ = NULL; } +proto + : empty | THING ; /* Optional list of subroutine attributes */ -subattrlist: %empty - { $$ = NULL; } +subattrlist + : empty | COLONATTR THING { $$ = $THING; } | COLONATTR @@ -717,8 +722,8 @@ sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ ; /* default part of sub signature scalar element: i.e. '= default_expr' */ -sigdefault: %empty - { $$ = NULL; } +sigdefault + : empty | ASSIGNOP { $$ = newOP(OP_NULL, 0); } | ASSIGNOP term @@ -811,14 +816,14 @@ siglist: ; /* () or (....) */ -siglistornull: %empty - { $$ = NULL; } +siglistornull + : empty | siglist { $$ = $siglist; } /* optional subroutine signature */ -optsubsignature: %empty - { $$ = NULL; } +optsubsignature + : empty | subsignature { $$ = $subsignature; } @@ -1370,20 +1375,20 @@ myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE ; /* Basic list expressions */ -optlistexpr: %empty %prec PREC_LOW - { $$ = NULL; } +optlistexpr + : empty %prec PREC_LOW | listexpr %prec PREC_LOW { $$ = $listexpr; } ; -optexpr: %empty - { $$ = NULL; } +optexpr + : empty | expr { $$ = $expr; } ; -optrepl: %empty - { $$ = NULL; } +optrepl + : empty | PERLY_SLASH expr { $$ = $expr; } ; -- cgit v1.2.1