summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-07-05 01:10:08 -0700
committerRicardo Signes <rjbs@cpan.org>2013-10-05 14:20:08 -0400
commit89f3591148a8f1ca21a2faaed697cfa194632816 (patch)
tree84359a06a80f5705c64334235f13c85f191c3462 /perly.y
parentb9ff0c4900019af7a99b75cd3befc2a4b62c4321 (diff)
downloadperl-89f3591148a8f1ca21a2faaed697cfa194632816.tar.gz
Postfix dereference syntax
$_->$* means $$_ (and compiled down to the same op tree) $_->@* means @$_ ( ditto ditto blah blah blah ) $_->%* means %$_ (...) $_->&* means &$_ $_->** means *$_ $_->@[...] means @$_[...] $_->@{...} means @$_{...} $_->*{...} means *$_{...} $_->@* is not always equivalent to @$_, particularly in contexts like @foo[0], which cannot be written foo->@*[0]. (Just omit the asterisk and it works.)
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y42
1 files changed, 39 insertions, 3 deletions
diff --git a/perly.y b/perly.y
index c48c9b257d..92c61f0972 100644
--- a/perly.y
+++ b/perly.y
@@ -94,6 +94,7 @@
%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
+%type <opval> sliceme gelem
%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
%type <opval> optlistexpr optexpr indirob listop method
%type <opval> formname subname proto subbody cont my_scalar formblock
@@ -845,7 +846,7 @@ method : METHOD
;
/* Some kind of subscripted expression */
-subscripted: star '{' expr ';' '}' /* *main::{something} */
+subscripted: gelem '{' expr ';' '}' /* *main::{something} */
/* In this and all the hash accessors, ';' is
* provided by the tokeniser */
{ $$ = newBINOP(OP_GELEM, 0, $1, scalar($3));
@@ -1195,7 +1196,7 @@ term : termbinop
{ $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
| subscripted
{ $$ = $1; }
- | ary '[' expr ']' /* array slice */
+ | sliceme '[' expr ']' /* array slice */
{ $$ = op_prepend_elem(OP_ASLICE,
newOP(OP_PUSHMARK, 0),
newLISTOP(OP_ASLICE, 0,
@@ -1219,7 +1220,7 @@ term : termbinop
TOKEN_GETMAD($2,$$,'[');
TOKEN_GETMAD($4,$$,']');
}
- | ary '{' expr ';' '}' /* @hash{@keys} */
+ | sliceme '{' expr ';' '}' /* @hash{@keys} */
{ $$ = op_prepend_elem(OP_HSLICE,
newOP(OP_PUSHMARK, 0),
newLISTOP(OP_HSLICE, 0,
@@ -1274,6 +1275,27 @@ term : termbinop
op_append_elem(OP_LIST, $3, scalar($2)));
TOKEN_GETMAD($1,$$,'o');
}
+ | term ARROW '$' '*'
+ { $$ = newSVREF($1);
+ TOKEN_GETMAD($3,$$,'$');
+ }
+ | term ARROW '@' '*'
+ { $$ = newAVREF($1);
+ TOKEN_GETMAD($3,$$,'@');
+ }
+ | term ARROW '%' '*'
+ { $$ = newHVREF($1);
+ TOKEN_GETMAD($3,$$,'%');
+ }
+ | term ARROW '&' '*'
+ { $$ = newUNOP(OP_ENTERSUB, 0,
+ scalar(newCVREF(IVAL($3),$1)));
+ TOKEN_GETMAD($3,$$,'&');
+ }
+ | term ARROW '*' '*' %prec '('
+ { $$ = newGVREF(0,$1);
+ TOKEN_GETMAD($3,$$,'*');
+ }
| LOOPEX /* loop exiting command (goto, last, dump, etc) */
{ $$ = newOP(IVAL($1), OPf_SPECIAL);
PL_hints |= HINT_BLOCK_SCOPE;
@@ -1465,6 +1487,20 @@ star : '*' indirob
}
;
+sliceme : ary
+ | term ARROW '@'
+ { $$ = newAVREF($1);
+ TOKEN_GETMAD($3,$$,'@');
+ }
+ ;
+
+gelem : star
+ | term ARROW '*'
+ { $$ = newGVREF(0,$1);
+ TOKEN_GETMAD($3,$$,'*');
+ }
+ ;
+
/* Indirect objects */
indirob : WORD
{ $$ = scalar($1); }