diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/tokenizer.rs | 21 | ||||
-rw-r--r-- | src/util/char.rs | 2 |
3 files changed, 23 insertions, 2 deletions
@@ -22,7 +22,7 @@ default = [] json = ["dep:serde", "dep:serde_json"] [dependencies] -log = "0.4" +log = { version = "0.4", optional = true } unicode-id = { version = "0.3", features = ["no_std"] } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 346e04e..e463b4b 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -13,7 +13,11 @@ use crate::parser::ParseState; use crate::resolve::{call as call_resolve, Name as ResolveName}; use crate::state::{call, State}; use crate::subtokenize::Subresult; -use crate::util::{char::format_byte_opt, constant::TAB_SIZE, edit_map::EditMap}; + +#[cfg(feature = "log")] +use crate::util::char::format_byte_opt; + +use crate::util::{constant::TAB_SIZE, edit_map::EditMap}; use alloc::{boxed::Box, string::String, vec, vec::Vec}; /// Containers. @@ -405,7 +409,10 @@ impl<'a> Tokenizer<'a> { move_point_back(self, &mut point); let info = (point.index, point.vs); + + #[cfg(feature = "log")] log::debug!("position: define skip: {:?} -> ({:?})", point.line, info); + let at = point.line - self.first_line; if at >= self.column_start.len() { @@ -476,6 +483,8 @@ impl<'a> Tokenizer<'a> { self.line_start = self.point.clone(); self.account_for_potential_skip(); + + #[cfg(feature = "log")] log::debug!("position: after eol: `{:?}`", self.point); } else { self.point.column += 1; @@ -533,7 +542,9 @@ impl<'a> Tokenizer<'a> { move_point_back(self, &mut point); } + #[cfg(feature = "log")] log::debug!("exit: `{:?}`", name); + let event = Event { kind: Kind::Exit, name, @@ -663,7 +674,9 @@ fn enter_impl(tokenizer: &mut Tokenizer, name: Name, link: Option<Link>) { let mut point = tokenizer.point.clone(); move_point_back(tokenizer, &mut point); + #[cfg(feature = "log")] log::debug!("enter: `{:?}`", name); + tokenizer.stack.push(name.clone()); tokenizer.events.push(Event { kind: Kind::Enter, @@ -708,7 +721,9 @@ fn push_impl( attempt.nok }; + #[cfg(feature = "log")] log::debug!("attempt: `{:?}` -> `{:?}`", state, next); + state = next; } else { break; @@ -735,13 +750,17 @@ fn push_impl( None }; + #[cfg(feature = "log")] log::debug!("feed: {} to {:?}", format_byte_opt(byte), name); + tokenizer.expect(byte); state = call(tokenizer, name); }; } State::Retry(name) => { + #[cfg(feature = "log")] log::debug!("retry: `{:?}`", name); + state = call(tokenizer, name); } } diff --git a/src/util/char.rs b/src/util/char.rs index 79cd32e..3ea4500 100644 --- a/src/util/char.rs +++ b/src/util/char.rs @@ -115,6 +115,7 @@ pub fn format_opt(char: Option<char>) -> String { } /// Format an optional `byte` (`none` means eof). +#[cfg(feature = "log")] pub fn format_byte_opt(byte: Option<u8>) -> String { byte.map_or("end of file".into(), |byte| { format!("byte {}", format_byte(byte)) @@ -191,6 +192,7 @@ mod tests { } #[test] + #[cfg(feature = "log")] fn test_format_byte_opt() { assert_eq!( format_byte_opt(None), |