grit_pattern_matcher/pattern/
bubble.rs

1use super::{
2    patterns::{Matcher, Pattern, PatternName},
3    PatternDefinition, State,
4};
5use crate::context::QueryContext;
6use grit_util::{error::GritResult, AnalysisLogs};
7
8#[derive(Debug, Clone)]
9pub struct Bubble<Q: QueryContext> {
10    pub pattern_def: PatternDefinition<Q>,
11    pub args: Vec<Option<Pattern<Q>>>,
12}
13
14impl<Q: QueryContext> Bubble<Q> {
15    pub fn new(pattern_def: PatternDefinition<Q>, args: Vec<Pattern<Q>>) -> Self {
16        Self {
17            pattern_def,
18            args: args.into_iter().map(Some).collect(),
19        }
20    }
21}
22
23impl<Q: QueryContext> PatternName for Bubble<Q> {
24    fn name(&self) -> &'static str {
25        "BUBBLE"
26    }
27}
28
29impl<Q: QueryContext> Matcher<Q> for Bubble<Q> {
30    fn execute<'a>(
31        &'a self,
32        binding: &Q::ResolvedPattern<'a>,
33        state: &mut State<'a, Q>,
34        context: &'a Q::ExecContext<'a>,
35        logs: &mut AnalysisLogs,
36    ) -> GritResult<bool> {
37        self.pattern_def
38            .call(state, binding, context, logs, &self.args)
39    }
40}