lite_parser/
traits.rs

1pub trait Position: core::ops::Sub<Self, Output = i32> + Copy {
2    fn index(&self) -> u32;
3    fn line(&self) -> u32;
4    fn column(&self) -> u32;
5}
6
7pub trait Error {
8    type Position;
9    fn reasons(&self) -> &[(Self::Position, &'static str)];
10    fn add_reason(self, position: Self::Position, reason: &'static str) -> Self;
11}
12
13pub trait Input: Default {
14    type Position: Position;
15    type Error: Error<Position = Self::Position>;
16    fn next(&self, pos: Self::Position) -> Result<(char, Self::Position), Self::Error>;
17    fn next_range(
18        &self,
19        start: Self::Position,
20        counts: u32,
21    ) -> Result<(&str, Self::Position), Self::Error>;
22    fn error_at(&self, pos: Self::Position, reason: &'static str) -> Self::Error;
23    fn is_end(&self, pos: Self::Position) -> bool;
24}
25
26pub type ResultOf<I, O> = Result<(O, <I as Input>::Position), <I as Input>::Error>;