Skip to content

Commit f49d79a

Browse files
committed
Make the Ppx_tyxml api a bit friendlier.
1 parent 63a3c6d commit f49d79a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

ppx/ppx_tyxml.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,9 @@ let replace_attribute ~loc (attr,value) =
173173
174174
Each token is equipped with a starting (but no ending) position.
175175
*)
176-
let ast_to_stream expr =
176+
let ast_to_stream expressions =
177177
let current_adjust_location = ref (Loc.adjust Lexing.dummy_pos 0) in
178178

179-
let expressions =
180-
match expr.pexp_desc with
181-
| Pexp_apply (f, arguments) -> f::(List.map snd arguments)
182-
| _ -> [expr]
183-
in
184-
185179
let strings =
186180
expressions |> List.map @@ fun expr ->
187181
match expr.pexp_desc with
@@ -321,14 +315,21 @@ let dispatch_ext {txt ; loc} =
321315
Some (Ppx_common.Svg, get_modname ~loc len l)
322316
| _ -> None
323317

318+
let application_to_list expr =
319+
match expr.pexp_desc with
320+
| Pexp_apply (f, arguments) -> f::(List.map snd arguments)
321+
| _ -> [expr]
322+
323+
324324
open Ast_mapper
325325

326326
let map_expr mapper e =
327327
match e.pexp_desc with
328328
| Pexp_extension (ext, payload) ->
329329
begin match dispatch_ext ext, payload with
330330
| Some (lang, modname), PStr [{pstr_desc = Pstr_eval (e, _)}] ->
331-
markup_to_expr_with_implementation lang modname e.pexp_loc e
331+
markup_to_expr_with_implementation lang modname e.pexp_loc @@
332+
application_to_list e
332333
| Some _, _ ->
333334
Ppx_common.error e.pexp_loc
334335
"Error: Payload of [%%tyxml] must be a single string"

ppx/ppx_tyxml.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
val markup_to_expr :
2828
Ppx_common.lang ->
29-
Location.t -> Parsetree.expression -> Parsetree.expression
29+
Location.t -> Parsetree.expression list -> Parsetree.expression
3030
(** Given the payload of a [%html ...] or [%svg ...] expression,
3131
converts it to a TyXML expression representing the markup
3232
contained therein. *)

0 commit comments

Comments
 (0)