Skip to content

Commit

Permalink
chore(craft-macros): fix REGEX_STR
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Sep 29, 2024
1 parent f4e456c commit d6e6988
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions crates/craft-macros/src/craft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ pub(crate) fn generate(input: Item) -> syn::Result<TokenStream> {
}
}

const REGEX_STR: &'static str =
r#"(?s)#\s*\[\s*craft\s*\(\s*(?P<name>handler|endpoint)\s*(?P<content>\(.*\))?\s*\)\s*\]"#;
const REGEX_STR: &'static str = r#"(?s)#\s*\[\s*(::)?\s*([a-zA-z][a-zA-z0-9]*\s*::\s*)*\s*craft\s*\(\s*(?P<name>handler|endpoint)\s*(?P<content>\(.*\))?\s*\)\s*\]"#;

fn take_method_macro(item_fn: &mut ImplItemFn) -> syn::Result<Option<Attribute>> {
let mut index: Option<usize> = None;
let mut new_attr: Option<Attribute> = None;
let re = Regex::new(REGEX_STR).unwrap();
for (idx, attr) in &mut item_fn.attrs.iter().enumerate() {
if !(match attr.path().segments.last() {
Some(segment) => segment.ident == "craft",
None => false,
}) {
continue;
}
let re = Regex::new(REGEX_STR).unwrap();
let attr_str = attr.to_token_stream().to_string().trim().to_owned();
if let Some(caps) = re.captures(&attr_str) {
if let Some(name) = caps.name("name") {
Expand Down Expand Up @@ -176,9 +175,9 @@ mod tests {
let re = Regex::new(REGEX_STR).unwrap();

let texts = vec![
r###"#[craft(endpoint(responses((status_code = 400, description = "[(Wrong)] request parameters."))))]"###,
r###"#[craft(handler())]"###,
r###"#[craft(endpoint(simple_text))] "###,
r###"#[:: craft(endpoint(responses((status_code = 400, description = "[(Wrong)] request parameters."))))]"###,
r###"#[ xx ::craft(handler())]"###,
r###"#[::xx::craft(endpoint(simple_text))] "###,
r###"#[craft(handler)]"###,
];
for text in texts {
Expand Down

0 comments on commit d6e6988

Please sign in to comment.