use std::collections::HashMap;
use bc_envelope::prelude::*;
use crate::pattern::{Pattern, vm::Instr};
pub type Path = Vec<Envelope>;
#[doc(hidden)]
pub trait Matcher: std::fmt::Debug + std::fmt::Display + Clone {
fn paths_with_captures(
&self,
_haystack: &Envelope,
) -> (Vec<Path>, HashMap<String, Vec<Path>>);
fn paths(&self, haystack: &Envelope) -> Vec<Path> {
self.paths_with_captures(haystack).0
}
fn matches(&self, haystack: &Envelope) -> bool {
!self.paths(haystack).is_empty()
}
fn compile(
&self,
_code: &mut Vec<Instr>,
_literals: &mut Vec<Pattern>,
_captures: &mut Vec<String>,
) {
unimplemented!("Matcher::compile not implemented for {:?}", self);
}
fn is_complex(&self) -> bool { false }
}
pub fn compile_as_atomic(
pat: &Pattern,
code: &mut Vec<Instr>,
lits: &mut Vec<Pattern>,
_captures: &mut Vec<String>,
) {
let _ = _captures;
let idx = lits.len();
lits.push(pat.clone());
code.push(Instr::MatchPredicate(idx));
}