Skip to main content

oni_comb_parser/primitive/
eof.rs

1use core::marker::PhantomData;
2
3use crate::error::ParseError;
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 = ParseError;
16  type Output = ();
17
18  #[inline]
19  fn parse_next(&mut self, input: &mut I) -> PResult<(), ParseError> {
20    if input.is_eof() {
21      Ok(())
22    } else {
23      Err(Fail::Backtrack(ParseError::expected_eof(input.offset())))
24    }
25  }
26}