@@ -142,44 +142,71 @@ def visit_call_node(node)
142
142
raise NotImplementedError , "More than two arguments for operator"
143
143
end
144
144
elsif node . call_operator_loc . nil?
145
- # In Ripper a method call like "puts myvar" with no parenthesis is a "command"
145
+ # In Ripper a method call like "puts myvar" with no parenthesis is a "command".
146
146
bounds ( node . message_loc )
147
147
ident_val = on_ident ( node . message )
148
- args = args_node_to_arguments ( node . arguments )
149
- return on_command ( ident_val , args )
148
+ args = node . arguments . nil? ? nil : args_node_to_arguments ( node . arguments )
149
+
150
+ # Unless it has a block, and then it's an fcall (e.g. "foo { bar }")
151
+ if node . block
152
+ block_val = visit ( node . block )
153
+ # In these calls, even if node.arguments is nil, we still get an :args_new call.
154
+ method_args_val = on_method_add_arg ( on_fcall ( ident_val ) , args_node_to_arguments ( node . arguments ) )
155
+ return on_method_add_block ( method_args_val , on_brace_block ( nil , block_val ) )
156
+ else
157
+ return on_command ( ident_val , args )
158
+ end
150
159
else
151
160
operator = node . call_operator_loc . slice
152
- if operator == "."
161
+ if operator == "." || operator == "&."
153
162
left_val = visit ( node . receiver )
154
163
155
164
bounds ( node . call_operator_loc )
156
- dot_val = on_period ( node . call_operator )
165
+ operator_val = operator == "." ? on_period ( node . call_operator ) : on_op ( node . call_operator )
157
166
158
167
bounds ( node . message_loc )
159
168
right_val = on_ident ( node . message )
160
169
161
- return on_call ( left_val , dot_val , right_val )
170
+ call_val = on_call ( left_val , operator_val , right_val )
171
+
172
+ if node . block
173
+ block_val = visit ( node . block )
174
+ return on_method_add_block ( call_val , on_brace_block ( nil , block_val ) )
175
+ else
176
+ return call_val
177
+ end
162
178
else
163
- raise NotImplementedError , "operator other than dot for call: #{ operator . inspect } "
179
+ raise NotImplementedError , "operator other than . or &. for call: #{ operator . inspect } "
164
180
end
165
181
end
166
182
end
167
183
168
184
# A non-operator method call with parentheses
169
- args = on_arg_paren ( args_node_to_arguments ( node . arguments ) )
185
+ args = on_arg_paren ( node . arguments . nil? ? nil : args_node_to_arguments ( node . arguments ) )
170
186
171
187
bounds ( node . message_loc )
172
188
ident_val = on_ident ( node . message )
173
189
174
190
bounds ( node . location )
175
191
args_call_val = on_method_add_arg ( on_fcall ( ident_val ) , args )
176
192
if node . block
177
- raise NotImplementedError , "Method call with a block!"
193
+ block_val = visit ( node . block )
194
+
195
+ return on_method_add_block ( args_call_val , on_brace_block ( nil , block_val ) )
178
196
else
179
197
return args_call_val
180
198
end
181
199
end
182
200
201
+ # Visit a BlockNode
202
+ def visit_block_node ( node )
203
+ if node . body . nil?
204
+ on_stmts_add ( on_stmts_new , on_void_stmt )
205
+ else
206
+ visit ( node . body )
207
+ end
208
+ end
209
+
183
210
# Visit an AndNode
184
211
def visit_and_node ( node )
185
212
visit_binary_operator ( node )
@@ -256,7 +283,7 @@ def visit_statements_node(node)
256
283
# Ripper generates an interesting format of argument list.
257
284
# We'd like to convert an ArgumentsNode to one.
258
285
def args_node_to_arguments ( args_node )
259
- return nil if args_node . nil?
286
+ return on_args_new if args_node . nil?
260
287
261
288
args = on_args_new
262
289
args_node . arguments . each do |arg |
0 commit comments