Add a feature to synom for verbose parsing logging
diff --git a/synom/Cargo.toml b/synom/Cargo.toml
index 6a7dad8..f3bd05d 100644
--- a/synom/Cargo.toml
+++ b/synom/Cargo.toml
@@ -22,6 +22,10 @@
clone-impls = []
extra-traits = []
+# NOTE: This feature is very verbose - it will cause every call!() expression to
+# be logged to stderr. It exists mostly as a debugging tool.
+verbose-trace = []
+
[dev-dependencies.syn]
version = "0.11"
path = ".."
diff --git a/synom/src/cursor.rs b/synom/src/cursor.rs
index 59516b1..3732454 100644
--- a/synom/src/cursor.rs
+++ b/synom/src/cursor.rs
@@ -347,11 +347,10 @@
// pretty useless.
impl<'a> fmt::Debug for Cursor<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.debug_struct("Cursor")
- .field("ptr", &self.ptr)
- .field("scope", &self.scope)
- // Dummy `entry` field to show data behind the `ptr` ptr.
- .field("entry", self.entry())
+ // Print what the cursor is currently looking at.
+ // This will look like Cursor("some remaining tokens here")
+ f.debug_tuple("Cursor")
+ .field(&self.token_stream().to_string())
.finish()
}
}
diff --git a/synom/src/lib.rs b/synom/src/lib.rs
index 8cf09ac..009de43 100644
--- a/synom/src/lib.rs
+++ b/synom/src/lib.rs
@@ -151,12 +151,30 @@
};
}
+#[cfg(feature = "verbose-trace")]
+#[macro_export]
+macro_rules! call {
+ ($i:expr, $fun:expr $(, $args:expr)*) => {
+ {
+ let i = $i;
+ eprintln!(concat!(" -> ", stringify!($fun), " @ {:?}"), i);
+ let r = $fun(i $(, $args)*);
+ match r {
+ Ok((i, _)) => eprintln!(concat!("OK ", stringify!($fun), " @ {:?}"), i),
+ Err(_) => eprintln!(concat!("ERR ", stringify!($fun), " @ {:?}"), i),
+ }
+ r
+ }
+ };
+}
+
/// Invoke the given parser function with the passed in arguments.
///
/// - **Syntax:** `call!(FUNCTION, ARGS...)`
///
/// where the signature of the function is `fn(&[U], ARGS...) -> IPResult<&[U], T>`
/// - **Output:** `T`, the result of invoking the function `FUNCTION`
+#[cfg(not(feature = "verbose-trace"))]
#[macro_export]
macro_rules! call {
($i:expr, $fun:expr $(, $args:expr)*) => {