chappi-syntax 0.1.0

Canonical S-expression parser and serializer for the Chappi cognitive-state language
Documentation
use serde::{Deserialize, Serialize};

use crate::Span;

/// The externally visible severity of a syntax diagnostic.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Severity {
    Error,
    Warning,
}

/// A structured parser error suitable for either human or machine output.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Diagnostic {
    pub code: String,
    pub severity: Severity,
    pub span: Span,
    pub semantic_path: Vec<String>,
    pub message: String,
    pub hint: Option<String>,
}

impl Diagnostic {
    pub(crate) fn error(code: &str, span: Span, message: impl Into<String>) -> Self {
        Self {
            code: code.to_owned(),
            severity: Severity::Error,
            span,
            semantic_path: Vec::new(),
            message: message.into(),
            hint: None,
        }
    }
}