Skip to main content

veryl_parser/
token_collector.rs

1use crate::veryl_token::{Token, VerylToken};
2use crate::veryl_walker::VerylWalker;
3
4#[derive(Default)]
5pub struct TokenCollector {
6    pub tokens: Vec<Token>,
7    include_comments: bool,
8}
9
10impl TokenCollector {
11    pub fn new(include_comments: bool) -> Self {
12        Self {
13            tokens: Vec::new(),
14            include_comments,
15        }
16    }
17}
18
19impl VerylWalker for TokenCollector {
20    /// Semantic action for non-terminal 'VerylToken'
21    fn veryl_token(&mut self, arg: &VerylToken) {
22        self.tokens.push(arg.token);
23        if self.include_comments {
24            for x in &arg.comments {
25                self.tokens.push(*x);
26            }
27        }
28    }
29}