1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SPDX-FileCopyrightText: 2022 Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>
// SPDX-FileCopyrightText: 2025 Knitli Inc. <knitli@knit.li>
// SPDX-FileContributor: Adam Poulemanos <adam@knit.li>
//
// SPDX-License-Identifier: AGPL-3.0-or-later AND MIT
//! # Text-Based Pattern Matching
//!
//! Provides regex-based matchers for finding AST nodes by their text content.
//! Useful when you need to match nodes based on their actual text rather
//! than their structural properties.
//!
//! ## Core Types
//!
//! - [`RegexMatcher`] - Matches nodes whose text content matches a regex pattern
//! - [`RegexMatcherError`] - Errors from invalid regex patterns
//!
//! ## Example Usage
//!
//! ```rust,ignore
//! // Find all nodes containing specific text patterns
//! let number_matcher = RegexMatcher::try_new(r"\d+")?; // Numbers
//! let email_matcher = RegexMatcher::try_new(r"[\w\.-]+@[\w\.-]+\.\w+")?; // Emails
//!
//! // Find all numeric literals
//! let numbers: Vec<_> = root.find_all(&number_matcher).collect();
//!
//! // Find specific variable names
//! let temp_vars = RegexMatcher::try_new(r"temp\w*")?;
//! let temp_variables: Vec<_> = root.find_all(&temp_vars).collect();
//! ```
//!
//! ## Use Cases
//!
//! Text matching complements structural patterns when you need to:
//! - Find nodes with specific naming patterns
//! - Locate hardcoded values or literals
//! - Search for code smells in text content
//! - Filter nodes by complex text criteria
use Matcher;
use crateDoc;
use crateNode;
use crateMetaVarEnv;
use BitSet;
use ;
use Error;
use Cow;
/// Errors that can occur when creating a [`RegexMatcher`].
/// 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
///
/// ```rust,ignore
/// // 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.