1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use crate::nodes::{Block, Expression, Identifier, Token};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GenericForTokens {
pub r#for: Token,
pub r#in: Token,
pub r#do: Token,
pub end: Token,
pub identifier_commas: Vec<Token>,
pub value_commas: Vec<Token>,
}
impl GenericForTokens {
pub fn clear_comments(&mut self) {
self.r#for.clear_comments();
self.r#in.clear_comments();
self.r#do.clear_comments();
self.end.clear_comments();
self.identifier_commas
.iter_mut()
.for_each(Token::clear_comments);
self.value_commas.iter_mut().for_each(Token::clear_comments);
}
pub fn clear_whitespaces(&mut self) {
self.r#for.clear_whitespaces();
self.r#in.clear_whitespaces();
self.r#do.clear_whitespaces();
self.end.clear_whitespaces();
self.identifier_commas
.iter_mut()
.for_each(Token::clear_whitespaces);
self.value_commas
.iter_mut()
.for_each(Token::clear_whitespaces);
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GenericForStatement {
identifiers: Vec<Identifier>,
expressions: Vec<Expression>,
block: Block,
tokens: Option<GenericForTokens>,
}
impl GenericForStatement {
pub fn new<B: Into<Block>>(
identifiers: Vec<Identifier>,
expressions: Vec<Expression>,
block: B,
) -> Self {
Self {
identifiers,
expressions,
block: block.into(),
tokens: None,
}
}
pub fn with_tokens(mut self, tokens: GenericForTokens) -> Self {
self.tokens = Some(tokens);
self
}
#[inline]
pub fn set_tokens(&mut self, tokens: GenericForTokens) {
self.tokens = Some(tokens);
}
#[inline]
pub fn get_tokens(&self) -> Option<&GenericForTokens> {
self.tokens.as_ref()
}
#[inline]
pub fn get_block(&self) -> &Block {
&self.block
}
#[inline]
pub fn get_identifiers(&self) -> &Vec<Identifier> {
&self.identifiers
}
#[inline]
pub fn iter_identifiers(&self) -> impl Iterator<Item = &Identifier> {
self.identifiers.iter()
}
#[inline]
pub fn get_expressions(&self) -> &Vec<Expression> {
&self.expressions
}
#[inline]
pub fn iter_expressions(&self) -> impl Iterator<Item = &Expression> {
self.expressions.iter()
}
#[inline]
pub fn iter_mut_identifiers(&mut self) -> impl Iterator<Item = &mut Identifier> {
self.identifiers.iter_mut()
}
#[inline]
pub fn iter_mut_expressions(&mut self) -> impl Iterator<Item = &mut Expression> {
self.expressions.iter_mut()
}
#[inline]
pub fn mutate_block(&mut self) -> &mut Block {
&mut self.block
}
#[inline]
pub fn identifiers_len(&self) -> usize {
self.identifiers.len()
}
#[inline]
pub fn expressions_len(&self) -> usize {
self.expressions.len()
}
pub fn clear_comments(&mut self) {
if let Some(tokens) = &mut self.tokens {
tokens.clear_comments();
}
}
pub fn clear_whitespaces(&mut self) {
if let Some(tokens) = &mut self.tokens {
tokens.clear_whitespaces();
}
}
}