treehouse/crates/treehouse-format/src/lib.rs

30 lines
733 B
Rust
Raw Normal View History

2023-08-17 21:59:56 +02:00
use std::ops::Range;
2023-08-18 13:25:20 +02:00
pub mod ast;
pub mod pull;
2023-08-17 21:59:56 +02:00
#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
pub enum ParseErrorKind {
#[error("branch kind (`+` or `-`) expected")]
BranchKindExpected,
2023-08-18 13:25:20 +02:00
#[error("root branches must not be indented")]
RootIndentLevel,
#[error("at least {expected} spaces of indentation were expected, but got {got}")]
InconsistentIndentation { got: usize, expected: usize },
2023-08-17 21:59:56 +02:00
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("{range:?}: {kind}")]
pub struct ParseError {
pub kind: ParseErrorKind,
pub range: Range<usize>,
}
2023-08-18 13:25:20 +02:00
impl ParseErrorKind {
pub fn at(self, range: Range<usize>) -> ParseError {
ParseError { kind: self, range }
2023-08-17 21:59:56 +02:00
}
}