aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-29 12:13:53 +0200
committerMartin Fischer <martin@push-f.com>2023-09-03 23:00:05 +0200
commitc38810192fbf11007f53bcccd48072e099a4191a (patch)
tree796f86fa5383fdf1d84823ac5d746603fa7c2347
parentd45e09a3157c71e3c95bf618a2b181f322c87a5d (diff)
break!: make Emitter::emit_error take span
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/emitter.rs8
-rw-r--r--src/tokenizer.rs5
3 files changed, 10 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 832f00d..90a9101 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,8 @@
* Removed `adjusted_current_node_present_and_not_in_html_namespace`.
+ * `emit_error` now takes a span instead of an offset.
+
* token types
* `AttributeOwned`: The `value_offset` field has been replaced with `value_span`.
diff --git a/src/emitter.rs b/src/emitter.rs
index e56ddd5..a014025 100644
--- a/src/emitter.rs
+++ b/src/emitter.rs
@@ -39,7 +39,7 @@ pub trait Emitter<O> {
fn emit_eof(&mut self);
/// A (probably recoverable) parsing error has occurred.
- fn emit_error(&mut self, error: Error, offset: O);
+ fn emit_error(&mut self, error: Error, span: Range<O>);
/// After every state change, the tokenizer calls this method to retrieve a new token that can
/// be returned via the tokenizer's iterator interface.
@@ -261,8 +261,8 @@ impl<O: Offset> Emitter<O> for DefaultEmitter<O> {
self.flush_current_characters();
}
- fn emit_error(&mut self, error: Error, offset: O) {
- self.push_error(error, offset..offset);
+ fn emit_error(&mut self, error: Error, span: Range<O>) {
+ self.push_error(error, span);
}
fn pop_token(&mut self) -> Option<Self::Token> {
@@ -339,7 +339,7 @@ impl<O: Offset> Emitter<O> for DefaultEmitter<O> {
*self_closing = true;
}
Token::EndTag(_) => {
- self.emit_error(Error::EndTagWithTrailingSolidus, offset - 1);
+ self.emit_error(Error::EndTagWithTrailingSolidus, offset - 1..offset - 1);
}
_ => {
debug_assert!(false);
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 5b11db0..db4fda6 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -178,7 +178,10 @@ impl<R: Reader + Position<O>, O: Offset, E: Emitter<O>> Tokenizer<R, O, E> {
/// Just a helper method for the machine.
#[inline]
pub(crate) fn emit_error(&mut self, error: Error) {
- self.emitter.emit_error(error, self.reader.position() - 1);
+ self.emitter.emit_error(
+ error,
+ self.reader.position() - 1..self.reader.position() - 1,
+ );
}
/// Assuming the _current token_ is an end tag, return true if all of these hold. Return false otherwise.