alkale 2.0.0

A simple LL(1) lexer library for Rust.
Documentation
//! Container module for string and character errors.

use crate::span::Span;

/// Aggregate collection of [`StringTokenError`]s.
pub type StringErrorList = Vec<StringTokenError<ParseCharError>>;

/// An error type representing a failed character-token parsing.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum CharTokenError {
    /// Wrapper for [`ParseCharError`].
    CharError(ParseCharError),
    /// Indicates that no closing `'` was found after the character— another character was found instead.
    /// Contains a [`char`] that represents the character found instead of a `'`.
    UnclosedCharError(char),
    /// Indicates that no closing `'` was found after the character— EOF was found instead.
    UnclosedCharErrorEOF,
}

/// An error type representing a failed string parsing.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum StringTokenError<E> {
    /// Contains a character-based error.
    CharError(E),
    /// Indicates that a closing quotation was not found.
    NoClosingDelimiter,
}

/// An error type representing a failed character parsing.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ParseCharError {
    /// Indicates that EOF was found instead of a valid character to parse.
    NoCharFound,
    /// Indicates that a backslash was used to escape a character, but EOF was found
    /// after the backslash.
    ///
    /// The contained [`Span`] encapsulates the backslash character.
    NoEscape(Span),
    /// Indicates that a backslash was used to escape a character, and the found
    /// character is not a valid escape.
    ///
    /// The contained [`char`] is the illegal character, and
    /// the [`Span`] covers both the backslash and the offending character.
    IllegalEscape(char, Span),
    /// Indicates that the a char token's delimiter was found unescaped.
    ///
    /// The contained [`Span`] contains the position of the offending delimiter character.
    ///
    /// # Safety
    /// This variant should never be constructed by a string-parsing method. An unescaped
    /// delimiter should be handled appropriately.
    UnescapedDelimiter(Span),
}