Skip to content

Commit

Permalink
Merge branch 'necauqua-pretty-errors' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Canop committed Nov 3, 2022
2 parents 482e15c + 2d3ad8d commit 7f862c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/proc_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
edition = "2018"

[dependencies]
syn = { version = "1.0", features = ["full"] }
syn = { version = "1.0.103", features = ["full"] }
proc-macro2 = "1.0"
quote = "1.0"
regex = "1.5"
Expand Down
10 changes: 8 additions & 2 deletions src/proc_macros/regex_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl TryFrom<LitStr> for RegexCode {
let mut ignore_whitespace = false;
let mut swap_greed = false;
let mut is_bytes = false;
for ch in lit_str.suffix().chars() {
for (i, ch) in lit_str.suffix().chars().enumerate() {
match ch {
'i' => case_insensitive = true,
'm' => multi_line = true,
Expand All @@ -38,7 +38,13 @@ impl TryFrom<LitStr> for RegexCode {
'U' => swap_greed = true,
'B' => is_bytes = true, // non-standard!
_ => {
panic!("unrecognized regex flag {:?}", ch);
let lit = lit_str.token();
let pos = lit.to_string().len() - i;
// subspan only works on nighlty
return Err(syn::Error::new(
lit.subspan(pos - 1..pos).unwrap_or_else(|| lit.span()),
format!("unrecognized regex flag {:?}", ch),
));
}
};
}
Expand Down

0 comments on commit 7f862c1

Please sign in to comment.