yapcol 0.1.0

Yet Another Parser Combinator Library - YAPCoL
Documentation
//! Error types returned by parsers when they fail to match input.
//!
//! This module defines [`Error`], the single error type used throughout the crate. Every parser
//! returns `Result<O, Error>`, so understanding the variants is enough to handle all failure
//! cases.

/// The error type returned by all parsers in this crate.
///
/// A parser returns `Err(Error::UnexpectedToken)` when the next token does not satisfy its
/// requirements, and `Err(Error::EndOfInput)` when it needs more tokens but the input stream is
/// exhausted.
///
/// # Examples
///
/// ```
/// use yapcol::{is, any};
/// use yapcol::error::Error;
/// use yapcol::input::Input;
///
/// let tokens = vec!['a'];
/// let mut input = Input::new(tokens);
///
/// // Fails with UnexpectedToken when the token does not match.
/// assert_eq!(is('b')(&mut input), Err(Error::UnexpectedToken));
///
/// // Fails with EndOfInput when the stream is exhausted.
/// is('a')(&mut input).unwrap(); // Consume the only token
/// assert_eq!(any()(&mut input), Err(Error::EndOfInput));
/// ```
#[derive(Copy, Clone, PartialOrd, PartialEq, Debug)]
pub enum Error {
	/// The next token was present but did not satisfy the parser's requirements.
	UnexpectedToken,
	/// The input stream was exhausted before the parser could match.
	EndOfInput,
}