34 lines
874 B
Rust
34 lines
874 B
Rust
//! Error types for the parser.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// Parser error type.
|
|
#[derive(Debug, Error)]
|
|
pub enum ParseError {
|
|
/// Tree-sitter failed to parse the document.
|
|
#[error("parsing failed")]
|
|
ParseFailed,
|
|
|
|
/// A node had an unexpected type.
|
|
#[error("unexpected node type: expected {expected}, got {actual}")]
|
|
UnexpectedNode {
|
|
expected: &'static str,
|
|
actual: String,
|
|
},
|
|
|
|
/// A required field was missing.
|
|
#[error("missing required field: {field}")]
|
|
MissingField { field: &'static str },
|
|
|
|
/// Invalid value encountered.
|
|
#[error("invalid value: {message}")]
|
|
InvalidValue { message: String },
|
|
|
|
/// The tree had a syntax error.
|
|
#[error("syntax error at byte {offset}")]
|
|
SyntaxError { offset: usize },
|
|
}
|
|
|
|
/// Result type for parsing operations.
|
|
pub type ParseResult<T> = Result<T, ParseError>;
|