diff --git a/src/proc_macros/Cargo.toml b/src/proc_macros/Cargo.toml index b94737d..e13b48c 100644 --- a/src/proc_macros/Cargo.toml +++ b/src/proc_macros/Cargo.toml @@ -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" diff --git a/src/proc_macros/regex_code.rs b/src/proc_macros/regex_code.rs index 06bdc31..7658656 100644 --- a/src/proc_macros/regex_code.rs +++ b/src/proc_macros/regex_code.rs @@ -29,7 +29,7 @@ impl TryFrom 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, @@ -38,7 +38,13 @@ impl TryFrom 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), + )); } }; }