Commit 1d271e8377

1d271e83770987f547ea03b67c84bb64c5dddef0

parent: 2a93b52e9f

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-06-27 12:58 UTC

config: Allow trailing commas in the declarative config definition.

Layout: unified · split

src/config.rs +17 −14
@@ -161,27 +161,27 @@ macro_rules! option_getter {
161161}
162162
163163macro_rules! option {
164 (String, $option_name:ident, $description:literal, $default:literal) => {
164 (String, $option_name:ident, $description:literal, $default:literal $(,)?) => {
165165 string_create!($option_name, $description, $default);
166166 option_getter!(String, $option_name, String);
167167 };
168168
169 (bool, $option_name:ident, $description:literal, $default:literal) => {
169 (bool, $option_name:ident, $description:literal, $default:literal $(,)?) => {
170170 bool_create!($option_name, $description, $default);
171171 option_getter!(Boolean, $option_name, bool);
172172 };
173173
174 (Integer, $option_name:ident, $description:literal, $default:literal, $min:literal..$max:literal) => {
174 (Integer, $option_name:ident, $description:literal, $default:literal, $min:literal..$max:literal $(,)?) => {
175175 integer_create!($option_name, $description, $default, $min, $max, []);
176176 option_getter!(Integer, $option_name, i64);
177177 };
178178
179 (Enum, $option_name:ident, $description:literal, $out_type:ty) => {
179 (Enum, $option_name:ident, $description:literal, $out_type:ty $(,)?) => {
180180 enum_create!($option_name, $description, $out_type);
181181 option_getter!(Integer, $option_name, $out_type);
182182 };
183183
184 (EvaluatedString, $option_name:ident, $description:literal, $default:literal) => {
184 (EvaluatedString, $option_name:ident, $description:literal, $default:literal $(,)?) => {
185185 string_create!($option_name, $description, $default);
186186
187187 paste::item! {
@@ -209,7 +209,7 @@ macro_rules! option {
209209}
210210
211211macro_rules! section {
212 ($section:ident { $($option_name:ident: $option_type:ident {$($option:tt)*}), * }) => {
212 ($section:ident { $($option_name:ident: $option_type:ident {$($option:tt)*}), * $(,)? }) => {
213213 paste::item! {
214214 pub struct [<$section:camel Section>]<'a>(SectionHandle<'a>);
215215
@@ -238,7 +238,7 @@ macro_rules! section {
238238}
239239
240240macro_rules! config {
241 ($(Section $section:ident { $($option:tt)* }), *) => {
241 ($(Section $section:ident { $($option:tt)* }), * $(,)?) => {
242242 pub struct Config(weechat::config::Config);
243243
244244 impl Deref for Config {
@@ -294,27 +294,30 @@ config!(
294294 Section look {
295295 encrypted_room_sign: String {
296296 "A sign that is used to show that the current room is encrypted",
297 "🔒"
297 "🔒",
298298 },
299
299300 what: EvaluatedString {
300301 "test",
301 "test2"
302 "test2",
302303 },
304
303305 int_test: Integer {
304306 "test",
305307 5,
306 0..10
308 0..10,
307309 },
310
308311 enum_test: Enum {
309312 "test",
310 Test
313 Test,
311314 },
312315
313316 bool_test: bool {
314317 "description",
315 false
316 }
317 }
318 false,
319 },
320 },
318321);
319322
320323impl ConfigHandle {