use Location.error_extensionf nodes
This commit is contained in:
parent
4b281e349b
commit
34156743b1
|
@ -2,23 +2,26 @@ open Ppxlib
|
||||||
|
|
||||||
let log_expander ~ctxt (e : expression) (l : (arg_label * expression) list) : expression =
|
let log_expander ~ctxt (e : expression) (l : (arg_label * expression) list) : expression =
|
||||||
let loc = Expansion_context.Extension.extension_point_loc ctxt in
|
let loc = Expansion_context.Extension.extension_point_loc ctxt in
|
||||||
let is_exn = begin match e.pexp_desc with
|
let open (val Ast_builder.make loc) in
|
||||||
|
let (is_exn, err) = begin match e.pexp_desc with
|
||||||
| Pexp_ident { txt = Lident "trace"; _ }
|
| Pexp_ident { txt = Lident "trace"; _ }
|
||||||
| Pexp_ident { txt = Lident "debug"; _ }
|
| Pexp_ident { txt = Lident "debug"; _ }
|
||||||
| Pexp_ident { txt = Lident "info"; _ }
|
| Pexp_ident { txt = Lident "info"; _ }
|
||||||
| Pexp_ident { txt = Lident "warn"; _ }
|
| Pexp_ident { txt = Lident "warn"; _ }
|
||||||
| Pexp_ident { txt = Lident "error"; _ } -> false
|
| Pexp_ident { txt = Lident "error"; _ } -> (false, None)
|
||||||
| Pexp_ident { txt = Lident "exn"; _ } -> true
|
| Pexp_ident { txt = Lident "exn"; _ } -> (true, None)
|
||||||
| _ ->
|
| _ ->
|
||||||
raise (Location.Error (Location.Error.make ~loc ~sub:[]
|
(false,
|
||||||
|
Some (pexp_extension @@ Location.error_extensionf ~loc
|
||||||
"log type must be one of: trace, debug, info, warn, error, exn"))
|
"log type must be one of: trace, debug, info, warn, error, exn"))
|
||||||
end in
|
end in match err with
|
||||||
let open (val Ast_builder.make loc) in
|
| Some err -> err
|
||||||
|
| None ->
|
||||||
if is_exn then
|
if is_exn then
|
||||||
match l with
|
match l with
|
||||||
| [] ->
|
| [] ->
|
||||||
raise (Location.Error (Location.Error.make ~loc ~sub:[]
|
pexp_extension @@ Location.error_extensionf ~loc
|
||||||
"must provide exn value"))
|
"must provide exn value"
|
||||||
| (_, v)::l ->
|
| (_, v)::l ->
|
||||||
let application =
|
let application =
|
||||||
eapply (pexp_ident { txt = Lident "m"; loc}) (List.map snd l) in
|
eapply (pexp_ident { txt = Lident "m"; loc}) (List.map snd l) in
|
||||||
|
|
Loading…
Reference in New Issue