aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authorKazuki Tsujimoto <kazuki@callcc.net>2019-09-01 16:39:34 +0900
committerKazuki Tsujimoto <kazuki@callcc.net>2019-09-01 16:39:34 +0900
commit94d6ec1d90bb28e5f303867b048e6322d8781cb1 (patch)
tree55a794614931f6dc7778f6b1b672ca3a01f0b34f /parse.y
parentcda5745c1bacdb3be8384d21ee0dd70a9d95af5b (diff)
downloadruby-94d6ec1d90bb28e5f303867b048e6322d8781cb1.tar.gz
Make pattern matching support **nil syntax
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y21
1 files changed, 19 insertions, 2 deletions
diff --git a/parse.y b/parse.y
index f6d6e27eb7..6729e104be 100644
--- a/parse.y
+++ b/parse.y
@@ -1033,7 +1033,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
%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
%type <id> f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon
-%type <id> p_kwrest
+%type <id> p_kwrest p_kwnorest
%type <id> f_no_kwarg
%token END_OF_INPUT 0 "end-of-input"
%token <id> '.'
@@ -3950,6 +3950,14 @@ p_kwargs : p_kwarg ',' p_kwrest
{
$$ = new_hash_pattern_tail(p, new_hash(p, Qnone, &@$), $1, &@$);
}
+ | p_kwarg ',' p_kwnorest
+ {
+ $$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), ID2SYM(idNil), &@$);
+ }
+ | p_kwnorest
+ {
+ $$ = new_hash_pattern_tail(p, new_hash(p, Qnone, &@$), ID2SYM(idNil), &@$);
+ }
;
p_kwarg : p_kw
@@ -4026,6 +4034,12 @@ p_kwrest : kwrest_mark tIDENTIFIER
}
;
+p_kwnorest : kwrest_mark keyword_nil
+ {
+ $$ = 0;
+ }
+ ;
+
p_value : p_primitive
| p_primitive tDOT2 p_primitive
{
@@ -11253,7 +11267,10 @@ new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, co
int saved_line = p->ruby_sourceline;
NODE *node, *kw_rest_arg_node;
- if (kw_rest_arg) {
+ if (kw_rest_arg == ID2SYM(idNil)) {
+ kw_rest_arg_node = NODE_SPECIAL_NO_REST_KEYWORD;
+ }
+ else if (kw_rest_arg) {
kw_rest_arg_node = assignable(p, kw_rest_arg, 0, loc);
}
else {