graph_auth/resource_path/string/
lexer_utils.rs1use std::cell::RefCell;
2use std::ops::Range;
3
4use crate::resource_path::string::range_ex::AsRange;
5
6pub type LocatedSpan<'a> = nom_locate::LocatedSpan<&'a str, LexerState>;
7pub type IResult<'a, T> = nom::IResult<LocatedSpan<'a>, T>;
8
9#[derive(Clone, Debug)]
10pub struct LexerState(pub(super) RefCell<Vec<LexerError>>);
11
12#[derive(Clone, Debug)]
13pub struct LexerError(pub Range<usize>, pub String);
14
15impl LexerState {
16 pub fn new() -> Self {
17 LexerState(RefCell::new(Vec::new()))
18 }
19
20 pub(super) fn report_error(&self, error: LexerError) {
21 self.0.borrow_mut().push(error);
22 }
23}
24
25impl Default for LexerState {
26 fn default() -> Self {
27 LexerState::new()
28 }
29}
30
31impl<'a> AsRange for LocatedSpan<'a> {
32 fn as_range(&self) -> Range<usize> {
33 let start = self.location_offset();
34 let end = start + self.fragment().len();
35 start..end
36 }
37}