diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-13 12:15:10 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-13 12:15:10 +0900 |
| commit | 100eac3fec17e630567f2088c818910fb7f63b64 (patch) | |
| tree | 03a1c7587b689c31c5a085601f5bd1ba356a0c12 /mrbgems/mruby-compiler/core/parse.y | |
| parent | 6c76926d0504eff50b06f4aea1dc84526403f26e (diff) | |
| download | mruby-100eac3fec17e630567f2088c818910fb7f63b64.tar.gz mruby-100eac3fec17e630567f2088c818910fb7f63b64.zip | |
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.
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 20 |
1 files changed, 19 insertions, 1 deletions
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 { |
