]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/camlp4/examples/type_quotation.ml
update
[l4.git] / l4 / pkg / ocaml / contrib / camlp4 / examples / type_quotation.ml
1 open Camlp4.PreCast;
2
3 value rec mk_tuple _loc t n =
4   if n <= 1 then t else <:ctyp< $t$ * $mk_tuple _loc t (n - 1)$ >>;
5
6 value ctyp_eoi = Gram.Entry.mk "ctyp eoi";
7
8 EXTEND Gram
9   ctyp_eoi: [[ t = Syntax.ctyp; `EOI -> t ]];
10 END;
11
12 value exp _loc _ s =
13   Scanf.sscanf s " %d | %[^!]" begin fun n s ->
14     let t = Syntax.Gram.parse_string ctyp_eoi _loc(* not accurate *) s in
15     <:ctyp< $tup:mk_tuple _loc t n$ >>
16   end;
17
18 Quotation.add "power" Quotation.DynAst.ctyp_tag exp;