Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit c7969a8

Browse files
format
1 parent 3c9c49f commit c7969a8

File tree

3 files changed

+63
-40
lines changed

3 files changed

+63
-40
lines changed

src/res_core.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,10 @@ let makeListAppend loc seq =
465465
in
466466
Ast_helper.Exp.apply ~loc
467467
(Ast_helper.Exp.ident (Location.mkloc (Longident.Lident "@") loc))
468-
[Nolabel, e1;
469-
Nolabel, exp_el]
468+
[(Nolabel, e1); (Nolabel, exp_el)]
470469
in
471470
handle_seq seq
472471

473-
474472
(* TODO: diagnostic reporting *)
475473
let lidentOfPath longident =
476474
match Longident.flatten longident |> List.rev with

src/res_parsetree_viewer.ml

+13
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ let collectListExpressions expr =
9292
in
9393
collect [] expr
9494

95+
let collectConcatListExpressions expr =
96+
let rec collect acc expr =
97+
match expr.pexp_desc with
98+
| Pexp_apply
99+
( {pexp_desc = Pexp_ident {txt = Longident.Lident "@"}},
100+
[(Nolabel, l1); (Nolabel, l2)] ) ->
101+
(* l1 @ l2 *)
102+
let subList = collectListExpressions l1 in
103+
collect (subList :: acc) l2
104+
| _ -> List.rev (collectListExpressions expr :: acc)
105+
in
106+
collect [] expr
107+
95108
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
96109
let rewriteUnderscoreApply expr =
97110
match expr.pexp_desc with

src/res_printer.ml

+49-37
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,41 @@ and printIfChain ~customLayout pexp_attributes ifs elseExpr cmtTbl =
26292629
Doc.concat [printAttributes ~customLayout attrs cmtTbl; ifDocs; elseDoc]
26302630

26312631
and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
2632+
let makeSpreadDoc = function
2633+
| Some expr ->
2634+
Doc.concat
2635+
[
2636+
Doc.text ",";
2637+
Doc.line;
2638+
Doc.dotdotdot;
2639+
(let doc = printExpressionWithComments ~customLayout expr cmtTbl in
2640+
match Parens.expr expr with
2641+
| Parens.Parenthesized -> addParens doc
2642+
| Braced braces -> printBraces doc expr braces
2643+
| Nothing -> doc);
2644+
]
2645+
| None -> Doc.nil
2646+
in
2647+
let makeSubListDoc (expressions, spread) =
2648+
let spreadDoc = makeSpreadDoc spread in
2649+
Doc.concat
2650+
[
2651+
Doc.softLine;
2652+
Doc.join
2653+
~sep:(Doc.concat [Doc.text ","; Doc.line])
2654+
(List.map
2655+
(fun expr ->
2656+
let doc =
2657+
printExpressionWithComments ~customLayout expr cmtTbl
2658+
in
2659+
match Parens.expr expr with
2660+
| Parens.Parenthesized -> addParens doc
2661+
| Braced braces -> printBraces doc expr braces
2662+
| Nothing -> doc)
2663+
expressions);
2664+
spreadDoc;
2665+
]
2666+
in
26322667
let printedExpression =
26332668
match e.pexp_desc with
26342669
| Parsetree.Pexp_constant c ->
@@ -2641,47 +2676,11 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
26412676
[Doc.text "list{"; printCommentsInside cmtTbl e.pexp_loc; Doc.rbrace]
26422677
| Pexp_construct ({txt = Longident.Lident "::"}, _) ->
26432678
let expressions, spread = ParsetreeViewer.collectListExpressions e in
2644-
let spreadDoc =
2645-
match spread with
2646-
| Some expr ->
2647-
Doc.concat
2648-
[
2649-
Doc.text ",";
2650-
Doc.line;
2651-
Doc.dotdotdot;
2652-
(let doc =
2653-
printExpressionWithComments ~customLayout expr cmtTbl
2654-
in
2655-
match Parens.expr expr with
2656-
| Parens.Parenthesized -> addParens doc
2657-
| Braced braces -> printBraces doc expr braces
2658-
| Nothing -> doc);
2659-
]
2660-
| None -> Doc.nil
2661-
in
26622679
Doc.group
26632680
(Doc.concat
26642681
[
26652682
Doc.text "list{";
2666-
Doc.indent
2667-
(Doc.concat
2668-
[
2669-
Doc.softLine;
2670-
Doc.join
2671-
~sep:(Doc.concat [Doc.text ","; Doc.line])
2672-
(List.map
2673-
(fun expr ->
2674-
let doc =
2675-
printExpressionWithComments ~customLayout expr
2676-
cmtTbl
2677-
in
2678-
match Parens.expr expr with
2679-
| Parens.Parenthesized -> addParens doc
2680-
| Braced braces -> printBraces doc expr braces
2681-
| Nothing -> doc)
2682-
expressions);
2683-
spreadDoc;
2684-
]);
2683+
Doc.indent (makeSubListDoc (expressions, spread));
26852684
Doc.trailingComma;
26862685
Doc.softLine;
26872686
Doc.rbrace;
@@ -2980,6 +2979,19 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
29802979
])
29812980
| extension ->
29822981
printExtension ~customLayout ~atModuleLvl:false extension cmtTbl)
2982+
| Pexp_apply
2983+
( {pexp_desc = Pexp_ident {txt = Longident.Lident "@"}},
2984+
[(Nolabel, _); (Nolabel, _)] ) ->
2985+
let subLists = ParsetreeViewer.collectConcatListExpressions e in
2986+
Doc.group
2987+
(Doc.concat
2988+
[
2989+
Doc.text "list{";
2990+
Doc.indent (Doc.concat (List.map makeSubListDoc subLists));
2991+
Doc.trailingComma;
2992+
Doc.softLine;
2993+
Doc.rbrace;
2994+
])
29832995
| Pexp_apply _ ->
29842996
if ParsetreeViewer.isUnaryExpression e then
29852997
printUnaryExpression ~customLayout e cmtTbl

0 commit comments

Comments
 (0)