darklua_core/nodes/
function_call.rs

1use crate::nodes::{Arguments, Expression, Identifier, Prefix, Token};
2
3#[derive(Clone, Debug, PartialEq, Eq)]
4pub struct FunctionCallTokens {
5    pub colon: Option<Token>,
6}
7
8impl FunctionCallTokens {
9    super::impl_token_fns!(iter = [colon]);
10}
11
12#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct FunctionCall {
14    prefix: Box<Prefix>,
15    arguments: Arguments,
16    method: Option<Identifier>,
17    tokens: Option<FunctionCallTokens>,
18}
19
20impl FunctionCall {
21    pub fn new(prefix: Prefix, arguments: Arguments, method: Option<Identifier>) -> Self {
22        Self {
23            prefix: Box::new(prefix),
24            arguments,
25            method,
26            tokens: None,
27        }
28    }
29
30    pub fn from_name<T: Into<Identifier>>(name: T) -> Self {
31        Self {
32            prefix: Box::new(name.into().into()),
33            arguments: Arguments::default(),
34            method: None,
35            tokens: None,
36        }
37    }
38
39    pub fn from_prefix<T: Into<Prefix>>(prefix: T) -> Self {
40        Self {
41            prefix: Box::new(prefix.into()),
42            arguments: Arguments::default(),
43            method: None,
44            tokens: None,
45        }
46    }
47
48    pub fn with_tokens(mut self, tokens: FunctionCallTokens) -> Self {
49        self.tokens = Some(tokens);
50        self
51    }
52
53    #[inline]
54    pub fn set_tokens(&mut self, tokens: FunctionCallTokens) {
55        self.tokens = Some(tokens);
56    }
57
58    #[inline]
59    pub fn get_tokens(&self) -> Option<&FunctionCallTokens> {
60        self.tokens.as_ref()
61    }
62
63    pub fn with_arguments<A: Into<Arguments>>(mut self, arguments: A) -> Self {
64        self.arguments = arguments.into();
65        self
66    }
67
68    pub fn with_argument<T: Into<Expression>>(mut self, argument: T) -> Self {
69        self.arguments = self.arguments.with_argument(argument);
70        self
71    }
72
73    pub fn with_method<IntoString: Into<Identifier>>(mut self, method: IntoString) -> Self {
74        self.method.replace(method.into());
75        self
76    }
77
78    #[inline]
79    pub fn get_arguments(&self) -> &Arguments {
80        &self.arguments
81    }
82
83    #[inline]
84    pub fn get_method(&self) -> Option<&Identifier> {
85        self.method.as_ref()
86    }
87
88    #[inline]
89    pub fn get_prefix(&self) -> &Prefix {
90        &self.prefix
91    }
92
93    #[inline]
94    pub fn take_method(&mut self) -> Option<Identifier> {
95        self.method.take()
96    }
97
98    #[inline]
99    pub fn set_arguments(&mut self, arguments: Arguments) {
100        self.arguments = arguments;
101    }
102
103    #[inline]
104    pub fn set_method(&mut self, method: Identifier) {
105        self.method.replace(method);
106    }
107
108    #[inline]
109    pub fn mutate_arguments(&mut self) -> &mut Arguments {
110        &mut self.arguments
111    }
112
113    #[inline]
114    pub fn mutate_prefix(&mut self) -> &mut Prefix {
115        &mut self.prefix
116    }
117
118    super::impl_token_fns!(iter = [tokens, method]);
119}