Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several OCaml fixes #648

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions topiary-queries/queries/ocaml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
(field_get_expression)
(local_open_pattern)
(labeled_argument)
(list_pattern)
; start equivalence class
(extended_module_path)
(module_path)
Expand Down Expand Up @@ -857,6 +858,7 @@
(signature
"sig" @append_spaced_softline
[
(module_definition)
(value_specification)
(type_definition)
; start equivalence class
Expand Down Expand Up @@ -1140,12 +1142,14 @@
(type_constraint) @append_indent_end
)

(package_type
.
"(" @append_empty_softline @append_indent_start
")" @prepend_empty_softline @prepend_indent_end
.
) @prepend_spaced_softline
(type_binding
(package_type
.
"(" @append_empty_softline @append_indent_start
")" @prepend_empty_softline @prepend_indent_end
.
) @prepend_spaced_softline
)

; Consider type constraints to be "out of the block" when deciding
; whether to add a newline between "=" and a constructed type.
Expand Down Expand Up @@ -1364,7 +1368,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 @@ -1396,6 +1400,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 Expand Up @@ -1491,46 +1506,24 @@
; top-level one: it is the one that is not preceded by a ";" (or ";%foo" for ppx sequences).
(
";"? @do_nothing
.
(sequence_expression
.
_
.
";"
.
"%"? @do_nothing
) @prepend_begin_scope @append_end_scope
(#scope_id! "sequence_expression")
)
(sequence_expression
";" @append_spaced_scoped_softline
(#scope_id! "sequence_expression")
)

(
";"?
.
"%"? @do_nothing
.
(attribute_id)?
.
(sequence_expression
.
_
.
";"
.
"%"
) @prepend_begin_scope @append_end_scope
(#scope_id! "ppx_sequence_expression")
(#scope_id! "sequence_expression")
)
(sequence_expression
";"
.
"%"
.
(attribute_id) @append_spaced_scoped_softline
(#scope_id! "ppx_sequence_expression")
(#scope_id! "sequence_expression")
)

; Allow softlines in or patterns in matches, such as
Expand Down
3 changes: 2 additions & 1 deletion topiary/tests/samples/expected/ocaml-interface.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,8 @@ module Dal: sig
context -> (context * Attestation.t) tzresult Lwt.t
end

module Operations: sig module Publish_slot_header: sig
module Operations: sig
module Publish_slot_header: sig
type t = {
published_level: Raw_level.t;
slot_index: Slot_index.t;
Expand Down
39 changes: 38 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 @@ -1123,3 +1124,39 @@ let _ =
| E
| F ->
bar

(* #642: interleaving regular sequence with PPX sequence *)
let () =
foo;
bar;%lwt
baz

let () = foo; bar;%lwt baz

(* #644: softlines before module definition in a module type *)
module type F = sig
module G: sig val h : string end

type ('state, 'proof, 'output) implementation =
(
module S with
type state = 'state
and type proof = 'proof
and type output_proof = 'output
)
end

(* #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

(* #647: missing space for pattern matching of constructor holding list *)
let _ =
match foo with
| Bar ["baz"] -> qux
36 changes: 36 additions & 0 deletions topiary/tests/samples/input/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1055,3 +1055,39 @@ let _ =
match foo with
| A | B | C
| D | E | F -> bar

(* #642: interleaving regular sequence with PPX sequence *)
let () =
foo;
bar;%lwt
baz

let () = foo; bar;%lwt baz

(* #644: softlines before module definition in a module type *)
module type F = sig
module G : sig val h : string end

type ('state, 'proof, 'output) implementation =
(
module S with
type state = 'state
and type proof = 'proof
and type output_proof = 'output
)
end

(* #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

(* #647: missing space for pattern matching of constructor holding list *)
let _ =
match foo with
| Bar ["baz"] -> qux
Loading
Loading