summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorKazuki Tsujimoto <kazuki@callcc.net>2021-03-21 15:12:54 +0900
committerKazuki Tsujimoto <kazuki@callcc.net>2021-03-21 15:14:31 +0900
commit21863470d965b8cc299b1f82417c70d5d26f8ab2 (patch)
tree727faf202cf818d796602b526e17fb9bfea0cb29 /parse.y
parent232433f22423fb6a3ff7a610140c711a964d3b3d (diff)
Pattern matching pin operator against expression [Feature #17411]
This commit is based on the patch by @nobu.
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y18
1 files changed, 14 insertions, 4 deletions
diff --git a/parse.y b/parse.y
index 10cd1000d9..e24d26e6e1 100644
--- a/parse.y
+++ b/parse.y
@@ -1196,7 +1196,7 @@ static int looking_at_eol_p(struct parser_params *p);
%type <node> p_case_body p_cases p_top_expr p_top_expr_body
%type <node> p_expr p_as p_alt p_expr_basic p_find
%type <node> p_args p_args_head p_args_tail p_args_post p_arg
-%type <node> p_value p_primitive p_variable p_var_ref p_const
+%type <node> p_value p_primitive p_variable p_var_ref p_expr_ref p_const
%type <node> p_kwargs p_kwarg p_kw
%type <id> keyword_variable user_variable sym operation operation2 operation3
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
@@ -3994,7 +3994,7 @@ p_top_expr : p_top_expr_body
| p_top_expr_body modifier_if expr_value
{
/*%%%*/
- $$ = new_if(p, $3, remove_begin($1), 0, &@$);
+ $$ = new_if(p, $3, $1, 0, &@$);
fixpos($$, $3);
/*% %*/
/*% ripper: if_mod!($3, $1) %*/
@@ -4002,7 +4002,7 @@ p_top_expr : p_top_expr_body
| p_top_expr_body modifier_unless expr_value
{
/*%%%*/
- $$ = new_unless(p, $3, remove_begin($1), 0, &@$);
+ $$ = new_unless(p, $3, $1, 0, &@$);
fixpos($$, $3);
/*% %*/
/*% ripper: unless_mod!($3, $1) %*/
@@ -4066,6 +4066,7 @@ p_lparen : '(' {$<tbl>$ = push_pktbl(p);};
p_lbracket : '[' {$<tbl>$ = push_pktbl(p);};
p_expr_basic : p_value
+ | p_variable
| p_const p_lparen p_args rparen
{
pop_pktbl(p, $<tbl>2);
@@ -4400,8 +4401,8 @@ p_value : p_primitive
/*% %*/
/*% ripper: dot3!($1, Qnil) %*/
}
- | p_variable
| p_var_ref
+ | p_expr_ref
| p_const
| tBDOT2 p_primitive
{
@@ -4462,6 +4463,15 @@ p_var_ref : '^' tIDENTIFIER
}
;
+p_expr_ref : '^' tLPAREN expr_value ')'
+ {
+ /*%%%*/
+ $$ = NEW_BEGIN($3, &@$);
+ /*% %*/
+ /*% ripper: begin!($3) %*/
+ }
+ ;
+
p_const : tCOLON3 cname
{
/*%%%*/