Skip to content

Commit 02d6176

Browse files
committed
dbg! in xml
1 parent 2b35ebf commit 02d6176

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/parser/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,12 @@ impl Parser {
340340
/// - `bytes`: a slice to search a new XML event. Should contain text in
341341
/// ASCII-compatible encoding
342342
pub fn feed(&mut self, bytes: &[u8]) -> Result<FeedResult, SyntaxError> {
343+
dbg!((self.0, crate::utils::Bytes(bytes)));
343344
for (offset, &byte) in bytes.iter().enumerate() {
344345
let trail = &bytes[offset..];
345346
let start = offset + 1;
346347
let rest = &bytes[start..];
348+
dbg!((self.0, offset, byte as char, crate::utils::Bytes(trail), crate::utils::Bytes(rest)));
347349
self.0 = match self.0 {
348350
State::Start => match byte {
349351
0x00 => State::Bom(BomParser::X00),
@@ -544,6 +546,7 @@ impl Parser {
544546
/// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()`
545547
#[inline]
546548
fn parse_text(&mut self, bytes: &[u8], offset: usize) -> FeedResult {
549+
dbg!((self.0, offset, crate::utils::Bytes(bytes)));
547550
self.0 = State::Text;
548551
match bytes.iter().position(|&b| b == b'<') {
549552
Some(i) => FeedResult::EmitText(offset + i),
@@ -565,6 +568,7 @@ impl Parser {
565568
offset: usize,
566569
mut parser: CommentParser,
567570
) -> FeedResult {
571+
dbg!((self.0, offset, crate::utils::Bytes(bytes), parser));
568572
match parser.feed(bytes) {
569573
Some(i) => {
570574
self.0 = State::Text;
@@ -588,6 +592,7 @@ impl Parser {
588592
/// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()`
589593
/// - `braces_left`: count of braces that wasn't seen yet in the end of previous data chunk
590594
fn parse_cdata(&mut self, bytes: &[u8], offset: usize, mut parser: CDataParser) -> FeedResult {
595+
dbg!((self.0, offset, crate::utils::Bytes(bytes), parser));
591596
match parser.feed(bytes) {
592597
Some(i) => {
593598
self.0 = State::Text;
@@ -606,8 +611,9 @@ impl Parser {
606611
offset: usize,
607612
mut parser: QuotedParser,
608613
) -> Result<FeedResult, SyntaxError> {
614+
dbg!((self.0, offset, crate::utils::Bytes(bytes), parser));
609615
// Search `[` (start of DTD definitions) or `>` (end of <!DOCTYPE> tag)
610-
match parser.one_of(bytes) {
616+
match dbg!(parser.one_of(bytes)) {
611617
OneOf::Open(i) => self.parse_dtd(&bytes[i..], offset + i, DtdParser::default()),
612618
OneOf::Close(i) => {
613619
self.0 = State::Text;
@@ -634,8 +640,9 @@ impl Parser {
634640
mut offset: usize,
635641
mut parser: DtdParser,
636642
) -> Result<FeedResult, SyntaxError> {
643+
dbg!((self.0, offset, crate::utils::Bytes(bytes), parser));
637644
loop {
638-
let result = match parser.feed(bytes) {
645+
let result = match dbg!(parser.feed(bytes)) {
639646
// Skip recognized DTD structure
640647
// TODO: Emit DTD events while parsing
641648
quick_dtd::FeedResult::EmitPI(off)
@@ -664,7 +671,8 @@ impl Parser {
664671
}
665672

666673
fn parse_doctype_finish(&mut self, bytes: &[u8], offset: usize) -> FeedResult {
667-
match bytes.iter().position(|&b| b == b'>') {
674+
dbg!((self.0, offset, crate::utils::Bytes(bytes)));
675+
match dbg!(bytes.iter().position(|&b| b == b'>')) {
668676
Some(i) => {
669677
self.0 = State::Text;
670678
// +1 for `>` which should be included in event
@@ -687,7 +695,8 @@ impl Parser {
687695
/// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()`
688696
/// - `has_mark`: a flag that indicates was the previous fed data ended with `?`
689697
fn parse_pi(&mut self, bytes: &[u8], offset: usize, mut parser: PiParser) -> FeedResult {
690-
match parser.feed(bytes) {
698+
dbg!((self.0, offset, crate::utils::Bytes(bytes), parser));
699+
match dbg!(parser.feed(bytes)) {
691700
Some(i) => {
692701
self.0 = State::Text;
693702
FeedResult::EmitPI(offset + i)
@@ -706,7 +715,8 @@ impl Parser {
706715
/// That sub-slice begins on the byte that represents a tag name
707716
/// - `offset`: a position of `bytes` sub-slice in the one that was passed to `feed()`
708717
fn parse_end(&mut self, bytes: &[u8], offset: usize) -> FeedResult {
709-
match bytes.iter().position(|&b| b == b'>') {
718+
dbg!((self.0, offset, crate::utils::Bytes(bytes)));
719+
match dbg!(bytes.iter().position(|&b| b == b'>')) {
710720
Some(i) => {
711721
self.0 = State::Text;
712722
// +1 for `>` which should be included in event
@@ -735,7 +745,8 @@ impl Parser {
735745
mut parser: QuotedParser,
736746
has_slash: bool,
737747
) -> FeedResult {
738-
match parser.feed(bytes) {
748+
dbg!((self.0, offset, crate::utils::Bytes(bytes), parser, has_slash));
749+
match dbg!(parser.feed(bytes)) {
739750
Some(0) if has_slash => {
740751
self.0 = State::Text;
741752
// +1 for `>` which should be included in event

src/reader/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,22 @@ macro_rules! read_event_impl {
204204
$self:ident, $buf:ident
205205
$(, $await:ident)?
206206
) => {{
207+
dbg!("===============================================================");
207208
if let Some(end) = $self.state.pending_end() {
208209
return Ok(end);
209210
}
210211
// Content in buffer before call is not a part of next event
211212
let start = $buf.len();
212213
let offset = $self.state.offset;
213214
loop {
214-
break match $self.reader.fill_buf() $(.$await)? {
215+
dbg!("--------------------------------");
216+
break match dbg!($self.reader.fill_buf() $(.$await)?) {
215217
Ok(bytes) if bytes.is_empty() => {
216218
let content = &$buf[start..];
217219
if content.is_empty() {
218220
Ok(Event::Eof)
219221
} else
220-
if let Err(error) = $self.state.parser.finish() {
222+
if let Err(error) = dbg!($self.state.parser.finish()) {
221223
$self.state.last_error_offset = offset;
222224
Err(Error::Syntax(error))
223225
} else {
@@ -226,7 +228,7 @@ macro_rules! read_event_impl {
226228
Ok(Event::Text(BytesText::wrap(content, $self.decoder())))
227229
}
228230
}
229-
Ok(bytes) => match $self.state.parse_into(bytes, $buf)? {
231+
Ok(bytes) => match dbg!($self.state.parse_into(bytes, $buf))? {
230232
ParseOutcome::Consume(offset, result) => {
231233
$self.reader.consume(offset);
232234
$self.state.make_event(result, &$buf[start..])

src/reader/slice_reader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ impl<'a> Reader<&'a [u8]> {
7070
/// ```
7171
#[inline]
7272
pub fn read_event(&mut self) -> Result<Event<'a>> {
73+
dbg!(self.state.parser);
7374
if let Some(end) = self.state.pending_end() {
7475
return Ok(end);
7576
}
7677
loop {
7778
if self.reader.is_empty() {
7879
return Ok(Event::Eof);
7980
}
80-
let result = self.state.parser.feed(self.reader)?;
81+
let result = dbg!(self.state.parser.feed(self.reader))?;
8182
return match result {
8283
FeedResult::NeedData => {
8384
let offset = self.reader.len();

src/reader/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl ReaderState {
106106
bytes: &'a [u8],
107107
buf: &'b mut Vec<u8>,
108108
) -> Result<ParseOutcome> {
109-
let result = self.parser.feed(bytes)?;
109+
dbg!(&self);
110+
let result = dbg!(self.parser.feed(bytes))?;
110111
match result {
111112
FeedResult::NeedData => {
112113
let mut content = bytes;

0 commit comments

Comments
 (0)