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
use crate::nodes::Block;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FunctionExpression {
block: Block,
parameters: Vec<String>,
is_variadic: bool,
}
impl FunctionExpression {
pub fn new(block: Block, parameters: Vec<String>, is_variadic: bool) -> Self {
Self {
block,
parameters,
is_variadic,
}
}
pub fn from_block<B: Into<Block>>(block: B) -> Self {
Self {
block: block.into(),
parameters: Vec::new(),
is_variadic: false,
}
}
pub fn with_parameter<S: Into<String>>(mut self, parameter: S) -> Self {
self.parameters.push(parameter.into());
self
}
pub fn variadic(mut self) -> Self {
self.is_variadic = true;
self
}
pub fn set_variadic(&mut self, is_variadic: bool) {
self.is_variadic = is_variadic;
}
#[inline]
pub fn get_block(&self) -> &Block {
&self.block
}
#[inline]
pub fn get_parameters(&self) -> &Vec<String> {
&self.parameters
}
#[inline]
pub fn is_variadic(&self) -> bool {
self.is_variadic
}
#[inline]
pub fn mutate_block(&mut self) -> &mut Block {
&mut self.block
}
#[inline]
pub fn mutate_parameters(&mut self) -> &mut Vec<String> {
&mut self.parameters
}
}
impl Default for FunctionExpression {
fn default() -> Self {
Self {
block: Block::default(),
parameters: Vec::new(),
is_variadic: false,
}
}
}