grit_pattern_matcher/pattern/
string_constant.rs1use super::{
2 patterns::{Matcher, PatternName},
3 resolved_pattern::ResolvedPattern,
4 State,
5};
6use crate::context::{ExecContext, QueryContext};
7use core::fmt::Debug;
8use grit_util::{error::GritResult, AnalysisLogs};
9
10#[derive(Debug, Clone)]
11pub struct StringConstant {
12 pub text: String,
13}
14
15impl StringConstant {
16 pub fn new(text: String) -> Self {
17 Self { text }
18 }
19}
20
21impl PatternName for StringConstant {
22 fn name(&self) -> &'static str {
23 "STRING_CONSTANT"
24 }
25}
26
27impl<Q: QueryContext> Matcher<Q> for StringConstant {
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 let text = binding.text(&state.files, context.language())?;
38 if text == self.text {
39 Ok(true)
40 } else {
41 Ok(false)
42 }
43 }
44}