1use crate::input::{Show, Length};
2
3pub trait Token<I: Input>: Show + PartialEq<I::Token> { }
4
5pub trait Slice<I: Input>: Show + Length + PartialEq<I::Slice> { }
6
7impl<I: Input, T> Token<I> for T where T: Show + PartialEq<I::Token> { }
8
9impl<I: Input, S> Slice<I> for S where S: Show + Length + PartialEq<I::Slice> { }
10
11#[derive(Debug, Copy, Clone)]
12pub struct ParserInfo {
13 pub name: &'static str,
14 pub raw: bool,
15}
16
17pub trait Rewind: Sized + Input {
18 fn rewind_to(&mut self, marker: Self::Marker);
20}
21
22pub trait Input: Sized {
23 type Token: Token<Self>;
24 type Slice: Slice<Self>;
25 type Many: Length;
26
27 type Marker: Copy;
28 type Context: Show;
29
30 fn token(&mut self) -> Option<Self::Token>;
32
33 fn slice(&mut self, n: usize) -> Option<Self::Slice>;
35
36 fn peek<F>(&mut self, cond: F) -> bool
38 where F: FnMut(&Self::Token) -> bool;
39
40 fn peek_slice<F>(&mut self, n: usize, cond: F) -> bool
42 where F: FnMut(&Self::Slice) -> bool;
43
44 fn eat<F>(&mut self, cond: F) -> Option<Self::Token>
47 where F: FnMut(&Self::Token) -> bool;
48
49 fn eat_slice<F>(&mut self, n: usize, cond: F) -> Option<Self::Slice>
52 where F: FnMut(&Self::Slice) -> bool;
53
54 fn take<F>(&mut self, cond: F) -> Self::Many
57 where F: FnMut(&Self::Token) -> bool;
58
59 fn skip<F>(&mut self, cond: F) -> usize
62 where F: FnMut(&Self::Token) -> bool;
63
64 fn has(&mut self, n: usize) -> bool;
66
67 #[allow(unused_variables)]
69 fn mark(&mut self, info: &ParserInfo) -> Self::Marker;
70
71 fn context(&mut self, _mark: Self::Marker) -> Self::Context;
74}