mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
1fe73dc860
commit
3cee99808d
Notes:
git
2019-09-26 15:11:14 +09:00
3 changed files with 26 additions and 3 deletions
20
parse.y
20
parse.y
|
@ -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
|
||||
|
|
|
@ -434,7 +434,7 @@ class TestISeq < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_to_binary_pattern_matching
|
||||
code = "case foo in []; end"
|
||||
code = "case foo; in []; end"
|
||||
iseq = compile(code)
|
||||
assert_include(iseq.disasm, "TypeError")
|
||||
assert_include(iseq.disasm, "NoMatchingPatternError")
|
||||
|
|
|
@ -1180,6 +1180,13 @@ END
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
################################################################
|
||||
|
||||
def test_modifier_in
|
||||
assert_equal true, (1 in a)
|
||||
assert_equal 1, a
|
||||
end
|
||||
end
|
||||
END_of_GUARD
|
||||
$VERBOSE = verbose
|
||||
|
|
Loading…
Reference in a new issue