use super::pattern::Pattern;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScannerMode {
pub name: String,
pub patterns: Vec<Pattern>,
pub transitions: Vec<(usize, usize)>,
}
impl ScannerMode {
pub fn new<P, T>(name: &str, patterns: P, mode_transitions: T) -> Self
where
P: IntoIterator<Item = Pattern>,
T: IntoIterator<Item = (usize, usize)>,
{
let patterns = patterns.into_iter().collect::<Vec<_>>();
let transitions = mode_transitions.into_iter().collect::<Vec<_>>();
debug_assert!(
transitions.windows(2).all(|w| w[0].0 < w[1].0),
"Transitions are not sorted by token type number."
);
Self {
name: name.to_string(),
patterns,
transitions,
}
}
}