~ubuntu-branches/ubuntu/hardy/ocaml-doc/hardy

« back to all changes in this revision

Viewing changes to examples/camlp4/type_quotation.ml

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2007-09-08 01:49:22 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070908014922-lvihyehz0ndq7suu
Tags: 3.10-1
* New upstream release.
* Removed camlp4 documentation since it is not up-to-date.
* Updated to standards version 3.7.2, no changes needed.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;