grit_pattern_matcher/pattern/
bubble.rs

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
use super::{
    patterns::{Matcher, Pattern, PatternName},
    PatternDefinition, State,
};
use crate::context::QueryContext;
use grit_util::{error::GritResult, AnalysisLogs};

#[derive(Debug, Clone)]
pub struct Bubble<Q: QueryContext> {
    pub pattern_def: PatternDefinition<Q>,
    pub args: Vec<Option<Pattern<Q>>>,
}

impl<Q: QueryContext> Bubble<Q> {
    pub fn new(pattern_def: PatternDefinition<Q>, args: Vec<Pattern<Q>>) -> Self {
        Self {
            pattern_def,
            args: args.into_iter().map(Some).collect(),
        }
    }
}

impl<Q: QueryContext> PatternName for Bubble<Q> {
    fn name(&self) -> &'static str {
        "BUBBLE"
    }
}

impl<Q: QueryContext> Matcher<Q> for Bubble<Q> {
    fn execute<'a>(
        &'a self,
        binding: &Q::ResolvedPattern<'a>,
        state: &mut State<'a, Q>,
        context: &'a Q::ExecContext<'a>,
        logs: &mut AnalysisLogs,
    ) -> GritResult<bool> {
        self.pattern_def
            .call(state, binding, context, logs, &self.args)
    }
}