pub struct RegexMatcher { /* private fields */ }Expand description
Matcher that finds AST nodes based on regex patterns applied to their text content.
RegexMatcher enables flexible text-based searching within AST nodes.
It matches any node whose text content satisfies the provided regular expression.
§Examples
ⓘ
// Match numeric literals
let numbers = RegexMatcher::try_new(r"^\d+$")?;
let numeric_nodes: Vec<_> = root.find_all(&numbers).collect();
// Find TODO comments
let todos = RegexMatcher::try_new(r"(?i)todo|fixme")?;
let todo_comments: Vec<_> = root.find_all(&todos).collect();
// Match specific naming patterns
let private_vars = RegexMatcher::try_new(r"^_\w+")?;
let private_variables: Vec<_> = root.find_all(&private_vars).collect();§Performance Note
Text matching requires extracting text from every tested node, which can be slower than structural matching. Consider combining with other matchers or using more specific patterns when possible.
Implementations§
Source§impl RegexMatcher
impl RegexMatcher
pub fn try_new(text: &str) -> Result<Self, RegexMatcherError>
Trait Implementations§
Source§impl Clone for RegexMatcher
impl Clone for RegexMatcher
Source§fn clone(&self) -> RegexMatcher
fn clone(&self) -> RegexMatcher
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RegexMatcher
impl Debug for RegexMatcher
Source§impl Matcher for RegexMatcher
impl Matcher for RegexMatcher
Source§fn match_node_with_env<'tree, D: Doc>(
&self,
node: Node<'tree, D>,
_env: &mut Cow<'_, MetaVarEnv<'tree, D>>,
) -> Option<Node<'tree, D>>
fn match_node_with_env<'tree, D: Doc>( &self, node: Node<'tree, D>, _env: &mut Cow<'_, MetaVarEnv<'tree, D>>, ) -> Option<Node<'tree, D>>
Attempt to match a node, updating the meta-variable environment. Read more
Auto Trait Implementations§
impl Freeze for RegexMatcher
impl RefUnwindSafe for RegexMatcher
impl Send for RegexMatcher
impl Sync for RegexMatcher
impl Unpin for RegexMatcher
impl UnsafeUnpin for RegexMatcher
impl UnwindSafe for RegexMatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more