Skip to content

Commit 30f99cb

Browse files
committed
simplify
1 parent 771034d commit 30f99cb

5 files changed

Lines changed: 6 additions & 34 deletions

File tree

lib/Fmt_ast.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ let box_fun_sig_args c =
119119
| `Fit_or_vertical -> hvbox
120120
| `Wrap | `Smart -> hovbox
121121

122-
let sugar_pmod_functor c ~for_functor_kw pmod =
123-
let source_is_long = Source.is_long_pmod_functor c.source in
124-
Sugar.functor_ c.cmts ~for_functor_kw ~source_is_long pmod
125-
126122
let drop_while ~f s =
127123
let i = ref 0 in
128124
while !i < String.length s && f !i s.[!i] do
@@ -2045,7 +2041,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
20452041
| Pexp_letmodule (name, pmod, exp) ->
20462042
let keyword = str "let module" $ fmt_extension_suffix c ext in
20472043
let xargs, xbody =
2048-
sugar_pmod_functor c ~for_functor_kw:false (sub_mod ~ctx pmod)
2044+
Sugar.functor_ c.cmts ~for_functor_kw:false (sub_mod ~ctx pmod)
20492045
in
20502046
let xbody, xmty =
20512047
match xbody.ast with
@@ -3847,7 +3843,7 @@ and fmt_module_expr ?(can_break_before_struct = false) c ({ast= m; _} as xmod)
38473843
( Cmts.fmt_after c pmod_loc
38483844
$ fmt_attributes c ~pre:(str " ") ~key:"@" atrs ) }
38493845
| Pmod_functor _ ->
3850-
let xargs, me = sugar_pmod_functor c ~for_functor_kw:true xmod in
3846+
let xargs, me = Sugar.functor_ c.cmts ~for_functor_kw:true xmod in
38513847
let doc, atrs = doc_atrs pmod_attributes in
38523848
let {opn; pro; psp; bdy; cls; esp; epi} = fmt_module_expr c me in
38533849
{ empty with
@@ -4328,7 +4324,7 @@ and fmt_module_binding c ctx ~rec_flag ~first pmb =
43284324
else str "and"
43294325
in
43304326
let xargs, xbody =
4331-
sugar_pmod_functor c ~for_functor_kw:false (sub_mod ~ctx pmb.pmb_expr)
4327+
Sugar.functor_ c.cmts ~for_functor_kw:false (sub_mod ~ctx pmb.pmb_expr)
43324328
in
43334329
let xbody, xmty =
43344330
match xbody.ast with

lib/Source.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ let is_long_pexp_open source {Parsetree.pexp_desc; _} =
204204
contains_token_between source ~from ~upto Parser.IN
205205
| _ -> false
206206
207-
let is_long_pmod_functor source Parsetree.{pmod_desc; pmod_loc= from; _} =
208-
match pmod_desc with
209-
| Pmod_functor (_, {pmod_loc= upto; _}) ->
210-
contains_token_between source ~from ~upto Parser.FUNCTOR
211-
| _ -> false
212-
213207
let lexbuf_from_loc t (l : Location.t) =
214208
let s = string_at t l.loc_start l.loc_end in
215209
Lexing.from_string s

lib/Source.mli

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ val is_long_pexp_open : t -> Parsetree.expression -> bool
5555
(** [is_long_pexp_open source exp] holds if [exp] is a [Pexp_open] expression
5656
that is expressed in long ('let open') form in source. *)
5757

58-
val is_long_pmod_functor : t -> Parsetree.module_expr -> bool
59-
(** [is_long_pmod_functor source mod_exp] holds if [mod_exp] is a
60-
[Pmod_functor] expression that is expressed in long ('functor (M) ->')
61-
form in source. *)
62-
6358
val begins_line : ?ignore_spaces:bool -> t -> Location.t -> bool
6459

6560
val ends_line : t -> Location.t -> bool

lib/Sugar.ml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ let rec functor_type cmts ~for_functor_kw ({ast= mty; _} as xmty) =
297297
; pmty_loc
298298
; pmty_attributes }
299299
when for_functor_kw || List.is_empty pmty_attributes ->
300-
let arg =
301-
match arg with
302-
| {txt= None; _} -> arg
303-
| {txt= Some name; _} ->
304-
if String.equal "*" name then {arg with txt= None} else arg
305-
in
306300
Cmts.relocate cmts ~src:pmty_loc ~before:arg.loc ~after:body.pmty_loc ;
307301
let body = sub_mty ~ctx body in
308302
let xargs, xbody =
@@ -324,26 +318,20 @@ let rec functor_type cmts ~for_functor_kw ({ast= mty; _} as xmty) =
324318

325319
(* The sugar is different when used with the [functor] keyword. The syntax
326320
M(A : A)(B : B) cannot handle [_] as module name. *)
327-
let rec functor_ cmts ~for_functor_kw ~source_is_long ({ast= me; _} as xme) =
321+
let rec functor_ cmts ~for_functor_kw ({ast= me; _} as xme) =
328322
let ctx = Mod me in
329323
match me with
330324
| { pmod_desc= Pmod_functor (Named (arg, arg_mt), body)
331325
; pmod_loc
332326
; pmod_attributes }
333327
when for_functor_kw || List.is_empty pmod_attributes ->
334-
let arg =
335-
match arg with
336-
| {txt= None; _} -> arg
337-
| {txt= Some name; _} ->
338-
if String.equal "*" name then {arg with txt= None} else arg
339-
in
340328
Cmts.relocate cmts ~src:pmod_loc ~before:arg.loc ~after:body.pmod_loc ;
341329
let xarg_mt = sub_mty ~ctx arg_mt in
342330
let ctx = Mod body in
343331
let body = sub_mod ~ctx body in
344332
let xargs, xbody_me =
345333
match pmod_attributes with
346-
| [] -> functor_ cmts ~for_functor_kw ~source_is_long body
334+
| [] -> functor_ cmts ~for_functor_kw body
347335
| _ -> ([], body)
348336
in
349337
((arg, Some xarg_mt) :: xargs, xbody_me)
@@ -353,7 +341,7 @@ let rec functor_ cmts ~for_functor_kw ~source_is_long ({ast= me; _} as xme) =
353341
let body = sub_mod ~ctx body in
354342
let xargs, xbody_me =
355343
match pmod_attributes with
356-
| [] -> functor_ cmts ~for_functor_kw ~source_is_long body
344+
| [] -> functor_ cmts ~for_functor_kw body
357345
| _ -> ([], body)
358346
in
359347
(({txt= Some ""; loc= Location.none}, None) :: xargs, xbody_me)

lib/Sugar.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ val functor_type :
118118
val functor_ :
119119
Cmts.t
120120
-> for_functor_kw:bool
121-
-> source_is_long:(module_expr -> bool)
122121
-> module_expr Ast.xt
123122
-> (label option loc * module_type Ast.xt option) list * module_expr Ast.xt
124123
(** [functor_ cmts for_functor_kw m] returns the list of module types applied

0 commit comments

Comments
 (0)