oni_comb_parser_rs/core/
parse_state.rs1#[derive(Clone)]
3pub struct ParseState<'a, I> {
4 input: &'a [I],
5 offset: usize,
6}
7
8impl<'a, I> ParseState<'a, I> {
9 pub fn new(input: &'a [I], offset: usize) -> Self {
11 Self { input, offset }
12 }
13
14 pub fn last_offset(&self) -> Option<usize> {
16 if self.offset > 0 {
17 Some(self.offset - 1)
18 } else {
19 None
20 }
21 }
22
23 pub fn current_offset(&self) -> usize {
25 self.offset
26 }
27
28 pub fn advance_by(&self, num_chars: usize) -> ParseState<'a, I> {
30 Self::new(self.input, self.offset + num_chars)
31 }
32
33 pub fn input(&self) -> &'a [I] {
35 &self.input[self.offset..]
36 }
37
38 pub fn slice_with_len(&self, n: usize) -> &'a [I] {
40 &self.input[self.offset..self.offset + n]
41 }
42}