Provide Position to debug.

This commit is contained in:
Stephen Chung
2020-12-12 11:47:18 +08:00
parent 5443368359
commit 40b6a014ae
7 changed files with 59 additions and 25 deletions

View File

@@ -1808,16 +1808,21 @@ impl Engine {
///
/// // Override action of 'print' function
/// let logger = result.clone();
/// engine.on_debug(move |s| logger.write().unwrap().push_str(s));
/// engine.on_debug(move |s, pos| logger.write().unwrap().push_str(
/// &format!("{:?} > {}", pos, s)
/// ));
///
/// engine.consume(r#"debug("hello");"#)?;
/// engine.consume(r#"let x = "hello"; debug(x);"#)?;
///
/// assert_eq!(*result.read().unwrap(), r#""hello""#);
/// assert_eq!(*result.read().unwrap(), r#"1:18 > "hello""#);
/// # Ok(())
/// # }
/// ```
#[inline(always)]
pub fn on_debug(&mut self, callback: impl Fn(&str) + SendSync + 'static) -> &mut Self {
pub fn on_debug(
&mut self,
callback: impl Fn(&str, Position) + SendSync + 'static,
) -> &mut Self {
self.debug = Box::new(callback);
self
}