context-weaver 0.1.1

(WIP) A procedural text evaluation engine
Documentation
// src/errors.rs
use thiserror::Error;

#[derive(Debug, Error)]
pub enum WorldInfoError {
    #[error("Parser error: {0}")]
    ParserError(ParserError),
    #[error("Processor error: {0}")]
    ProcessorError(String),
    #[error("Evaluation error: {0}")]
    EvaluationError(String),
}

/// Errors that can occur during parsing and processing of world info text.
#[derive(Error, Debug)]
pub enum ParserError {
    /// Error originating from the pest parser (e.g., syntax error).
    #[error("Parsing error: {0}")]
    PestParse(#[from] pest::error::Error<Rule>),

    /// Error during JSON serialization or deserialization of properties.
    #[error("JSON processing error: {0}")]
    Json(#[from] serde_json::Error),

    /// Failed to find or instantiate a processor.
    #[error("Processor '{0}' not found or failed to instantiate: {1}")]
    ProcessorInstantiation(String, String), // name, underlying error string

    /// An invalid rule was encountered during AST construction.
    #[error("Invalid parsing rule encountered: {0:?}")]
    InvalidRule(Rule),

    /// Error originating from a processor's execution.
    // Assuming WorldInfoError can be converted or displayed
    #[error("Processor execution failed: {0}")]
    ProcessorExecution(String), // Displayable error from WorldInfoError

    /// Trigger tag is missing the required 'id' attribute.
    #[error("Trigger tag missing 'id' attribute: {0}")]
    MissingTriggerId(String),

    #[error("Processing error: {0}")]
    Processing(String),

    #[error("Undefined variable: {0}")]
    UndefinedVariable(String),

    #[error("Variable already exists: {0}")]
    VariableAlreadyExists(String),

    #[error("Insufficient permissions: {0}")]
    InsufficientPermissions(String),

    #[error("Type error: {0}")]
    TypeError(String),

    #[error("Evaluation error: {0}")] // For variable/macro evaluation issues
    Evaluation(String),
    
    #[error("Internal parser error: {0}")]
    Internal(String),

    #[error("Regex compilation error: {0}")]
    RegexCompilation(String, String),
}

// Import the Rule enum generated by pest
use crate::parser::Rule;