def visit_lambda(node)
# [:lambda, [:params, nil, nil, nil, nil, nil, nil, nil], [[:void_stmt]]]
# [:lambda, [:params, nil, nil, nil, nil, nil, nil, nil], [[:@int, "1", [2, 2]], [:@int, "2", [3, 2]]]]
# [:lambda, [:params, nil, nil, nil, nil, nil, nil, nil], [:bodystmt, [[:@int, "1", [2, 2]], [:@int, "2", [3, 2]]], nil, nil, nil]] (on 2.6.0)
_, params, body = node
body = body[1] if body[0] == :bodystmt
check :on_tlambda
write "->"
next_token
first_space = skip_space
write_space_using_setting(first_space, :one)
if empty_params?(params)
if current_token_kind == :on_lparen
next_token
skip_space_or_newline
check :on_rparen
next_token
skip_space_or_newline
end
else
visit params
consume_space
end
if void_exps?(body)
consume_token :on_tlambeg
consume_space
consume_token :on_rbrace
return
end
brace = current_token_value == "{"
if brace
closing_brace_token, index = find_closing_brace_token
# Check if the whole block fits into a single line
if current_token_line == closing_brace_token[0][0]
consume_token :on_tlambeg
consume_space
visit_exps body, with_lines: false
consume_space
consume_token :on_rbrace
return
end
consume_token :on_tlambeg
else
consume_keyword "do"
end
indent_body body, force_multiline: true
write_indent
if brace
consume_token :on_rbrace
else
consume_keyword "end"
end
end