Skip to content

Commit 35aac84

Browse files
committed
feat: made the macro error message human readable
1 parent 80366ac commit 35aac84

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

Cargo.lock

Lines changed: 37 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bmatcher-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license-file.workspace = true
1010
bench = false
1111

1212
[dependencies]
13+
thiserror-no-std = "2.0.2"
1314

1415
[dev-dependencies]
1516
criterion = { version = "0.5", features = ["html_reports"] }

bmatcher-core/src/compiler/parser.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use alloc::vec::Vec;
22
use core::num::ParseIntError;
33

4+
use thiserror_no_std::Error;
5+
46
use super::{
57
Lexer,
68
PositionedError,
@@ -13,22 +15,33 @@ use crate::{
1315
ReadWidth,
1416
};
1517

16-
#[derive(Debug, PartialEq, Eq, Clone)]
18+
#[derive(Debug, Error, PartialEq, Eq, Clone)]
1719
pub enum ParseError {
20+
#[error("unexpected token encountered")]
1821
UnexpectedToken,
19-
UnexpectedEnd,
2022

21-
MaskByteLenMismatch,
23+
#[error("unexpected end of input")]
24+
UnexpectedEnd,
2225

26+
#[error("invalid binary value")]
2327
BinaryValueInvalid,
28+
29+
#[error("incomplete binary value; bits missing")]
2430
BinaryValueIncomplete,
2531

32+
#[error("group not properly closed (missing ')')")]
2633
GroupNotClosed,
34+
35+
#[error("block not properly closed (missing '}}')")]
2736
BlockNotClosed,
2837

38+
#[error("invalid range bound: {0}")]
2939
RangeBoundInvalid(ParseIntError),
40+
41+
#[error("range end must be greater than start")]
3042
RangeEndMustBeGraterThenStart,
3143

44+
#[error("sequence exceeds maximum allowed size")]
3245
SequenceTooLarge,
3346
}
3447

bmatcher-proc/src/macro_pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn pattern(item: TokenStream) -> Result<TokenStream> {
163163
.token()
164164
.subspan(error.position().start + 1..error.position().end + 1)
165165
.unwrap_or(pattern_str.span());
166-
return Err(Error::new(error_span, format!("{:?}", error.inner())));
166+
return Err(Error::new(error_span, format!("{}", error.inner())));
167167
}
168168
};
169169

0 commit comments

Comments
 (0)