parse.y: allow non-local variable access from hash value omission.

For example, `{p:}` (means `{p:p}`) and `{String:}` (`{String:String}`)
should be allowed like CRuby.
parent 6c76926d
...@@ -1292,6 +1292,24 @@ var_reference(parser_state *p, node *lhs) ...@@ -1292,6 +1292,24 @@ var_reference(parser_state *p, node *lhs)
return lhs; return lhs;
} }
static node*
label_reference(parser_state *p, mrb_sym sym)
{
const char *name = mrb_sym_name(p->mrb, sym);
node *n;
if (local_var_p(p, sym)) {
n = new_lvar(p, sym);
}
else if (ISUPPER(name[0])) {
n = new_const(p, sym);
}
else {
n = new_fcall(p, sym, 0);
}
return n;
}
typedef enum mrb_string_type string_type; typedef enum mrb_string_type string_type;
static node* static node*
...@@ -4007,7 +4025,7 @@ assoc : arg tASSOC arg ...@@ -4007,7 +4025,7 @@ assoc : arg tASSOC arg
} }
| tIDENTIFIER tLABEL_TAG | tIDENTIFIER tLABEL_TAG
{ {
$$ = cons(new_sym(p, $1), new_lvar(p, $1)); $$ = cons(new_sym(p, $1), label_reference(p, $1));
} }
| string_fragment tLABEL_TAG arg | string_fragment tLABEL_TAG arg
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment