From 100eac3fec17e630567f2088c818910fb7f63b64 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 13 Sep 2021 12:15:10 +0900 Subject: 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. --- mrbgems/mruby-compiler/core/parse.y | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 0cdb206a6..d71e90176 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -1292,6 +1292,24 @@ var_reference(parser_state *p, node *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; static node* @@ -4007,7 +4025,7 @@ assoc : arg tASSOC arg } | 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 { -- cgit v1.2.3