# sipha-error

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Repository](https://img.shields.io/badge/github-sipha-blue)](https://github.com/NyalephTheCat/sipha)
[![Crates.io](https://img.shields.io/crates/v/sipha-error)](https://crates.io/crates/sipha-error)
[![docs.rs](https://docs.rs/sipha-error/badge.svg)](https://docs.rs/sipha-error)

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`:

```toml
[dependencies]
sipha-error = "0.1.1"
```

With diagnostics:

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

## Example

```rust
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](../LICENSE) file for details.

