diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-21 10:29:34 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-26 15:10:48 +0900 |
commit | 3cee99808d629c0ec493955ce8ea019d1f8a637b (patch) | |
tree | ec38ae37041a16a138f668e700570d74f7446e07 /parse.y | |
parent | 1fe73dc8609c4bac9e517dc70f602a16dae556cc (diff) |
[EXPERIMENTAL] Expression with modifier `in`
[Feature #15865]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2485
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -1127,7 +1127,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in %nonassoc tLOWEST %nonassoc tLBRACE_ARG -%nonassoc modifier_if modifier_unless modifier_while modifier_until +%nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in %left keyword_or keyword_and %right keyword_not %nonassoc keyword_defined @@ -1537,7 +1537,23 @@ expr : command_call { $$ = call_uni_op(p, method_cond(p, $2, &@2), '!', &@1, &@$); } - | arg + | arg keyword_in + { + SET_LEX_STATE(EXPR_BEG|EXPR_LABEL); + p->command_start = FALSE; + $<num>$ = p->in_kwarg; + p->in_kwarg = 1; + } + p_top_expr_body + { + p->in_kwarg = !!$<num>2; + /*%%%*/ + $$ = NEW_CASE3($1, NEW_IN($4, NEW_TRUE(&@4), NEW_FALSE(&@4), &@4), &@$); + rb_warn0L(nd_line($$), "Pattern matching is experimental, and the behavior may change in future versions of Ruby!"); + /*% %*/ + /*% ripper: case!($1, in!($4, Qnil, Qnil)) %*/ + } + | arg %prec tLBRACE_ARG ; expr_value : expr |