socratic 0.0.1

A dialog system for games in rust
Documentation
use thiserror::Error;

use crate::lexing::Line;

#[derive(Debug, Error, Eq, PartialEq)]
pub enum LexError {
    #[error("end of input reached")]
    Eof,

    #[error("failed to lex the string")]
    Fail,
}

/// Error encountered while parsing dialog data.
#[derive(Debug, Error, PartialEq, Eq)]
pub enum BaseParseError {
    /// Error while lexing
    #[error("failed to parse dialog line")]
    LexError(#[from] LexError),

    /// Found a section `:: section` that is indented.
    #[error("sections must be at the start of the line")]
    IndentedSectionStartError,

    /// Couldn't find a section start where it was expected.
    #[error("expected the start of a section but saw `{0}`")]
    ExpectedSectionStart(Line<String, String, String>),

    /// Unexpected indent
    #[error("unexpected indent")]
    UnexpectedIndent,

    /// Unexpected dedent.
    #[error("unexpected dedent")]
    UnexpectedDedent,

    /// Unexpected line.
    #[error("expected line of type {0}, but found `{1}`")]
    UnexpectedLine(&'static str, Line<String, String, String>),

    /// No dialog node found
    #[error("expected a dialog node, but found `{0}`")]
    NoDialogNodeFound(Line<String, String, String>),

    /// Dialog tree was empty
    #[error("expected dialog tree, but it was empty")]
    EmptyDialogTree,

    #[error("duplicate section name {0}")]
    DuplicateSectionKey(String),
}

/// Error encountered while parsing dialog data.
#[derive(Debug, Error, PartialEq, Eq)]
pub enum ParseError<DAError, IFError, TEError> {
    /// Base
    #[error("{0}")]
    Base(#[from] BaseParseError),

    /// DoAction parse error
    #[error("failed to parse do action: {0}")]
    DoAction(DAError),

    /// IF parse error
    #[error("failed to parse if: {0}")]
    IF(IFError),

    /// Interpolation parse error
    #[error("failed to parse interpolation: {0}")]
    TE(TEError),
}

/// Errors with socratic dialogs.
#[derive(Debug, Error)]
pub enum SocraticError<DAError, IFError, TEError> {
    /// Parse error
    #[error("encountered an error while parsing: {0}")]
    Parse(#[from] ParseError<DAError, IFError, TEError>),

    /// IO Error
    #[error("encountered an IO error: {0}")]
    IO(#[from] std::io::Error),
}