grit_pattern_matcher/pattern/
ast_node_pattern.rs

1use super::{
2    iter_pattern::PatternOrPredicate,
3    patterns::{Matcher, PatternName},
4};
5use crate::context::{QueryContext, StaticDefinitions};
6
7/// Type of pattern that matches against an individual (non-leaf) AST node.
8pub trait AstNodePattern<Q: QueryContext>:
9    Clone + std::fmt::Debug + Matcher<Q> + PatternName + Sized
10{
11    /// Does this AST include trivia?
12    /// Trivia is useful for being able to re-print an AST, but not all parsers support collecting it.
13    const INCLUDES_TRIVIA: bool;
14
15    fn children<'a>(
16        &'a self,
17        definitions: &'a StaticDefinitions<Q>,
18    ) -> Vec<PatternOrPredicate<'a, Q>>;
19
20    fn matches_kind_of(&self, node: &Q::Node<'_>) -> bool;
21}
22
23/// Type of pattern that matches against an individual AST leaf node.
24pub trait AstLeafNodePattern<Q: QueryContext>:
25    Clone + std::fmt::Debug + Matcher<Q> + PatternName + Sized
26{
27    /// Provides a *possible* text value for the leaf node.
28    /// This is not mandatory, but enables some advanced functionality.
29    fn text(&self) -> Option<&str> {
30        None
31    }
32}