Skip to content

Commit

Permalink
elbrujohalcon.otp_formatter.update- Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
elbrujohalcon committed Oct 24, 2024
1 parent 070fccd commit 80dd875
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/formatters/default_formatter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -594,23 +594,17 @@ lay_no_comments(Node, Ctxt) ->
Ctxt1 = reset_prec(Ctxt),
D1 = lay(erl_syntax:generator_pattern(Node), Ctxt1),
D2 = lay(erl_syntax:generator_body(Node), Ctxt1),
prettypr:par([D1,
prettypr:beside(
prettypr:text("<- "), D2)],
Ctxt1#ctxt.break_indent);
lay_generator(D1, D2, "<- ", Ctxt1);
binary_generator ->
Ctxt1 = reset_prec(Ctxt),
D1 = lay(erl_syntax:binary_generator_pattern(Node), Ctxt1),
D2 = lay(erl_syntax:binary_generator_body(Node), Ctxt1),
prettypr:par([D1,
prettypr:beside(
prettypr:text("<= "), D2)],
Ctxt1#ctxt.break_indent);
lay_generator(D1, D2, "<= ", Ctxt1);
map_generator ->
Ctxt1 = reset_prec(Ctxt),
D1 = lay(erl_syntax:map_generator_pattern(Node), Ctxt1),
D2 = lay(erl_syntax:map_generator_body(Node), Ctxt1),
prettypr:par([D1, prettypr:beside(prettypr:text("<- "), D2)], Ctxt1#ctxt.break_indent);
lay_generator(D1, D2, "<- ", Ctxt1);
implicit_fun ->
D = lay(erl_syntax:implicit_fun_name(Node), reset_prec(Ctxt)),
prettypr:beside(lay_text_float("fun "), D);
Expand All @@ -631,7 +625,7 @@ lay_no_comments(Node, Ctxt) ->
D1 = lay(erl_syntax:map_comp_template(Node), Ctxt1),
D2 = lay_items(erl_syntax:map_comp_body(Node), Ctxt1, fun lay/2),
D3 = prettypr:beside(lay_text_float("|| "), prettypr:beside(D2, lay_text_float("}"))),
prettypr:beside(lay_text_float("#{"),prettypr:par([D1, D3]));
prettypr:beside(lay_text_float("#{"), prettypr:par([D1, D3]));
macro ->
%% This is formatted similar to a normal function call or a variable
N = macro_name(Node, variable),
Expand Down Expand Up @@ -1095,6 +1089,12 @@ maybe_convert_to_qualifier(Node, #ctxt{force_arity_qualifiers = true}) ->
Node
end.

lay_generator(D1, D2, Connector, Ctxt) ->
prettypr:par([D1,
prettypr:beside(
prettypr:text(Connector), D2)],
Ctxt#ctxt.break_indent).

lay_nested_infix_expr(Node, #ctxt{parenthesize_infix_operations = false} = Ctxt) ->
lay(Node, Ctxt);
lay_nested_infix_expr(Node, #ctxt{parenthesize_infix_operations = true} = Ctxt) ->
Expand Down

0 comments on commit 80dd875

Please sign in to comment.