#[derive(Copy, Clone)]
pub struct Rule<K> {
kind: K,
matcher: fn(&str) -> Option<usize>,
}
impl<K> Rule<K> {
pub const fn new(kind: K, matcher: fn(&str) -> Option<usize>) -> Self {
Self { kind, matcher }
}
}
impl<K: Copy> Rule<K> {
pub(in crate::lexer) fn kind(&self) -> K {
self.kind
}
}
impl<K> Rule<K> {
pub(in crate::lexer) fn try_match(&self, source: &str) -> Option<usize> {
(self.matcher)(source)
}
}