Skip to content

Commit

Permalink
Added SMETHREF
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Nov 15, 2018
1 parent cd9fbe3 commit 2307713
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions compile.c
Expand Up @@ -4524,7 +4524,7 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
case NODE_ATTRASGN:{
const int explicit_receiver =
(type == NODE_CALL || type == NODE_OPCALL ||
type == NODE_METHREF ||
(type == NODE_METHREF && node->nd_recv) ||
(type == NODE_ATTRASGN && !private_recv_p(node)));

if (!lfinish[1] && (node->nd_args || explicit_receiver)) {
Expand Down Expand Up @@ -7499,7 +7499,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
break;
}
case NODE_METHREF:
CHECK(COMPILE_(ret, "receiver", node->nd_recv, popped));
if (node->nd_recv) {
CHECK(COMPILE_(ret, "receiver", node->nd_recv, popped));
}
else {
ADD_INSN(ret, line, putself);
}
ADD_ELEM(ret, &new_insn_body(iseq, line, BIN(methodref), 1, ID2SYM(node->nd_mid))->link);
break;
default:
Expand Down
7 changes: 6 additions & 1 deletion node.c
Expand Up @@ -938,7 +938,12 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
ANN("method reference");
ANN("format: [nd_recv].:[nd_mid]");
ANN("example: foo.:method");
F_NODE(nd_recv, "receiver");
if (node->nd_recv) {
F_NODE(nd_recv, "receiver");
}
else {
F_MSG(nd_recv, "implicit self", "omitted receiver");
}
LAST_NODE;
F_ID(nd_mid, "method name");
return;
Expand Down
10 changes: 9 additions & 1 deletion parse.y
Expand Up @@ -900,6 +900,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
%token tDSTAR "**arg"
%token tAMPER "&"
%token tLAMBDA "->"
%token tSMETHREF "(.:name)"
%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG
%token tSTRING_DBEG tSTRING_DEND tSTRING_DVAR tSTRING_END tLAMBEG tLABEL_END

Expand Down Expand Up @@ -2718,6 +2719,13 @@ primary : literal
/*% %*/
/*% ripper: methref!($1, $3) %*/
}
| tSMETHREF operation2
{
/*%%%*/
$$ = NEW_METHREF(0, $2, &@$);
/*% %*/
/*% ripper: methref!(Qnil, $2) %*/
}
;

primary_value : primary
Expand Down Expand Up @@ -8078,7 +8086,7 @@ parser_yylex(struct parser_params *p)
case ':':
if ((c = nextc(p)) != -1 && parser_is_identchar(p)) {
pushback(p, c);
return tMETHREF;
return IS_lex_state_for(last_state, EXPR_BEG) ? tSMETHREF : tMETHREF;
}
pushback(p, c);
c = ':';
Expand Down

0 comments on commit 2307713

Please sign in to comment.