Skip to content

Commit 8f9f074

Browse files
committed
rust: multiple author/alias support in module!
Signed-off-by: Gary Guo <[email protected]>
1 parent bb190f4 commit 8f9f074

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

rust/macros/module.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ fn parse_list<T>(
9797
vec
9898
}
9999

100+
fn parse_item_or_list<T>(
101+
it: &mut Cursor<'_>,
102+
delim: Delimiter,
103+
f: impl Fn(&mut Cursor<'_>) -> T,
104+
) -> Vec<T> {
105+
if it.group(delim).is_some() {
106+
parse_list(it, delim, f)
107+
} else {
108+
vec![f(it)]
109+
}
110+
}
111+
100112
fn get_literal(it: &mut Cursor<'_>, expected_name: &str) -> String {
101113
assert_eq!(expect_ident(it), expected_name);
102114
assert_eq!(expect_punct(it), ':');
@@ -325,9 +337,9 @@ struct ModuleInfo {
325337
type_: String,
326338
license: String,
327339
name: String,
328-
author: Option<String>,
340+
author: Vec<String>,
329341
description: Option<String>,
330-
alias: Option<String>,
342+
alias: Vec<String>,
331343
params: Vec<ParamInfo>,
332344
}
333345

@@ -367,11 +379,16 @@ impl ModuleInfo {
367379
match key.as_str() {
368380
"type" => info.type_ = expect_ident(it),
369381
"name" => info.name = expect_string(it),
370-
"author" => info.author = Some(expect_string(it)),
382+
"author" => info.author = parse_item_or_list(it, Delimiter::Bracket, expect_string),
371383
"description" => info.description = Some(expect_string(it)),
372384
"license" => info.license = expect_string(it),
373-
"alias" => info.alias = Some(expect_string(it)),
374-
"alias_rtnl_link" => info.alias = Some(format!("rtnl-link-{}", expect_string(it))),
385+
"alias" => info.alias = parse_item_or_list(it, Delimiter::Bracket, expect_string),
386+
"alias_rtnl_link" => {
387+
info.alias = parse_item_or_list(it, Delimiter::Bracket, expect_string)
388+
.into_iter()
389+
.map(|x| format!("rtnl-link-{}", x))
390+
.collect()
391+
}
375392
"params" => info.params = parse_list(it, Delimiter::Brace, ParamInfo::parse),
376393
_ => panic!(
377394
"Unknown key \"{}\". Valid keys are: {:?}.",
@@ -411,10 +428,14 @@ impl ModuleInfo {
411428

412429
fn generate(&self) -> TokenStream {
413430
let mut modinfo = ModInfoBuilder::new(&self.name);
414-
modinfo.emit_optional("author", self.author.as_deref());
431+
for author in self.author.iter() {
432+
modinfo.emit("author", author);
433+
}
415434
modinfo.emit_optional("description", self.description.as_deref());
416435
modinfo.emit("license", &self.license);
417-
modinfo.emit_optional("alias", self.alias.as_deref());
436+
for alias in self.alias.iter() {
437+
modinfo.emit("alias", alias);
438+
}
418439

419440
// Built-in modules also export the `file` modinfo string
420441
let file = std::env::var("RUST_MODFILE")

0 commit comments

Comments
 (0)