Skip to content

Commit 9d72bbc

Browse files
committed
Merge pull request #151 from ocsigen/ppx_api
Make the Ppx_tyxml api a bit friendlier.
2 parents 15c7278 + 4c524a0 commit 9d72bbc

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

ppx/ppx_tyxml.ml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,7 @@ let replace_attribute ~loc (attr,value) =
237237
238238
Each token is equipped with a starting (but no ending) position.
239239
*)
240-
let ast_to_stream expr =
241-
let expressions =
242-
match expr.pexp_desc with
243-
| Pexp_apply (f, arguments) -> f::(List.map snd arguments)
244-
| _ -> [expr]
245-
in
240+
let ast_to_stream expressions =
246241

247242
let strings =
248243
expressions |> List.map @@ fun expr ->
@@ -380,6 +375,12 @@ let dispatch_ext {txt ; loc} =
380375
Some (Ppx_common.Svg, get_modname ~loc len l)
381376
| _ -> None
382377

378+
let application_to_list expr =
379+
match expr.pexp_desc with
380+
| Pexp_apply (f, arguments) -> f::(List.map snd arguments)
381+
| _ -> [expr]
382+
383+
383384
open Ast_mapper
384385
open Ast_helper
385386

@@ -390,7 +391,8 @@ let markup_cases ~lang ~modname cases =
390391
let f ({pc_rhs} as case) =
391392
let loc = pc_rhs.pexp_loc in
392393
let pc_rhs =
393-
markup_to_expr_with_implementation lang modname loc pc_rhs
394+
markup_to_expr_with_implementation lang modname loc @@
395+
application_to_list pc_rhs
394396
in {case with pc_rhs}
395397
in
396398
List.map f cases
@@ -405,7 +407,8 @@ let rec markup_function ~lang ~modname e =
405407
let cases = markup_cases ~lang ~modname cases in
406408
{e with pexp_desc = Pexp_function cases}
407409
| _ ->
408-
markup_to_expr_with_implementation lang modname loc e
410+
markup_to_expr_with_implementation lang modname loc @@
411+
application_to_list e
409412

410413
let markup_bindings ~lang ~modname l =
411414
let f ({pvb_expr} as b) =
@@ -424,7 +427,8 @@ let rec expr mapper e =
424427
let bindings = markup_bindings ~lang ~modname bindings in
425428
{e with pexp_desc = Pexp_let (recflag, bindings, expr mapper next)}
426429
| _ ->
427-
markup_to_expr_with_implementation lang modname e.pexp_loc e
430+
markup_to_expr_with_implementation lang modname e.pexp_loc @@
431+
application_to_list e
428432
end
429433
| Some _, _ -> error ext
430434
| None, _ -> default_mapper.expr mapper e

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)