]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/camlp4/examples/gen_type_N.ml
update
[l4.git] / l4 / pkg / ocaml / contrib / camlp4 / examples / gen_type_N.ml
1 open Camlp4.PreCast;;
2
3 let data_constructor_arguments _loc n t =
4   let rec self n =
5     if n <= 0 then <:ctyp<>> else <:ctyp< $t$ and $self (n-1)$ >>
6   in self n
7 ;;
8
9 let data_constructor _loc n t =
10   <:ctyp< $uid:"C"^string_of_int n$ of $data_constructor_arguments _loc n t$ >>
11 ;;
12
13 let gen_type _loc n t =
14   let rec self n =
15     if n <= 0 then <:ctyp<>>
16     else <:ctyp< $self (n-1)$ | $data_constructor _loc n t$ >>
17   in <:ctyp< [ $self n$ ] >>
18 ;;
19
20 let filter =
21   function
22   | <:ctyp@_loc< gen_type $lid:x$ >> | <:ctyp@_loc< $lid:x$ gen_type >> ->
23       Scanf.sscanf x "%[^0-9]%d" begin fun _ n ->
24         gen_type _loc n <:ctyp< $lid:x$ >>
25       end
26   | t -> t
27 ;;
28
29 AstFilters.register_str_item_filter (Ast.map_ctyp filter)#str_item;;
30
31 IFDEF TEST THEN
32   type t7 = gen_type t7;;
33 ENDIF;;