]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/camlp4/examples/ex_str.ml
update
[l4.git] / l4 / pkg / ocaml / contrib / camlp4 / examples / ex_str.ml
1 open Camlp4.PreCast;;
2 module Caml =
3   Camlp4OCamlParser.Make
4     (Camlp4OCamlRevisedParser.Make
5       (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));;
6
7 let quotexpander str =
8   "[1; 2; 3]" (* ... do some real code on str *)
9
10 let patt_quotexpander loc _loc_name_opt str =
11   Gram.parse_string Caml.patt loc (quotexpander str)
12
13 let expr_quotexpander loc _loc_name_opt str =
14   Gram.parse_string Caml.expr loc (quotexpander str)
15
16 let str_item_quotexpander loc loc_name_opt str =
17   <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >>
18
19 let () =
20   Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag expr_quotexpander;
21   Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag str_item_quotexpander;
22   Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag patt_quotexpander