Skip to content

Commit

Permalink
[skip ci] yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Mar 24, 2024
1 parent ebf27aa commit dd51d14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/pattern/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ fn implicit_metavariable_regex(
&text[last as usize..range.end_byte as usize],
));
}
let regex = format!("^{}$", regex_string);
let regex = RegexLike::Regex(Regex::new(regex.as_str())?);
let regex = format!("{}", regex_string);
let regex = RegexLike::Regex(regex);
Ok(Some(RegexPattern::new(regex, variables)))
}

Expand Down
25 changes: 14 additions & 11 deletions crates/core/src/pattern/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct RegexPattern {

#[derive(Debug, Clone)]
pub enum RegexLike {
Regex(Regex),
Regex(String),
Pattern(Box<Pattern>),
}

Expand Down Expand Up @@ -66,7 +66,7 @@ impl RegexPattern {
.strip_suffix('\"')
.ok_or_else(|| anyhow!("invalid regex postfix"))?;

RegexLike::Regex(Regex::new(regex)?)
RegexLike::Regex(regex.to_string())
} else {
let back_tick_node = regex_node
.child_by_field_name("snippet")
Expand Down Expand Up @@ -143,19 +143,22 @@ impl RegexPattern {
must_match_entire_string: bool,
) -> Result<bool> {
let text = binding.text(&state.files)?;
let resolved_regex = match self.regex {
RegexLike::Regex(ref regex) => regex.clone(),
let resolved_regex_text = match &self.regex {
RegexLike::Regex(regex) => match must_match_entire_string {
true => format!("^{}$", regex),
false => regex.to_string(),
},
RegexLike::Pattern(ref pattern) => {
let resolved = ResolvedPattern::from_pattern(pattern, state, context, logs)?;
let text = format!("{}", resolved.text(&state.files)?);
Regex::new(&text)?
let text = resolved.text(&state.files)?;
match must_match_entire_string {
true => format!("^{}$", text),
false => text.to_string(),
}
}
};
let wrapped_regex = match must_match_entire_string {
true => format!("^{}$", resolved_regex),
false => format!("{}", resolved_regex),
};
let captures = match resolved_regex.captures(&text) {
let final_regex = Regex::new(&resolved_regex_text)?;
let captures = match final_regex.captures(&text) {
Some(captures) => captures,
None => return Ok(false),
};
Expand Down

0 comments on commit dd51d14

Please sign in to comment.