dcbor_pattern/pattern/
matcher.rs1use std::collections::HashMap;
2
3use dcbor::prelude::*;
4
5use crate::pattern::{Pattern, vm::Instr};
6
7pub type Path = Vec<CBOR>;
10
11#[doc(hidden)]
12pub trait Matcher: std::fmt::Debug + std::fmt::Display + Clone {
13    fn paths_with_captures(
15        &self,
16        _haystack: &CBOR,
17    ) -> (Vec<Path>, HashMap<String, Vec<Path>>) {
18        unimplemented!(
19            "Matcher::paths_with_captures not implemented for {:?}",
20            self
21        )
22    }
23
24    fn paths(&self, haystack: &CBOR) -> Vec<Path> {
26        self.paths_with_captures(haystack).0
27    }
28
29    fn matches(&self, haystack: &CBOR) -> bool { !self.paths(haystack).is_empty() }
30
31    fn compile(
32        &self,
33        _code: &mut Vec<Instr>,
34        _literals: &mut Vec<Pattern>,
35        _captures: &mut Vec<String>,
36    ) {
37        unimplemented!("Matcher::compile not implemented for {:?}", self);
38    }
39
40    fn collect_capture_names(&self, _names: &mut Vec<String>) {
42        }
45
46    fn is_complex(&self) -> bool { false }
51}