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
use crate::tokenizer::TokenReference;
use std::{borrow::Borrow, fmt::Display};
use crate::ast::punctuated::Punctuated;
use std::fmt::Write;
pub fn display_option<T: Display, O: Borrow<Option<T>>>(option: O) -> String {
match option.borrow() {
Some(x) => x.to_string(),
None => "".to_string(),
}
}
pub fn display_optional_punctuated<T: Display>(pair: &(T, Option<TokenReference>)) -> String {
format!("{}{}", pair.0, display_option(&pair.1))
}
pub fn display_optional_punctuated_vec<T: Display>(vec: &[(T, Option<TokenReference>)]) -> String {
let mut string = String::new();
for pair in vec {
string.push_str(&display_optional_punctuated(pair));
}
string
}
pub fn join_vec<T: Display, V: AsRef<[T]>>(vec: V) -> String {
let mut string = String::new();
for item in vec.as_ref() {
string.push_str(&item.to_string());
}
string
}
#[cfg(feature = "roblox")]
pub fn join_type_specifiers<I: IntoIterator<Item = Option<T2>>, T1: Display, T2: Display>(
parameters: &Punctuated<T1>,
type_specifiers: I,
) -> String {
let mut string = String::new();
for (parameter, type_specifier) in parameters.pairs().zip(
type_specifiers
.into_iter()
.chain(std::iter::repeat_with(|| None)),
) {
let _ = write!(
string,
"{}{}{}",
parameter.value(),
display_option(type_specifier),
display_option(parameter.punctuation())
);
}
string
}
pub fn join_iterators<
I1: IntoIterator<Item = Option<T2>>,
I2: IntoIterator<Item = Option<T3>>,
T1: Display,
T2: Display,
T3: Display,
>(
parameters: &Punctuated<T1>,
first_iterator: I1,
second_iterator: I2,
) -> String {
let mut string = String::new();
for ((name, item1), item2) in parameters
.pairs()
.zip(first_iterator.into_iter())
.zip(second_iterator.into_iter())
{
let _ = write!(
string,
"{}{}{}{}",
name.value(),
display_option(item1),
display_option(item2),
display_option(name.punctuation())
);
}
string
}