From 273c8a008fce553697d0f772fb6057a95b962f4c Mon Sep 17 00:00:00 2001 From: Mingun Date: Thu, 28 Sep 2023 00:49:39 +0500 Subject: [PATCH] dbg! in xml --- src/parser/mod.rs | 23 +++++++++++++++++------ src/reader/mod.rs | 8 +++++--- src/reader/slice_reader.rs | 3 ++- src/reader/state.rs | 3 ++- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index e6a6daee..46a14007 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -345,10 +345,12 @@ impl Parser { /// - `bytes`: a slice to search a new XML event. Should contain text in /// ASCII-compatible encoding pub fn feed(&mut self, bytes: &[u8]) -> Result { + dbg!((self.0, crate::utils::Bytes(bytes))); for (offset, &byte) in bytes.iter().enumerate() { let trail = &bytes[offset..]; let start = offset + 1; let rest = &bytes[start..]; + dbg!((self.0, offset, byte as char, crate::utils::Bytes(trail), crate::utils::Bytes(rest))); self.0 = match self.0 { State::Start => match byte { 0x00 => State::Bom(BomParser::X00), @@ -549,6 +551,7 @@ impl Parser { /// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()` #[inline] fn parse_text(&mut self, bytes: &[u8], offset: usize) -> FeedResult { + dbg!((self.0, offset, crate::utils::Bytes(bytes))); self.0 = State::Text; match bytes.iter().position(|&b| b == b'<') { Some(i) => FeedResult::EmitText(offset + i), @@ -570,6 +573,7 @@ impl Parser { offset: usize, mut parser: CommentParser, ) -> FeedResult { + dbg!((self.0, offset, crate::utils::Bytes(bytes), parser)); match parser.feed(bytes) { Some(i) => { self.0 = State::Text; @@ -593,6 +597,7 @@ impl Parser { /// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()` /// - `braces_left`: count of braces that wasn't seen yet in the end of previous data chunk fn parse_cdata(&mut self, bytes: &[u8], offset: usize, mut parser: CDataParser) -> FeedResult { + dbg!((self.0, offset, crate::utils::Bytes(bytes), parser)); match parser.feed(bytes) { Some(i) => { self.0 = State::Text; @@ -611,8 +616,9 @@ impl Parser { offset: usize, mut parser: QuotedParser, ) -> Result { + dbg!((self.0, offset, crate::utils::Bytes(bytes), parser)); // Search `[` (start of DTD definitions) or `>` (end of tag) - match parser.one_of(bytes) { + match dbg!(parser.one_of(bytes)) { OneOf::Open(i) => self.parse_dtd(&bytes[i..], offset + i, DtdParser::default()), OneOf::Close(i) => { self.0 = State::Text; @@ -639,8 +645,9 @@ impl Parser { mut offset: usize, mut parser: DtdParser, ) -> Result { + dbg!((self.0, offset, crate::utils::Bytes(bytes), parser)); loop { - let result = match parser.feed(bytes) { + let result = match dbg!(parser.feed(bytes)) { // Skip recognized DTD structure // TODO: Emit DTD events while parsing quick_dtd::FeedResult::EmitPI(off) @@ -669,7 +676,8 @@ impl Parser { } fn parse_doctype_finish(&mut self, bytes: &[u8], offset: usize) -> FeedResult { - match bytes.iter().position(|&b| b == b'>') { + dbg!((self.0, offset, crate::utils::Bytes(bytes))); + match dbg!(bytes.iter().position(|&b| b == b'>')) { Some(i) => { self.0 = State::Text; // +1 for `>` which should be included in event @@ -692,7 +700,8 @@ impl Parser { /// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()` /// - `has_mark`: a flag that indicates was the previous fed data ended with `?` fn parse_pi(&mut self, bytes: &[u8], offset: usize, mut parser: PiParser) -> FeedResult { - match parser.feed(bytes) { + dbg!((self.0, offset, crate::utils::Bytes(bytes), parser)); + match dbg!(parser.feed(bytes)) { Some(i) => { self.0 = State::Text; FeedResult::EmitPI(offset + i) @@ -711,7 +720,8 @@ impl Parser { /// That sub-slice begins on the byte that represents a tag name /// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()` fn parse_end(&mut self, bytes: &[u8], offset: usize) -> FeedResult { - match bytes.iter().position(|&b| b == b'>') { + dbg!((self.0, offset, crate::utils::Bytes(bytes))); + match dbg!(bytes.iter().position(|&b| b == b'>')) { Some(i) => { self.0 = State::Text; // +1 for `>` which should be included in event @@ -740,7 +750,8 @@ impl Parser { mut parser: QuotedParser, has_slash: bool, ) -> FeedResult { - match parser.feed(bytes) { + dbg!((self.0, offset, crate::utils::Bytes(bytes), parser, has_slash)); + match dbg!(parser.feed(bytes)) { Some(0) if has_slash => { self.0 = State::Text; // +1 for `>` which should be included in event diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 9062a148..9c5b3dfc 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -204,6 +204,7 @@ macro_rules! read_event_impl { $self:ident, $buf:ident $(, $await:ident)? ) => {{ + dbg!("==============================================================="); if let Some(end) = $self.state.pending_end() { return Ok(end); } @@ -211,13 +212,14 @@ macro_rules! read_event_impl { let start = $buf.len(); let offset = $self.state.offset; loop { - break match $self.reader.fill_buf() $(.$await)? { + dbg!("--------------------------------"); + break match dbg!($self.reader.fill_buf() $(.$await)?) { Ok(bytes) if bytes.is_empty() => { let content = &$buf[start..]; if content.is_empty() { Ok(Event::Eof) } else - if let Err(error) = $self.state.parser.finish() { + if let Err(error) = dbg!($self.state.parser.finish()) { $self.state.last_error_offset = offset; Err(Error::Syntax(error)) } else { @@ -226,7 +228,7 @@ macro_rules! read_event_impl { Ok(Event::Text(BytesText::wrap(content, $self.decoder()))) } } - Ok(bytes) => match $self.state.parse_into(bytes, $buf)? { + Ok(bytes) => match dbg!($self.state.parse_into(bytes, $buf))? { ParseOutcome::Consume(offset, result) => { $self.reader.consume(offset); $self.state.make_event(result, &$buf[start..]) diff --git a/src/reader/slice_reader.rs b/src/reader/slice_reader.rs index 173b0c27..a975af21 100644 --- a/src/reader/slice_reader.rs +++ b/src/reader/slice_reader.rs @@ -70,6 +70,7 @@ impl<'a> Reader<&'a [u8]> { /// ``` #[inline] pub fn read_event(&mut self) -> Result> { + dbg!(self.state.parser); if let Some(end) = self.state.pending_end() { return Ok(end); } @@ -77,7 +78,7 @@ impl<'a> Reader<&'a [u8]> { if self.reader.is_empty() { return Ok(Event::Eof); } - let result = self.state.parser.feed(self.reader)?; + let result = dbg!(self.state.parser.feed(self.reader))?; return match result { FeedResult::NeedData => { let offset = self.reader.len(); diff --git a/src/reader/state.rs b/src/reader/state.rs index b7a59c03..57b19590 100644 --- a/src/reader/state.rs +++ b/src/reader/state.rs @@ -106,7 +106,8 @@ impl ReaderState { bytes: &'a [u8], buf: &'b mut Vec, ) -> Result { - let result = self.parser.feed(bytes)?; + dbg!(&self); + let result = dbg!(self.parser.feed(bytes))?; match result { FeedResult::NeedData => { let mut content = bytes;