diff options
author | Martin Fischer <martin@push-f.com> | 2023-08-17 16:12:51 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-08-19 13:41:55 +0200 |
commit | cb4e9cf7cfc1612c67f16bfabadbdf442cd380fe (patch) | |
tree | 5aa2bf7dccafe66d735f3609d446bfad083ab8a3 /src/tokenizer.rs | |
parent | c15895d44d17984386d3684e2aa85aca386ba3bf (diff) |
fix: fix lots of position off-by-ones
Previously the PosTrackingReader always mysteriously subtracted 1
from the current position ... this wasn't sound at all ... the machine
just happens to often call `Tokenizer::unread_char` ... but not always.
E.g. for proper comments it didn't which resulted in their offset and
spans being off-by-one, which is fixed by this commit (see test_spans.rs).
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r-- | src/tokenizer.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 02a4d62..e8a8908 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -106,7 +106,7 @@ impl From<State> for InternalState { } } -impl<R: Reader + Position<O>, O, E: Emitter<O>> Tokenizer<R, O, E> { +impl<R: Reader + Position<O>, O: Offset, E: Emitter<O>> Tokenizer<R, O, E> { /// Test-internal function to override internal state. /// /// Only available with the `integration-tests` feature which is not public API. @@ -123,7 +123,7 @@ impl<R: Reader + Position<O>, O, 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()); + self.emitter.emit_error(error, self.reader.position() - 1); } /// Assuming the _current token_ is an end tag, return true if all of these hold. Return false otherwise. @@ -140,14 +140,14 @@ impl<R: Reader + Position<O>, O, E: Emitter<O>> Tokenizer<R, O, E> { #[inline] pub(crate) fn init_start_tag(&mut self) { - self.emitter.init_start_tag(self.reader.position()); + self.emitter.init_start_tag(self.reader.position() - 1); self.current_tag_name.clear(); self.is_start_tag = true; } #[inline] pub(crate) fn init_end_tag(&mut self) { - self.emitter.init_end_tag(self.reader.position()); + self.emitter.init_end_tag(self.reader.position() - 1); self.current_tag_name.clear(); self.is_start_tag = false; } |