oni_comb_parser/primitive/
eof.rs1use core::marker::PhantomData;
2
3use crate::error::{ExpectError, Expected};
4use crate::fail::{Fail, PResult};
5use crate::input::Input;
6use crate::parser::Parser;
7
8pub struct Eof<I: Input>(PhantomData<fn(&mut I)>);
9
10pub fn eof<I: Input>() -> Eof<I> {
11 Eof(PhantomData)
12}
13
14impl<I: Input> Parser<I> for Eof<I> {
15 type Error = I::Error;
16 type Output = ();
17
18 #[inline]
19 fn parse_next(&mut self, input: &mut I) -> PResult<(), I::Error> {
20 if input.is_eof() {
21 Ok(())
22 } else {
23 Err(Fail::Backtrack(I::Error::from_expected(input.offset(), Expected::Eof)))
24 }
25 }
26}