Skip to content

Commit 38e0f28

Browse files
committed
rust: multiple author/alias support in module!
Signed-off-by: Gary Guo <gary@garyguo.net>
1 parent 5598904 commit 38e0f28

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) -> Literal {
101113
assert_eq!(expect_ident(it), expected_name);
102114
assert_eq!(expect_punct(it), ':');
@@ -316,9 +328,9 @@ struct ModuleInfo {
316328
type_: String,
317329
license: String,
318330
name: String,
319-
author: Option<String>,
331+
author: Vec<String>,
320332
description: Option<String>,
321-
alias: Option<String>,
333+
alias: Vec<String>,
322334
params: Vec<ParamInfo>,
323335
}
324336

@@ -358,11 +370,16 @@ impl ModuleInfo {
358370
match key.as_str() {
359371
"type" => info.type_ = expect_ident(it),
360372
"name" => info.name = expect_string(it),
361-
"author" => info.author = Some(expect_string(it)),
373+
"author" => info.author = parse_item_or_list(it, Delimiter::Bracket, expect_string),
362374
"description" => info.description = Some(expect_string(it)),
363375
"license" => info.license = expect_string(it),
364-
"alias" => info.alias = Some(expect_string(it)),
365-
"alias_rtnl_link" => info.alias = Some(format!("rtnl-link-{}", expect_string(it))),
376+
"alias" => info.alias = parse_item_or_list(it, Delimiter::Bracket, expect_string),
377+
"alias_rtnl_link" => {
378+
info.alias = parse_item_or_list(it, Delimiter::Bracket, expect_string)
379+
.into_iter()
380+
.map(|x| format!("rtnl-link-{}", x))
381+
.collect()
382+
}
366383
"params" => info.params = parse_list(it, Delimiter::Brace, ParamInfo::parse),
367384
_ => panic!(
368385
"Unknown key \"{}\". Valid keys are: {:?}.",
@@ -402,10 +419,14 @@ impl ModuleInfo {
402419

403420
fn generate(&self) -> TokenStream {
404421
let mut modinfo = ModInfoBuilder::new(&self.name);
405-
modinfo.emit_optional("author", self.author.as_deref());
422+
for author in self.author.iter() {
423+
modinfo.emit("author", author);
424+
}
406425
modinfo.emit_optional("description", self.description.as_deref());
407426
modinfo.emit("license", &self.license);
408-
modinfo.emit_optional("alias", self.alias.as_deref());
427+
for alias in self.alias.iter() {
428+
modinfo.emit("alias", alias);
429+
}
409430

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

0 commit comments

Comments
 (0)