Skip to content
Snippets Groups Projects
Commit aa4ce4b3 authored by Alan Schmitt's avatar Alan Schmitt Committed by Thomas Wood
Browse files

let%some

parent cd277b69
No related branches found
No related tags found
No related merge requests found
...@@ -6,12 +6,12 @@ open Longident ...@@ -6,12 +6,12 @@ open Longident
let monad_mapping = let monad_mapping =
[("run", "if_run"); [("run", "if_run");
(*("spec", "if_spec"); *)
("string", "if_string"); ("string", "if_string");
("object", "if_object"); ("object", "if_object");
("value", "if_value"); ("value", "if_value");
("prim", "if_prim"); ("prim", "if_prim");
("number", "if_number"); ("number", "if_number");
("some", "if_some");
(*("success", "ifsuccess")*) (*("success", "ifsuccess")*)
] ]
...@@ -28,7 +28,6 @@ becomes ...@@ -28,7 +28,6 @@ becomes
*) *)
let generate_mapper namesid = function argv -> let generate_mapper namesid = function argv ->
{ default_mapper with { default_mapper with
expr = fun mapper expr -> expr = fun mapper expr ->
...@@ -36,37 +35,49 @@ let generate_mapper namesid = function argv -> ...@@ -36,37 +35,49 @@ let generate_mapper namesid = function argv ->
match expr with match expr with
(* Is this an extension node? *) (* Is this an extension node? *)
| { pexp_desc = | { pexp_desc =
(* Should have name "getenv". *)
Pexp_extension ({ txt = name; loc }, pstr)} -> Pexp_extension ({ txt = name; loc }, pstr)} ->
begin begin
try try
let ident = List.assoc name namesid in let ident = List.assoc name namesid in
match pstr with match pstr with
| PStr [{ pstr_desc = | PStr [{ pstr_desc =
Pstr_eval ({ pexp_loc = loc; Pstr_eval ({ pexp_loc = loc;
pexp_desc = Pexp_let pexp_desc = Pexp_let
(rf, (rf,
[{pvb_pat = [{pvb_pat = {ppat_desc = Ppat_var _} as p;
{ppat_desc = pvb_expr = e}],
Ppat_tuple [p1;p2]}; cont)
pvb_expr = e}], }, _)}] ->
cont) Exp.apply ~loc (Exp.ident
}, _)}] -> (Location.mkloc
Exp.apply ~loc (Exp.ident (Longident.Lident ident) Location.none))
(Location.mkloc [("", aux e);
(Longident.Lident ident) Location.none)) ("", Exp.fun_ "" None p (aux cont))]
[("", aux e); | PStr [{ pstr_desc =
("", Exp.fun_ "" None p1 (Exp.fun_ "" None p2 (aux cont)))] Pstr_eval ({ pexp_loc = loc;
| _ -> pexp_desc = Pexp_let
(rf,
[{pvb_pat =
{ppat_desc =
Ppat_tuple [p1;p2]};
pvb_expr = e}],
cont)
}, _)}] ->
Exp.apply ~loc (Exp.ident
(Location.mkloc
(Longident.Lident ident) Location.none))
[("", aux e);
("", Exp.fun_ "" None p1 (Exp.fun_ "" None p2 (aux cont)))]
| _ ->
raise (Location.Error (
Location.error ~loc ("error with let%"^name)))
with
| Not_found ->
raise (Location.Error ( raise (Location.Error (
Location.error ~loc ("error with let%"^name))) Location.error ~loc ("no let%"^name)))
with
| Not_found ->
raise (Location.Error (
Location.error ~loc ("no let%"^name)))
end end
(* Delegate to the default mapper. *) (* Delegate to the default mapper. *)
| x -> default_mapper.expr mapper x; | x -> default_mapper.expr mapper x;
} }
let () = register "my_monads" (generate_mapper monad_mapping) let () = register "my_monads" (generate_mapper monad_mapping)
This diff is collapsed.
...@@ -362,3 +362,4 @@ let ifx_prim w k = if_prim w k ...@@ -362,3 +362,4 @@ let ifx_prim w k = if_prim w k
let ifx_number w k = if_number w k let ifx_number w k = if_number w k
let ifx_string w k = if_string w k let ifx_string w k = if_string w k
let ifx_success_state a b c = if_success_state a b c let ifx_success_state a b c = if_success_state a b c
let ifx_some_or_default v d f = if_some_or_default v d f
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment