bc_envelope_pattern/
error.rs

1use logos::Span;
2use thiserror::Error;
3
4use crate::parse::Token;
5
6/// Errors that can occur during parsing of Envelope patterns.
7#[derive(Debug, Clone, Error, PartialEq, Default)]
8pub enum Error {
9    #[error("Empty input")]
10    EmptyInput,
11
12    #[error("Unexpected end of input")]
13    UnexpectedEndOfInput,
14
15    #[error("Extra data at end of input")]
16    ExtraData(Span),
17
18    #[error("Unexpected token {0:?}")]
19    UnexpectedToken(Box<Token>, Span),
20
21    #[error("Unrecognized token at position {0:?}")]
22    UnrecognizedToken(Span),
23
24    #[error("Invalid regex pattern at {0:?}")]
25    InvalidRegex(Span),
26
27    #[error("Unterminated regex pattern at {0:?}")]
28    UnterminatedRegex(Span),
29
30    #[error("Invalid range at {0:?}")]
31    InvalidRange(Span),
32
33    #[error("Invalid hex string at {0:?}")]
34    InvalidHexString(Span),
35
36    #[error("Invalid date format at {0:?}")]
37    InvalidDateFormat(Span),
38
39    #[error("Invalid number format at {0:?}")]
40    InvalidNumberFormat(Span),
41
42    #[error("Invalid UR: {0} at {1:?}")]
43    InvalidUr(String, Span),
44
45    #[error("Expected opening parenthesis")]
46    ExpectedOpenParen(Span),
47
48    #[error("Expected closing parenthesis")]
49    ExpectedCloseParen(Span),
50
51    #[error("Expected pattern after operator")]
52    ExpectedPattern(Span),
53
54    #[error("Unmatched parentheses")]
55    UnmatchedParentheses(Span),
56
57    #[error("Unmatched braces")]
58    UnmatchedBraces(Span),
59
60    #[error("Invalid capture group name")]
61    InvalidCaptureGroupName(String, Span),
62
63    #[error("Unknown error")]
64    #[default]
65    Unknown,
66}
67
68/// A Result type specialized for envelope pattern parsing.
69pub type Result<T> = std::result::Result<T, Error>;