113.33.00
This commit is contained in:
parent
f255c375a0
commit
4f498086fa
2
_oasis
2
_oasis
@ -2,7 +2,7 @@ OASISFormat: 0.4
|
||||
OCamlVersion: >= 4.02.3
|
||||
FindlibVersion: >= 1.3.2
|
||||
Name: ppx_let
|
||||
Version: 113.24.00
|
||||
Version: 113.33.00
|
||||
Synopsis: Monadic let-bindings
|
||||
Authors: Jane Street Group, LLC <opensource@janestreet.com>
|
||||
Copyrights: (C) 2015-2016 Jane Street Group LLC <opensource@janestreet.com>
|
||||
|
@ -6,8 +6,8 @@ let sections =
|
||||
],
|
||||
[ ("META", None)
|
||||
])
|
||||
; ("libexec",
|
||||
[ ("built_exec_ppx", Some "ppx")
|
||||
; ("bin",
|
||||
[ ("built_exec_ppx", Some "../lib/ppx_let/ppx")
|
||||
],
|
||||
[])
|
||||
]
|
||||
|
@ -67,7 +67,8 @@ let bind_apply ~loc extension_name ~arg ~fn =
|
||||
[("", arg); (fn_label, fn)]
|
||||
;;
|
||||
|
||||
let maybe_open extension_name ~loc ~to_open:module_to_open expr =
|
||||
let maybe_open extension_name ~to_open:module_to_open expr =
|
||||
let loc = expr.pexp_loc in
|
||||
match (extension_name : Extension_name.t) with
|
||||
| Bind | Map -> expr
|
||||
| Bind_open | Map_open -> pexp_open ~loc Override (module_to_open ~loc) expr
|
||||
@ -90,18 +91,18 @@ let expand_let extension_name ~loc bindings body =
|
||||
in
|
||||
bind_apply ~loc extension_name ~arg:nested_boths
|
||||
~fn:(pexp_fun ~loc "" None nested_patterns
|
||||
(maybe_open extension_name ~loc ~to_open:open_in_body body))
|
||||
(maybe_open extension_name ~to_open:open_in_body body))
|
||||
;;
|
||||
|
||||
let expand_match extension_name ~loc expr cases =
|
||||
let cases =
|
||||
List.map cases ~f:(fun case ->
|
||||
{ case with
|
||||
pc_rhs = maybe_open extension_name ~loc ~to_open:open_in_body case.pc_rhs;
|
||||
pc_rhs = maybe_open extension_name ~to_open:open_in_body case.pc_rhs;
|
||||
})
|
||||
in
|
||||
bind_apply ~loc extension_name
|
||||
~arg:(maybe_open extension_name ~loc ~to_open:open_on_rhs expr)
|
||||
~arg:(maybe_open extension_name ~to_open:open_on_rhs expr)
|
||||
~fn:(pexp_function ~loc cases)
|
||||
;;
|
||||
|
||||
@ -113,7 +114,7 @@ let expand ~loc:_ ~path:_ extension_name expr =
|
||||
let bindings =
|
||||
List.map bindings ~f:(fun vb ->
|
||||
{ vb with
|
||||
pvb_expr = maybe_open extension_name ~loc ~to_open:open_on_rhs vb.pvb_expr;
|
||||
pvb_expr = maybe_open extension_name ~to_open:open_on_rhs vb.pvb_expr;
|
||||
})
|
||||
in
|
||||
expand_with_tmp_vars ~loc bindings expr ~f:(expand_let extension_name)
|
||||
|
19
test/test-locations.mlt
Normal file
19
test/test-locations.mlt
Normal file
@ -0,0 +1,19 @@
|
||||
(* -*- tuareg -*- *)
|
||||
|
||||
module Let_syntax = struct
|
||||
type 'a t = T of 'a
|
||||
let map (T x) ~f = T (f x)
|
||||
let both (T x) (T y) = T (x, y)
|
||||
module Open_on_rhs = struct
|
||||
let return x = T x
|
||||
let f x ~(doc:string) = T (x, doc)
|
||||
end
|
||||
module Open_in_body = struct end
|
||||
end
|
||||
|
||||
let _ = [%map_open let x = return 42 and y = f 42 in ()]
|
||||
[%%expect{|
|
||||
Line _, characters 45-49:
|
||||
Error: This expression has type doc:bytes -> (int * bytes) Let_syntax.t
|
||||
but an expression was expected of type 'a Let_syntax.t
|
||||
|}]
|
25
test/test.ml
25
test/test.ml
@ -126,6 +126,7 @@ module Async_command_override_example = struct
|
||||
module Deferred : sig
|
||||
type 'a t
|
||||
val return : 'a -> 'a t
|
||||
module Let_syntax : sig
|
||||
module Let_syntax : sig
|
||||
type 'a t
|
||||
val return : 'a -> 'a t
|
||||
@ -134,9 +135,11 @@ module Async_command_override_example = struct
|
||||
module Open_on_rhs : sig val return : 'a -> 'a t end
|
||||
module Open_in_body : sig val return : 'a -> 'a t end
|
||||
end with type 'a t := 'a t
|
||||
end
|
||||
end = struct
|
||||
type 'a t = 'a
|
||||
let return x = x
|
||||
module Let_syntax = struct
|
||||
module Let_syntax = struct
|
||||
let return = return
|
||||
let map x ~f = f x
|
||||
@ -145,6 +148,7 @@ module Async_command_override_example = struct
|
||||
module Open_in_body = struct let return = return end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Command : sig
|
||||
module Param : sig
|
||||
@ -153,6 +157,7 @@ module Async_command_override_example = struct
|
||||
val flag : 'a -> int t
|
||||
val anon : 'a -> int t
|
||||
end
|
||||
module Let_syntax : sig
|
||||
module Let_syntax : sig
|
||||
type 'a t
|
||||
val return : 'a -> 'a t
|
||||
@ -161,6 +166,7 @@ module Async_command_override_example = struct
|
||||
module Open_on_rhs = Param
|
||||
module Open_in_body : sig end
|
||||
end with type 'a t := 'a Param.t
|
||||
end
|
||||
end = struct
|
||||
module Param = struct
|
||||
type 'a t = 'a
|
||||
@ -170,12 +176,14 @@ module Async_command_override_example = struct
|
||||
let flag _ = 66
|
||||
let anon _ = 77
|
||||
end
|
||||
module Let_syntax = struct
|
||||
module Let_syntax = struct
|
||||
include Param
|
||||
module Open_on_rhs = Param
|
||||
module Open_in_body = struct end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Command_override = struct
|
||||
module Param = struct
|
||||
@ -183,19 +191,20 @@ module Async_command_override_example = struct
|
||||
let special_flag = flag 88
|
||||
end
|
||||
module Let_syntax = struct
|
||||
include (Command.Let_syntax : module type of Command.Let_syntax
|
||||
with module Open_on_rhs := Command.Let_syntax.Open_on_rhs
|
||||
and module Open_in_body := Command.Let_syntax.Open_in_body)
|
||||
open Command.Let_syntax
|
||||
module Let_syntax = struct
|
||||
include (Let_syntax : module type of Let_syntax
|
||||
with module Open_on_rhs := Let_syntax.Open_on_rhs
|
||||
and module Open_in_body := Let_syntax.Open_in_body)
|
||||
|
||||
module Open_on_rhs = Param
|
||||
module Open_in_body = struct
|
||||
module Let_syntax = Deferred.Let_syntax
|
||||
module Open_in_body = Deferred.Let_syntax
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
let _1 : int Command.Param.t =
|
||||
let module Let_syntax = Command.Let_syntax in
|
||||
let open Command.Let_syntax in
|
||||
[%map_open
|
||||
let x = flag "foo"
|
||||
and y = anon "bar"
|
||||
@ -205,7 +214,7 @@ module Async_command_override_example = struct
|
||||
;;
|
||||
|
||||
let _1 : (unit -> int Deferred.t) Command_override.Param.t =
|
||||
let module Let_syntax = Command_override.Let_syntax in
|
||||
let open Command_override.Let_syntax in
|
||||
[%map_open
|
||||
let x = flag "foo"
|
||||
and y = anon "bar"
|
||||
@ -218,7 +227,7 @@ module Async_command_override_example = struct
|
||||
;;
|
||||
|
||||
let _1 : (unit -> unit Deferred.t) Command.Param.t =
|
||||
let module Let_syntax = Command_override.Let_syntax in
|
||||
let open Command_override.Let_syntax in
|
||||
[%map_open
|
||||
let () = return () in
|
||||
fun () ->
|
||||
|
Loading…
Reference in New Issue
Block a user