summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2018-02-22 12:23:52 +0000
committerDavid Mitchell <davem@iabyn.com>2018-03-02 13:36:42 +0000
commit436ddf68a973edeede30e3cdf27a8063d7686eec (patch)
tree9870ba1dedc532d0a852e1f7b0a659b9048de878 /perly.y
parent50333c9768fa52a79ec159c7a43b40948291861e (diff)
downloadperl-436ddf68a973edeede30e3cdf27a8063d7686eec.tar.gz
parse subs and signature subs separately
Currently the toker returns a SUB or ANONSUB token at the beginning of a sub (or BEGIN etc). Change it so that in the scope of 'use feature "signatures"', it returns a SIGSUB / ANON_SIGSUB token instead. Then in perly.y, duplicate the 2 rules containing SUB / ANONSUB to cope with these two new tokens. The net effect of this is to use different rules in the parser for parsing subs when signatures are in scope. Since the two sets of rules have just been cut and pasted, there should be no functional changes yet, but that will change shortly.
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y22
1 files changed, 21 insertions, 1 deletions
diff --git a/perly.y b/perly.y
index f10cfbdb11..dd00deb264 100644
--- a/perly.y
+++ b/perly.y
@@ -51,7 +51,7 @@
%token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
%token <opval> PLUGEXPR PLUGSTMT
%token <pval> LABEL
-%token <ival> FORMAT SUB ANONSUB PACKAGE USE
+%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> LOOPEX DOTDOT YADAYADA
@@ -290,6 +290,23 @@ barestmt: PLUGSTMT
intro_my();
parser->parsed_sub = 1;
}
+ | SIGSUB subname startsub
+ {
+ init_named_cv(PL_compcv, $2);
+ parser->in_my = 0;
+ parser->in_my_stash = NULL;
+ }
+ proto subattrlist optsubbody
+ {
+ SvREFCNT_inc_simple_void(PL_compcv);
+ $2->op_type == OP_CONST
+ ? newATTRSUB($3, $2, $5, $6, $7)
+ : newMYSUB($3, $2, $5, $6, $7)
+ ;
+ $$ = NULL;
+ intro_my();
+ parser->parsed_sub = 1;
+ }
| PACKAGE BAREWORD BAREWORD ';'
{
package($3);
@@ -1011,6 +1028,9 @@ anonymous: '[' expr ']'
| ANONSUB startanonsub proto subattrlist realsubbody %prec '('
{ SvREFCNT_inc_simple_void(PL_compcv);
$$ = newANONATTRSUB($2, $3, $4, $5); }
+ | ANON_SIGSUB startanonsub proto subattrlist realsubbody %prec '('
+ { SvREFCNT_inc_simple_void(PL_compcv);
+ $$ = newANONATTRSUB($2, $3, $4, $5); }
;
/* Things called with "do" */