summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-05-13 15:31:46 -0700
committerJeremy Evans <code@jeremyevans.net>2021-07-15 09:56:02 -0700
commitfa87f72e1e84e2b55516be188f00434a683b924c (patch)
tree0c4efbae462e0ebae46447ea0e18bbea4d7821f0 /parse.y
parentf1035248af04b2a4d58990740c3f1b840a5eac78 (diff)
Add pattern matching pin support for instance/class/global variables
Pin matching for local variables and constants is already supported, and it is fairly simple to add support for these variable types. Note that pin matching for method calls is still not supported without wrapping in parentheses (pin expressions). I think that's for the best as method calls are far more complex (arguments/blocks). Implements [Feature #17724]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4502
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y14
1 files changed, 13 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index df16cf62365..dec4b7dfd9c 100644
--- a/parse.y
+++ b/parse.y
@@ -1203,7 +1203,7 @@ static int looking_at_eol_p(struct parser_params *p);
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
%type <id> f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon
%type <id> p_rest p_kwrest p_kwnorest p_any_kwrest p_kw_label
-%type <id> f_no_kwarg f_any_kwrest args_forward excessed_comma
+%type <id> f_no_kwarg f_any_kwrest args_forward excessed_comma nonlocal_var
%type <ctxt> lex_ctxt /* keep <ctxt> in ripper */
%token END_OF_INPUT 0 "end-of-input"
%token <id> '.'
@@ -4517,6 +4517,13 @@ p_var_ref : '^' tIDENTIFIER
/*% %*/
/*% ripper: var_ref!($2) %*/
}
+ | '^' nonlocal_var
+ {
+ /*%%%*/
+ if (!($$ = gettable(p, $2, &@$))) $$ = NEW_BEGIN(0, &@$);
+ /*% %*/
+ /*% ripper: var_ref!($2) %*/
+ }
;
p_expr_ref : '^' tLPAREN expr_value ')'
@@ -4993,6 +5000,11 @@ simple_numeric : tINTEGER
| tIMAGINARY
;
+nonlocal_var : tIVAR
+ | tGVAR
+ | tCVAR
+ ;
+
user_variable : tIDENTIFIER
| tIVAR
| tGVAR