dcbor_pattern/
error.rs

1use logos::Span;
2use thiserror::Error;
3
4use crate::parse::Token;
5
6/// Errors that can occur during parsing of dCBOR 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("Unterminated string literal at {0:?}")]
31    UnterminatedString(Span),
32
33    #[error("Invalid range at {0:?}")]
34    InvalidRange(Span),
35
36    #[error("Invalid hex string at {0:?}")]
37    InvalidHexString(Span),
38
39    #[error("Unterminated hex string at {0:?}")]
40    UnterminatedHexString(Span),
41
42    #[error("Invalid date format at {0:?}")]
43    InvalidDateFormat(Span),
44
45    #[error("Invalid number format at {0:?}")]
46    InvalidNumberFormat(Span),
47
48    #[error("Invalid UR: {0} at {1:?}")]
49    InvalidUr(String, Span),
50
51    #[error("Expected opening parenthesis")]
52    ExpectedOpenParen(Span),
53
54    #[error("Expected closing parenthesis")]
55    ExpectedCloseParen(Span),
56
57    #[error("Expected closing bracket")]
58    ExpectedCloseBracket(Span),
59
60    #[error("Expected closing brace")]
61    ExpectedCloseBrace(Span),
62
63    #[error("Expected colon")]
64    ExpectedColon(Span),
65
66    #[error("Expected pattern after operator")]
67    ExpectedPattern(Span),
68
69    #[error("Unmatched parentheses")]
70    UnmatchedParentheses(Span),
71
72    #[error("Unmatched braces")]
73    UnmatchedBraces(Span),
74
75    #[error("Invalid capture group name")]
76    InvalidCaptureGroupName(String, Span),
77
78    #[error("Invalid digest pattern: {0} at {1:?}")]
79    InvalidDigestPattern(String, Span),
80
81    #[error("Unterminated digest quoted pattern at {0:?}")]
82    UnterminatedDigestQuoted(Span),
83
84    #[error("Unterminated date quoted pattern at {0:?}")]
85    UnterminatedDateQuoted(Span),
86
87    #[error("Unknown error")]
88    #[default]
89    Unknown,
90}
91
92/// A Result type specialized for dCBOR pattern parsing.
93pub type Result<T> = std::result::Result<T, Error>;