sipha-error

Crates.iosipha-error
lib.rssipha-error
version0.3.1
created_at2025-11-19 17:47:44.388872+00
updated_at2025-11-22 10:29:32.802821+00
descriptionError handling and diagnostics for sipha parsers
homepage
repositoryhttps://github.com/NyalephTheCat/sipha
max_upload_size
id1940488
size57,264
Nyaleph (NyalephTheCat)

documentation

README

sipha-error

License: MIT Repository Crates.io docs.rs

Error handling and diagnostics for sipha parsers.

Overview

sipha-error provides comprehensive error handling and diagnostic capabilities for sipha parsers:

  • ParseError: Enum with all parse error variants
  • Expected: Type for describing expected tokens
  • ErrorContext: Context tracking for error reporting
  • Diagnostic: Rich diagnostic types with miette integration (optional)

Features

  • default: Includes diagnostics feature
  • diagnostics: Enables rich error diagnostics with miette integration
  • color: Adds color support for error output (requires diagnostics)

Quick Start

Add sipha-error to your Cargo.toml:

[dependencies]
sipha-error = "0.1.1"

With diagnostics:

[dependencies]
sipha-error = { version = "0.1.1", features = ["diagnostics", "color"] }

Example

use sipha_error::{ParseError, Expected};
use sipha_core::{span::Span, traits::TokenKind};

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum Token { Ident, Plus }
impl TokenKind for Token { fn is_trivia(&self) -> bool { false } }

let error = ParseError::Expected {
    expected: Expected::Single(Token::Ident),
    found: Some(Token::Plus),
    span: Span::new(0, 1),
    rule_context: None,
    context_stack: vec![],
};

#[cfg(feature = "diagnostics")]
{
    use sipha_error::Diagnostic;
    let diagnostic = Diagnostic::from_parse_error(&error);
    println!("{}", diagnostic.format_with_source("+ 5"));
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt