use crate::nodes::Node;
use crate::plugins::Plugin;
use crate::state::*;
#[derive(Debug, PartialEq)]
pub struct WordCountPlugin {
pub words: usize,
}
impl WordCountPlugin {
pub fn new() -> Shared<Self> {
Shared::share(WordCountPlugin { words: 0 })
}
}
impl Plugin for WordCountPlugin {
fn on_node_parsed(&mut self, token: Node) -> Node {
if let Node::Word { .. } = token {
self.words += 1;
}
token
}
}