Skip to content

Commit 382678d

Browse files
committed
[Bug #19788] Use the result of tCOLON2 event
1 parent 6a5c548 commit 382678d

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

parse.y

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs
20452045
/*%%%*/
20462046
$$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $6, &@$);
20472047
/*% %*/
2048-
/*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $6) %*/
2048+
/*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/
20492049
}
20502050
| defn_head f_opt_paren_args '=' endless_command
20512051
{
@@ -2316,14 +2316,14 @@ command : fcall command_args %prec tLOWEST
23162316
/*%%%*/
23172317
$$ = new_command_qcall(p, ID2VAL(idCOLON2), $1, $3, $4, Qnull, &@3, &@$);
23182318
/*% %*/
2319-
/*% ripper: command_call!($1, ID2VAL(idCOLON2), $3, $4) %*/
2319+
/*% ripper: command_call!($1, $2, $3, $4) %*/
23202320
}
23212321
| primary_value tCOLON2 operation2 command_args cmd_brace_block
23222322
{
23232323
/*%%%*/
23242324
$$ = new_command_qcall(p, ID2VAL(idCOLON2), $1, $3, $4, $5, &@3, &@$);
23252325
/*% %*/
2326-
/*% ripper: method_add_block!(command_call!($1, ID2VAL(idCOLON2), $3, $4), $5) %*/
2326+
/*% ripper: method_add_block!(command_call!($1, $2, $3, $4), $5) %*/
23272327
}
23282328
| keyword_super command_args
23292329
{
@@ -2599,7 +2599,7 @@ lhs : user_variable
25992599
/*%%%*/
26002600
$$ = attrset(p, $1, idCOLON2, $3, &@$);
26012601
/*% %*/
2602-
/*% ripper: field!($1, ID2VAL(idCOLON2), $3) %*/
2602+
/*% ripper: field!($1, $2, $3) %*/
26032603
}
26042604
| primary_value call_op tCONSTANT
26052605
{
@@ -2790,7 +2790,7 @@ arg : lhs '=' lex_ctxt arg_rhs
27902790
/*%%%*/
27912791
$$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $6, &@$);
27922792
/*% %*/
2793-
/*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $6) %*/
2793+
/*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/
27942794
}
27952795
| primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt arg_rhs
27962796
{
@@ -4351,14 +4351,14 @@ method_call : fcall paren_args
43514351
$$ = new_qcall(p, ID2VAL(idCOLON2), $1, $3, $4, &@3, &@$);
43524352
nd_set_line($$, @3.end_pos.lineno);
43534353
/*% %*/
4354-
/*% ripper: method_add_arg!(call!($1, ID2VAL(idCOLON2), $3), $4) %*/
4354+
/*% ripper: method_add_arg!(call!($1, $2, $3), $4) %*/
43554355
}
43564356
| primary_value tCOLON2 operation3
43574357
{
43584358
/*%%%*/
43594359
$$ = new_qcall(p, ID2VAL(idCOLON2), $1, $3, Qnull, &@3, &@$);
43604360
/*% %*/
4361-
/*% ripper: call!($1, ID2VAL(idCOLON2), $3) %*/
4361+
/*% ripper: call!($1, $2, $3) %*/
43624362
}
43634363
| primary_value call_op paren_args
43644364
{
@@ -4374,7 +4374,7 @@ method_call : fcall paren_args
43744374
$$ = new_qcall(p, ID2VAL(idCOLON2), $1, ID2VAL(idCall), $3, &@2, &@$);
43754375
nd_set_line($$, @2.end_pos.lineno);
43764376
/*% %*/
4377-
/*% ripper: method_add_arg!(call!($1, ID2VAL(idCOLON2), ID2VAL(idCall)), $3) %*/
4377+
/*% ripper: method_add_arg!(call!($1, $2, ID2VAL(idCall)), $3) %*/
43784378
}
43794379
| keyword_super paren_args
43804380
{

test/ripper/test_parser_events.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,23 @@ def test_call
499499
assert_equal "[call(ref(self),&.,foo,[])]", tree
500500
end
501501

502+
def test_call_colon2
503+
hook = Module.new do
504+
def on_op(op)
505+
super("(op: #{op.inspect})")
506+
end
507+
def on_call(recv, name, *args)
508+
super(recv, "(method: #{name})", *args)
509+
end
510+
def on_ident(name)
511+
super("(ident: #{name.inspect})")
512+
end
513+
end
514+
515+
parser = DummyParser.new("a::b").extend(hook)
516+
assert_equal '[call(vcall((ident: "a")),(method: (op: "::")),(ident: "b"))]', parser.parse.to_s
517+
end
518+
502519
def test_excessed_comma
503520
thru_excessed_comma = false
504521
parse("proc{|x,|}", :on_excessed_comma) {thru_excessed_comma = true}

test/ripper/test_scanner_events.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ def test_backtick
179179
scan('backtick', %q[p `make all`])
180180
end
181181

182+
def test_colon2_call
183+
assert_equal ["::"],
184+
scan('op', %q[ a::b ])
185+
end
186+
182187
def test_comma
183188
assert_equal [','] * 6,
184189
scan('comma', %q[ m(0,1,2,3,4,5,6) ])

0 commit comments

Comments
 (0)