diff options
Diffstat (limited to 'ocaml-binary-annot/camlp4/examples/ex_str.ml')
| -rw-r--r-- | ocaml-binary-annot/camlp4/examples/ex_str.ml | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ocaml-binary-annot/camlp4/examples/ex_str.ml b/ocaml-binary-annot/camlp4/examples/ex_str.ml new file mode 100644 index 0000000000..ac9513b9a0 --- /dev/null +++ b/ocaml-binary-annot/camlp4/examples/ex_str.ml @@ -0,0 +1,22 @@ +open Camlp4.PreCast;; +module Caml = + Camlp4OCamlParser.Make + (Camlp4OCamlRevisedParser.Make + (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));; + +let quotexpander str = + "[1; 2; 3]" (* ... do some real code on str *) + +let patt_quotexpander loc _loc_name_opt str = + Gram.parse_string Caml.patt loc (quotexpander str) + +let expr_quotexpander loc _loc_name_opt str = + Gram.parse_string Caml.expr loc (quotexpander str) + +let str_item_quotexpander loc loc_name_opt str = + <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >> + +let () = + Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag expr_quotexpander; + Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag str_item_quotexpander; + Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag patt_quotexpander |
