diff --git i/parse.y w/parse.y index 463781ce3a9..e125dbb2554 100644 --- i/parse.y +++ w/parse.y @@ -4614,6 +4614,30 @@ primary : inline_primary p->ctxt.cant_return = $k_class.cant_return; p->ctxt.shareable_constant_value = $k_class.shareable_constant_value; } + | k_class cpath '=' primary_value[cdef] term + { + begin_definition("class", &@k_class, &@cpath); + YYLTYPE loc = code_loc_gen(&@cpath, &@cdef); + $$ = const_decl(p, $cpath, &@cpath); + $$ = node_assign(p, $$, $cdef, NO_LEX_CTXT, &loc); + $$ = NEW_BEGIN($$, &loc); + /*% ripper: stmts_add!(stmts_new!, assign!($:cpath, $:cdef)) %*/ + }[cdecl] + bodystmt + k_end + { + $$ = NEW_CLASS($cpath, $bodystmt, 0, &@$); + nd_set_line(RNODE_CLASS($$)->nd_body, @k_end.end_pos.lineno); + set_line_body($bodystmt, @cdef.end_pos.lineno); + nd_set_line($$, @cdef.end_pos.lineno); + /*% ripper: class!($:cpath, Qnil, $:bodystmt) %*/ + local_pop(p); + p->ctxt.in_class = $k_class.in_class; + p->ctxt.cant_return = $k_class.cant_return; + p->ctxt.shareable_constant_value = $k_class.shareable_constant_value; + /*% ripper: stmts_add!($:cdecl, $:$) %*/ + $$ = block_append(p, $cdecl, $$); + } | k_class tLSHFT expr_value { begin_definition("", &@k_class, &@tLSHFT); @@ -4650,6 +4674,30 @@ primary : inline_primary p->ctxt.cant_return = $k_module.cant_return; p->ctxt.shareable_constant_value = $k_module.shareable_constant_value; } + | k_module cpath '=' primary_value[cdef] term + { + begin_definition("module", &@k_module, &@cpath); + YYLTYPE loc = code_loc_gen(&@cpath, &@cdef); + $$ = const_decl(p, $cpath, &@cpath); + $$ = node_assign(p, $$, $cdef, NO_LEX_CTXT, &loc); + $$ = NEW_BEGIN($$, &loc); + /*% ripper: stmts_add!(stmts_new!, assign!($:cpath, $:cdef)) %*/ + }[cdecl] + bodystmt + k_end + { + $$ = NEW_MODULE($cpath, $bodystmt, &@$); + nd_set_line(RNODE_MODULE($$)->nd_body, @k_end.end_pos.lineno); + set_line_body($bodystmt, @cpath.end_pos.lineno); + nd_set_line($$, @cpath.end_pos.lineno); + /*% ripper: module!($:cpath, $:bodystmt) %*/ + local_pop(p); + p->ctxt.in_class = $k_module.in_class; + p->ctxt.cant_return = $k_module.cant_return; + p->ctxt.shareable_constant_value = $k_module.shareable_constant_value; + /*% ripper: stmts_add!($:cdecl, $:$) %*/ + $$ = block_append(p, $cdecl, $$); + } | defn_head[head] f_arglist[args] {