Skip to content

Commit

Permalink
[ocaml] allow multi-line functor types
Browse files Browse the repository at this point in the history
  • Loading branch information
nbacquey committed Oct 23, 2023
1 parent 9a66a65 commit d1dc299
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion topiary-queries/queries/ocaml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@
(#scope_id! "tuple")
)

; Allow softlines in function types, such as
; Allow softlines in function and functor types, such as
; type t =
; a ->
; (b -> c) ->
Expand Down Expand Up @@ -1398,6 +1398,17 @@
(#scope_id! "function_type")
)

(
"->"? @do_nothing
.
(functor_type) @prepend_begin_scope @append_end_scope
(#scope_id! "functor_type")
)
(functor_type
"->" @append_spaced_scoped_softline
(#scope_id! "functor_type")
)

; Allow softlines in boolean infix expressions, such as
; let b =
; foo
Expand Down
9 changes: 8 additions & 1 deletion topiary/tests/samples/expected/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,8 @@ module Lift
end

module MOption:
functor (A: SERIALISABLE) -> SERIALISABLE with
functor (A: SERIALISABLE) ->
SERIALISABLE with
type t = A.t option

module MUnit: SERIALISABLE with
Expand Down Expand Up @@ -1127,3 +1128,9 @@ let _ =
(* #645: idempotency error on first-class module types *)
let peer_functor : (module Peer.F) =
if !listening then (module Server) else (module Client)

(* #646: multi-line functor type formatted as single-line*)
module Make:
functor (I: Interface.S) ->
functor (_: Transport.S with type payload = I.data Payload.t) ->
S
6 changes: 6 additions & 0 deletions topiary/tests/samples/input/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1059,3 +1059,9 @@ let _ =
(* #645: idempotency error on first-class module types *)
let peer_functor : (module Peer.F) =
if !listening then (module Server) else (module Client)

(* #646: multi-line functor type formatted as single-line*)
module Make:
functor (I: Interface.S) ->
functor (_: Transport.S with type payload = I.data Payload.t) ->
S

0 comments on commit d1dc299

Please sign in to comment.