Skip to content

Commit 0055561

Browse files
committed
feat(stream): Add access to previous tokens
1 parent 85cef7e commit 0055561

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/stream/token.rs

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ where
5151
let start = self.initial.checkpoint();
5252
self.input.reset(&start);
5353
}
54+
55+
/// Iterate over consumed tokens starting with the last emitted
56+
///
57+
/// This is intended to help build up appropriate context when reporting errors.
58+
#[inline]
59+
pub fn previous_tokens(&self) -> impl Iterator<Item = &'t T> {
60+
let offset = self.input.offset_from(&self.initial);
61+
self.initial[0..offset].iter().rev()
62+
}
5463
}
5564

5665
/// Track locations by implementing [`Location`] on the Token.

0 commit comments

Comments
 (0)