pub struct Pattern {
pub node: PatternNode,
pub strictness: MatchStrictness,
/* private fields */
}Expand description
Structural pattern for matching AST nodes based on their shape and content.
Patterns represent code structures with support for meta-variables (like $VAR)
that can capture parts of the matched code. They’re built from source code strings
and compiled into efficient matching structures.
§Example
ⓘ
// Pattern for variable declarations
let pattern = Pattern::new("let $NAME = $VALUE", language);
// Can match: "let x = 42", "let result = calculate()", etc.Fields§
§node: PatternNodeThe root pattern node containing the matching logic
strictness: MatchStrictnessHow strictly the pattern should match
Implementations§
Source§impl Pattern
impl Pattern
pub fn try_new<L: Language>(src: &str, lang: &L) -> Result<Self, PatternError>
pub fn new<L: Language>(src: &str, lang: &L) -> Self
pub const fn with_strictness(self, strictness: MatchStrictness) -> Self
pub fn contextual<L: Language>( context: &str, selector: &str, lang: &L, ) -> Result<Self, PatternError>
Trait Implementations§
Source§impl Matcher for Pattern
impl Matcher for Pattern
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 Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnsafeUnpin for Pattern
impl UnwindSafe for Pattern
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