Skip to content

Commit

Permalink
Use separate offset for errors
Browse files Browse the repository at this point in the history
In the perfect world we would add offset to the `Error` type, but right now
this is impractical, because this significantly changes some API that would be
removed soon
  • Loading branch information
Mingun committed Nov 29, 2023
1 parent 215cb79 commit 25f029d
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 126 deletions.
10 changes: 9 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The way to configure parser is changed. Now all configuration is contained in th
`Config` struct and can be applied at once. When `serde-types` feature is enabled,
configuration is serializable.

The way how positions of errors is reported is changed. Now use `error_position()`
to get an offset of the error position. For `SyntaxError`s the range
`error_position()..buffer_position()` also will represent a span of error.

### New Features

- [#513]: Allow to continue parsing after getting new `Error::IllFormed`.
Expand Down Expand Up @@ -46,18 +50,22 @@ configuration is serializable.
- `Error::XmlDeclWithoutVersion` replaced by `IllFormedError::MissingDeclVersion` (in [#684])
- `Error::EmptyDocType` replaced by `IllFormedError::MissingDoctypeName` (in [#684])
- [#684]: Changed positions reported for `SyntaxError`s: now they are always points
to the start of markup (i. e. to the `<` character) with error.
to the start of markup (i. e. to the `<` character) with error. Use `error_position()`
for that.
- [#684]: Now `<??>` parsed as `Event::PI` with empty content instead of raising
syntax error.
- [#684]: Now `<?xml?>` parsed as `Event::Decl` instead of `Event::PI`.
- [#362]: Now default quote level is `QuoteLevel::Partial` when using serde serializer.
- [#689]: `buffer_position()` now always report the position the parser last seen.
To get an error position use `error_position()`.

[#362]: https://github.com/tafia/quick-xml/issues/362
[#513]: https://github.com/tafia/quick-xml/issues/513
[#622]: https://github.com/tafia/quick-xml/issues/622
[#675]: https://github.com/tafia/quick-xml/pull/675
[#677]: https://github.com/tafia/quick-xml/pull/677
[#684]: https://github.com/tafia/quick-xml/pull/684
[#689]: https://github.com/tafia/quick-xml/pull/689


## 0.31.0 -- 2023-10-22
Expand Down
12 changes: 3 additions & 9 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ macro_rules! impl_buffered_source {
buf.push(b'!');
self $(.$reader)? .consume(1);

let bang_type = BangType::new(self.peek_one() $(.$await)? ?, position)?;
let bang_type = BangType::new(self.peek_one() $(.$await)? ?)?;

loop {
match self $(.$reader)? .fill_buf() $(.$await)? {
Expand Down Expand Up @@ -139,10 +139,7 @@ macro_rules! impl_buffered_source {
}
}

// <!....EOF
// ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
// so we move offset to it (+1 for `<`)
*position -= 1;
*position += read;
Err(bang_type.to_err())
}

Expand Down Expand Up @@ -186,10 +183,7 @@ macro_rules! impl_buffered_source {
};
}

// <.....EOF
// ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
// so we move offset to it (+1 for `<`)
*position -= 1;
*position += read;
Err(Error::Syntax(SyntaxError::UnclosedTag))
}

Expand Down

0 comments on commit 25f029d

Please sign in to comment.