summaryrefslogtreecommitdiffstats
path: root/camlp4/examples/parse_files.ml
diff options
context:
space:
mode:
Diffstat (limited to 'camlp4/examples/parse_files.ml')
-rw-r--r--camlp4/examples/parse_files.ml31
1 files changed, 31 insertions, 0 deletions
diff --git a/camlp4/examples/parse_files.ml b/camlp4/examples/parse_files.ml
new file mode 100644
index 000000000..3e7e30fbe
--- /dev/null
+++ b/camlp4/examples/parse_files.ml
@@ -0,0 +1,31 @@
+open Camlp4.PreCast;;
+
+module CamlGram = MakeGram(Lexer);;
+
+module Caml =
+ Camlp4.Printers.OCaml.Make
+ (Camlp4OCamlParser.Make
+ (Camlp4OCamlRevisedParser.Make
+ (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation))));;
+
+let parse f =
+ let ic = open_in f in
+ let strm = Stream.of_channel ic in
+ let res = Caml.parse_implem (Loc.mk f) strm in
+ close_in ic; res;;
+
+let ghost = Loc.ghost;;
+
+let main () =
+ let a = parse "apply_operator_test.ml" in
+ let b = parse "global_handler_test.ml" in
+ Caml.print_implem
+ <:str_item@ghost<
+ module Apply_operator_test = struct $a$ end;;
+ module Global_handler_test = struct $b$ end >>
+;;
+
+try main ()
+with e ->
+ Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e;
+ exit 1;;