grit_pattern_matcher/pattern/
sequential.rs1use super::{
2 patterns::{Matcher, PatternName},
3 state::State,
4 step::Step,
5};
6use crate::context::QueryContext;
7use grit_util::{error::GritResult, AnalysisLogs};
8use std::ops;
9
10#[derive(Debug, Clone)]
11pub struct Sequential<Q: QueryContext>(pub Vec<Step<Q>>);
12
13impl<Q: QueryContext> Matcher<Q> for Sequential<Q> {
14 fn execute<'a>(
15 &'a self,
16 binding: &Q::ResolvedPattern<'a>,
17 state: &mut State<'a, Q>,
18 context: &'a Q::ExecContext<'a>,
19 logs: &mut AnalysisLogs,
20 ) -> GritResult<bool> {
21 for step in &self.0 {
22 if !step.execute(binding, state, context, logs)? {
23 return Ok(false);
24 }
25 }
26 Ok(true)
27 }
28}
29
30impl<Q: QueryContext> From<Vec<Step<Q>>> for Sequential<Q> {
31 fn from(logs: Vec<Step<Q>>) -> Self {
32 Self(logs)
33 }
34}
35
36impl<Q: QueryContext> ops::Deref for Sequential<Q> {
37 type Target = Vec<Step<Q>>;
38
39 fn deref(&self) -> &Self::Target {
40 &self.0
41 }
42}
43
44impl<Q: QueryContext> PatternName for Sequential<Q> {
45 fn name(&self) -> &'static str {
46 "SEQUENTIAL"
47 }
48}