Skip to main content

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 opening bracket")]
52    ExpectedOpenBracket(Span),
53
54    #[error("Expected closing bracket")]
55    ExpectedCloseBracket(Span),
56
57    #[error("Expected pattern after operator")]
58    ExpectedPattern(Span),
59
60    #[error("Unmatched parentheses")]
61    UnmatchedParentheses(Span),
62
63    #[error("Unmatched braces")]
64    UnmatchedBraces(Span),
65
66    #[error("Invalid capture group name")]
67    InvalidCaptureGroupName(String, Span),
68
69    #[error("Invalid pattern at {0:?}")]
70    InvalidPattern(Span),
71
72    #[error("Unknown error")]
73    #[default]
74    Unknown,
75
76    #[error(transparent)]
77    DCBORPatternError(#[from] dcbor_pattern::Error),
78}
79
80/// A Result type specialized for envelope pattern parsing.
81pub type Result<T> = std::result::Result<T, Error>;