Skip to content

Commit

Permalink
parse.y: allow NUMPARAMs (e.g. _1) as hash keys; fix mruby#5785
Browse files Browse the repository at this point in the history
  • Loading branch information
matz authored and lopopolo committed Jan 2, 2023
1 parent d6a85f5 commit 858f4e6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ intern_gen(parser_state *p, const char *s, size_t len)

#define intern_op(op) MRB_OPSYM_2(p->mrb, op)

static mrb_sym
intern_numparam_gen(parser_state *p, int num)
{
char buf[3];
buf[0] = '_'; buf[1] = '0'+num; buf[2] = '\0';
return intern(buf, 2);
}
#define intern_numparam(n) intern_numparam_gen(p,(n))

static void
cons_free_gen(parser_state *p, node *cons)
{
Expand Down Expand Up @@ -3667,6 +3676,10 @@ f_label : tIDENTIFIER tLABEL_TAG
{
local_nest(p);
}
| tNUMPARAM tLABEL_TAG
{
local_nest(p);
}
;

f_kw : f_label arg
Expand Down Expand Up @@ -4031,6 +4044,16 @@ assoc : arg tASSOC arg
{
$$ = cons(new_sym(p, $1), label_reference(p, $1));
}
| tNUMPARAM tLABEL_TAG
{
mrb_sym sym = intern_numparam($1);
$$ = cons(new_sym(p, sym), label_reference(p, sym));
}
| tNUMPARAM tLABEL_TAG arg
{
void_expr_error(p, $3);
$$ = cons(new_sym(p, intern_numparam($1)), $3);
}
| string_fragment tLABEL_TAG arg
{
void_expr_error(p, $3);
Expand Down

0 comments on commit 858f4e6

Please sign in to comment.