Skip to content

Commit

Permalink
Add antiquotation for structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
paurkedal committed May 9, 2016
1 parent a413df1 commit ef5e021
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ppx_metaquot.ml
Expand Up @@ -19,6 +19,7 @@
[%e ...] where ... is an expression of type Parsetree.expression
[%t ...] where ... is an expression of type Parsetree.core_type
[%p ...] where ... is an expression of type Parsetree.pattern
[%%s ...] where ... is an expression of type Parsetree.structure
All locations generated by the meta quotation are by default set
Expand Down Expand Up @@ -67,6 +68,10 @@ module Main : sig end = struct
| Ldot(m, _) -> String.concat "." (Longident.flatten m) ^ "." ^ s
| _ -> s

let append ?loc ?attrs e e' =
let fn = Location.mknoloc (Longident.(Ldot (Lident "List", "append"))) in
Exp.apply ?loc ?attrs (Exp.ident fn) [Nolabel, e; Nolabel, e']

class exp_builder =
object
method record ty x = record (List.map (fun (l, e) -> prefix ty l, e) x)
Expand Down Expand Up @@ -135,6 +140,15 @@ module Main : sig end = struct
| {ppat_desc=Ppat_extension({txt="p";loc}, e); _} -> map (get_exp loc e)
| x -> super # lift_Parsetree_pattern x

method! lift_Parsetree_structure str =
List.fold_right
(function
| {pstr_desc=Pstr_extension(({txt="s";loc}, e), _); _} ->
append (get_exp loc e)
| x ->
cons (super # lift_Parsetree_structure_item x))
str (nil ())

method! lift_Parsetree_core_type = function
| {ptyp_desc=Ptyp_extension({txt="t";loc}, e); _} -> map (get_exp loc e)
| x -> super # lift_Parsetree_core_type x
Expand Down

0 comments on commit ef5e021

Please sign in to comment.