Skip to content

Commit 64e6728

Browse files
committed
Cleanup
1 parent 9db7b7d commit 64e6728

File tree

2 files changed

+59
-64
lines changed

2 files changed

+59
-64
lines changed

compiler/syntax/src/res_comments_table.ml

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ let log t =
8888
let attach tbl loc comments =
8989
match comments with
9090
| [] -> ()
91-
| comments ->
92-
Printf.eprintf "DEBUG: Attaching %d comments to ___location [%d:%d-%d:%d]\n"
93-
(List.length comments)
94-
loc.Location.loc_start.pos_lnum (loc.Location.loc_start.pos_cnum - loc.Location.loc_start.pos_bol)
95-
loc.Location.loc_end.pos_lnum (loc.Location.loc_end.pos_cnum - loc.Location.loc_end.pos_bol);
96-
List.iter (fun c -> Printf.eprintf " Comment: %S\n" (Comment.txt c)) comments;
97-
Hashtbl.replace tbl loc comments
91+
| comments -> Hashtbl.replace tbl loc comments
9892

9993
(* Partitions a list of comments into three groups based on their position relative to a ___location:
10094
* - leading: comments that end before the ___location's start position
@@ -1214,12 +1208,6 @@ and walk_expression expr t comments =
12141208
| Pexp_variant (_label, None) -> ()
12151209
| Pexp_variant (_label, Some expr) -> walk_expression expr t comments
12161210
| Pexp_array exprs | Pexp_tuple exprs ->
1217-
Printf.eprintf "DEBUG: Processing array/tuple with %d expressions:\n" (List.length exprs);
1218-
List.iteri (fun i e ->
1219-
Printf.eprintf " [%d] Expression at [%d:%d-%d:%d]\n" i
1220-
e.Parsetree.pexp_loc.loc_start.pos_lnum (e.Parsetree.pexp_loc.loc_start.pos_cnum - e.Parsetree.pexp_loc.loc_start.pos_bol)
1221-
e.Parsetree.pexp_loc.loc_end.pos_lnum (e.Parsetree.pexp_loc.loc_end.pos_cnum - e.Parsetree.pexp_loc.loc_end.pos_bol)
1222-
) exprs;
12231211
walk_list (exprs |> List.map (fun e -> Expression e)) t comments
12241212
| Pexp_record (rows, spread_expr) ->
12251213
if rows = [] then attach t.inside expr.pexp_loc comments
@@ -1551,55 +1539,66 @@ and walk_expression expr t comments =
15511539
}
15521540
when Res_parsetree_viewer.is_tuple_array key_values ->
15531541
walk_list [Expression key_values] t comments
1554-
| Pexp_apply {funct = call_expr; args = arguments} ->
1542+
| Pexp_apply {funct = call_expr; args = arguments} -> (
15551543
(* Special handling for Belt.Array.concatMany - treat like an array *)
1556-
(match call_expr.pexp_desc with
1557-
| Pexp_ident {txt = Longident.Ldot (Longident.Ldot (Longident.Lident "Belt", "Array"), "concatMany")}
1544+
match call_expr.pexp_desc with
1545+
| Pexp_ident
1546+
{
1547+
txt =
1548+
Longident.Ldot
1549+
(Longident.Ldot (Longident.Lident "Belt", "Array"), "concatMany");
1550+
}
15581551
when List.length arguments = 1 -> (
1559-
match arguments with
1560-
| [(_, {pexp_desc = Pexp_array sub_arrays})] ->
1561-
Printf.eprintf "DEBUG: Special handling for Belt.Array.concatMany with %d sub-arrays\n" (List.length sub_arrays);
1562-
(* Collect all individual expressions from sub-arrays *)
1563-
let all_exprs = List.fold_left (fun acc sub_array ->
1564-
match sub_array.Parsetree.pexp_desc with
1565-
| Pexp_array exprs -> acc @ exprs
1566-
| _ -> acc @ [sub_array]
1567-
) [] sub_arrays in
1568-
Printf.eprintf "DEBUG: Collected %d individual expressions\n" (List.length all_exprs);
1569-
walk_list (all_exprs |> List.map (fun e -> Expression e)) t comments
1570-
| _ ->
1571-
(* Fallback to regular apply handling *)
1572-
let before, inside, after = partition_by_loc comments call_expr.pexp_loc in
1573-
let after =
1574-
if is_block_expr call_expr then (
1575-
let after_expr, rest =
1576-
partition_adjacent_trailing call_expr.pexp_loc after
1577-
in
1578-
walk_expression call_expr t (List.concat [before; inside; after_expr]);
1579-
rest)
1580-
else (
1581-
attach t.leading call_expr.pexp_loc before;
1582-
walk_expression call_expr t inside;
1583-
after)
1584-
in
1585-
let after_expr, rest =
1586-
partition_adjacent_trailing call_expr.pexp_loc after
1587-
in
1588-
attach t.trailing call_expr.pexp_loc after_expr;
1589-
walk_list
1590-
(arguments
1591-
|> List.map (fun (lbl, expr) ->
1592-
let loc =
1593-
match lbl with
1594-
| Asttypes.Labelled {loc} | Optional {loc} ->
1595-
{loc with loc_end = expr.Parsetree.pexp_loc.loc_end}
1596-
| _ -> expr.pexp_loc
1597-
in
1598-
ExprArgument {expr; loc}))
1599-
t rest)
1552+
match arguments with
1553+
| [(_, {pexp_desc = Pexp_array sub_arrays})] ->
1554+
(* Collect all individual expressions from sub-arrays *)
1555+
let all_exprs =
1556+
List.fold_left
1557+
(fun acc sub_array ->
1558+
match sub_array.Parsetree.pexp_desc with
1559+
| Pexp_array exprs -> acc @ exprs
1560+
| _ -> acc @ [sub_array])
1561+
[] sub_arrays
1562+
in
1563+
walk_list (all_exprs |> List.map (fun e -> Expression e)) t comments
1564+
| _ ->
1565+
(* Fallback to regular apply handling *)
1566+
let before, inside, after =
1567+
partition_by_loc comments call_expr.pexp_loc
1568+
in
1569+
let after =
1570+
if is_block_expr call_expr then (
1571+
let after_expr, rest =
1572+
partition_adjacent_trailing call_expr.pexp_loc after
1573+
in
1574+
walk_expression call_expr t
1575+
(List.concat [before; inside; after_expr]);
1576+
rest)
1577+
else (
1578+
attach t.leading call_expr.pexp_loc before;
1579+
walk_expression call_expr t inside;
1580+
after)
1581+
in
1582+
let after_expr, rest =
1583+
partition_adjacent_trailing call_expr.pexp_loc after
1584+
in
1585+
attach t.trailing call_expr.pexp_loc after_expr;
1586+
walk_list
1587+
(arguments
1588+
|> List.map (fun (lbl, expr) ->
1589+
let loc =
1590+
match lbl with
1591+
| Asttypes.Labelled {loc} | Optional {loc} ->
1592+
{loc with loc_end = expr.Parsetree.pexp_loc.loc_end}
1593+
| _ -> expr.pexp_loc
1594+
in
1595+
ExprArgument {expr; loc}))
1596+
t rest)
16001597
| _ ->
16011598
(* Regular apply handling *)
1602-
let before, inside, after = partition_by_loc comments call_expr.pexp_loc in
1599+
let before, inside, after =
1600+
partition_by_loc comments call_expr.pexp_loc
1601+
in
16031602
let after =
16041603
if is_block_expr call_expr then (
16051604
let after_expr, rest =

compiler/syntax/src/res_printer.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,7 +4054,7 @@ and print_belt_array_concat_apply ~state sub_lists cmt_tbl =
40544054
| _ -> Doc.concat [Doc.text ","; Doc.line]
40554055
in
40564056
let spread_doc = make_spread_doc comma_before_spread spread in
4057-
let expressions_doc =
4057+
let expressions_doc =
40584058
Doc.join
40594059
~sep:(Doc.concat [Doc.text ","; Doc.line])
40604060
(List.map
@@ -4066,11 +4066,7 @@ and print_belt_array_concat_apply ~state sub_lists cmt_tbl =
40664066
| Nothing -> doc)
40674067
expressions)
40684068
in
4069-
Doc.concat
4070-
[
4071-
expressions_doc;
4072-
spread_doc;
4073-
]
4069+
Doc.concat [expressions_doc; spread_doc]
40744070
in
40754071
Doc.group
40764072
(Doc.concat

0 commit comments

Comments
 (0)