etch/plugins/
word_count.rs

1use crate::nodes::Node;
2use crate::plugins::Plugin;
3use crate::state::*;
4
5#[derive(Debug, PartialEq)]
6pub struct WordCountPlugin {
7    pub words: usize,
8}
9
10impl WordCountPlugin {
11    pub fn new() -> Shared<Self> {
12        Shared::share(WordCountPlugin { words: 0 })
13    }
14}
15
16impl Plugin for WordCountPlugin {
17    fn on_node_parsed(&mut self, token: Node) -> Node {
18        if let Node::Word { .. } = token {
19            self.words += 1;
20        }
21
22        token
23    }
24}