css_parse/
parser_checkpoint.rs

1use crate::{Cursor, Kind, Span, ToSpan, Token};
2
3/// Represents a point during the [Parser's][crate::Parser] lifecycle; retaining state that can then be rewound.
4///
5/// Don't use this directly, instead retrieve a checkpoint with [Parser::checkpoint()][crate::Parser::checkpoint] and
6/// rewind the parser to a checkpoint with [Parser::rewind()][crate::Parser::rewind()].
7#[derive(Debug, Clone)]
8pub struct ParserCheckpoint<I> {
9	pub(crate) cursor: Cursor,
10	pub(crate) errors_pos: u8,
11	pub(crate) trivia_pos: u16,
12	pub(crate) iter: I,
13	pub(crate) buffer: [Cursor; 12],
14	pub(crate) buffer_index: usize,
15}
16
17impl<I> From<ParserCheckpoint<I>> for Cursor {
18	fn from(value: ParserCheckpoint<I>) -> Self {
19		value.cursor
20	}
21}
22
23impl<I> From<ParserCheckpoint<I>> for Token {
24	fn from(value: ParserCheckpoint<I>) -> Self {
25		value.cursor.token()
26	}
27}
28
29impl<I> From<ParserCheckpoint<I>> for Kind {
30	fn from(value: ParserCheckpoint<I>) -> Self {
31		value.cursor.token().kind()
32	}
33}
34
35impl<I> ToSpan for ParserCheckpoint<I> {
36	fn to_span(&self) -> Span {
37		self.cursor.span()
38	}
39}