@@ -215,7 +215,7 @@ defmodule Macro do
215
215
216
216
# left -> right
217
217
def to_binary ( { :-> , _ , _ } = arrow ) do
218
- "(" <> arrow_to_binary ( arrow ) <> ")"
218
+ "(" <> arrow_to_binary ( arrow , true ) <> ")"
219
219
end
220
220
221
221
# Binary ops
@@ -287,8 +287,8 @@ defmodule Macro do
287
287
288
288
defp block_to_binary ( { :-> , _ , exprs } ) do
289
289
Enum . map_join ( exprs , "\n " , fn ( { left , right } ) ->
290
- left = Enum . map_join ( left , ", " , to_binary ( & 1 ) )
291
- left <> " ->\n " <> adjust_new_lines block_to_binary ( right ) , "\n "
290
+ left = comma_join_or_empty_paren ( left , false )
291
+ left <> "->\n " <> adjust_new_lines block_to_binary ( right ) , "\n "
292
292
end )
293
293
end
294
294
@@ -304,13 +304,20 @@ defmodule Macro do
304
304
305
305
defp op_to_binary ( expr ) , do: to_binary ( expr )
306
306
307
- defp arrow_to_binary ( { :-> , _ , pairs } ) do
307
+ defp arrow_to_binary ( { :-> , _ , pairs } , paren // false ) do
308
308
Enum . map_join ( pairs , "; " , fn ( { left , right } ) ->
309
- left = Enum . map_join ( left , ", " , to_binary ( & 1 ) )
310
- left <> " -> " <> to_binary ( right )
309
+ left = comma_join_or_empty_paren ( left , paren )
310
+ left <> "-> " <> to_binary ( right )
311
311
end )
312
312
end
313
313
314
+ defp comma_join_or_empty_paren ( [ ] , true ) , do: "() "
315
+ defp comma_join_or_empty_paren ( [ ] , false ) , do: ""
316
+
317
+ defp comma_join_or_empty_paren ( left , _ ) do
318
+ Enum . map_join ( left , ", " , to_binary ( & 1 ) ) <> " "
319
+ end
320
+
314
321
defp adjust_new_lines ( block , replacement ) do
315
322
bc << x >> in bits block do
316
323
<< case x == ?\n do
0 commit comments