summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Pouillard <np@nicolaspouillard.fr>2007-11-22 18:56:01 +0000
committerNicolas Pouillard <np@nicolaspouillard.fr>2007-11-22 18:56:01 +0000
commite49b8c08d84035be94fcc962769db3e00bb0da4a (patch)
tree7fda3c8d2ecf53078d251b5744928d38a84c1f79
parenta4154feec72e29419656ec79051996165b185329 (diff)
[camlp4] Add an example about the "debug" syntax extension.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@8611 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--camlp4/examples/debug_extension.ml37
1 files changed, 37 insertions, 0 deletions
diff --git a/camlp4/examples/debug_extension.ml b/camlp4/examples/debug_extension.ml
new file mode 100644
index 000000000..21696e4a9
--- /dev/null
+++ b/camlp4/examples/debug_extension.ml
@@ -0,0 +1,37 @@
+(*
+ * No debugging code at all:
+ * $ camlp4o -parser Camlp4DebugParser debug_extension.ml
+ * true
+ * Debugging code for lexing:
+ * $ STATIC_CAMLP4_DEBUG='lexing' camlp4o -parser Camlp4DebugParser debug_extension.ml
+ * let () =
+ * if Camlp4.Debug.mode "lexing"
+ * then Debug.printf "lexing" "TOKEN: Int %d" (2 * 21)
+ * else ()
+ * in true
+ *
+ * Debugging code for lexing and parsing:
+ * $ STATIC_CAMLP4_DEBUG='lexing:parsing' camlp4o -parser Camlp4DebugParser debug_extension.ml
+ * let () =
+ * if Camlp4.Debug.mode "lexing"
+ * then Debug.printf "lexing" "TOKEN: Int %d" (2 * 21)
+ * else () in
+ * let () =
+ * if Camlp4.Debug.mode "parsing"
+ * then Debug.printf "parsing" "RULE: ..."
+ * else ()
+ * in true
+ *
+ * Debugging code for any section:
+ * $ STATIC_CAMLP4_DEBUG='*' camlp4o -parser Camlp4DebugParser debug_extension.ml
+ * ... same output as above ...
+ *
+ * When you program is compiled you can use the CAMLP4_DEBUG variable to
+ * activate some debugging sections.
+ *
+ * CAMLP4_DEBUG_FILE manage where messages goes (default is stderr).
+ *)
+
+camlp4_debug lexing "TOKEN: Int %d" (2 * 21) in
+camlp4_debug parsing "RULE: ..." in
+true