pipa-lang 1.0.0-alpha.1

A tiny template language
Documentation
// SPDX-FileCopyrightText: Copyright 2026 olav@occy.org
// SPDX-License-Identifier: MPL-2.0

//! Errors related to lexing, parsing, and evaluation. No panics.

use crate::value::span::Span;

#[derive(Debug, PartialEq)]
pub struct Error {
    pub kind: ErrorKind,
    pub source: Option<String>,
    pub span: Span,
    pub message: String,
}

impl core::error::Error for Error {}

impl core::fmt::Display for Error {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{self:?}")
    }
}

#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum ErrorKind {
    Lex,
    Parse,
    Eval,
    Flag,
    Func,
    String,
    Template,
}

impl core::fmt::Display for ErrorKind {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.write_str(&format!("{self:?}").to_lowercase())
    }
}

impl From<Error> for Span {
    fn from(value: Error) -> Self {
        value.span
    }
}