|
1 | 1 | // SPDX-License-Identifier: GPL-2.0
|
2 | 2 |
|
3 | 3 | use crate::helpers::*;
|
4 |
| -use proc_macro::{token_stream, Literal, TokenStream, TokenTree}; |
| 4 | +use proc_macro::{token_stream, Delimiter, Literal, TokenStream, TokenTree}; |
5 | 5 | use std::fmt::Write;
|
6 | 6 |
|
| 7 | +fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> { |
| 8 | + let group = expect_group(it); |
| 9 | + assert_eq!(group.delimiter(), Delimiter::Bracket); |
| 10 | + let mut values = Vec::new(); |
| 11 | + let mut it = group.stream().into_iter(); |
| 12 | + |
| 13 | + while let Some(val) = try_string(&mut it) { |
| 14 | + assert!(val.is_ascii(), "Expected ASCII string"); |
| 15 | + values.push(val); |
| 16 | + match it.next() { |
| 17 | + Some(TokenTree::Punct(punct)) => assert_eq!(punct.as_char(), ','), |
| 18 | + None => break, |
| 19 | + _ => panic!("Expected ',' or end of array"), |
| 20 | + } |
| 21 | + } |
| 22 | + values |
| 23 | +} |
| 24 | + |
7 | 25 | struct ModInfoBuilder<'a> {
|
8 | 26 | module: &'a str,
|
9 | 27 | counter: usize,
|
@@ -78,7 +96,7 @@ struct ModuleInfo {
|
78 | 96 | name: String,
|
79 | 97 | author: Option<String>,
|
80 | 98 | description: Option<String>,
|
81 |
| - alias: Option<String>, |
| 99 | + alias: Option<Vec<String>>, |
82 | 100 | }
|
83 | 101 |
|
84 | 102 | impl ModuleInfo {
|
@@ -112,7 +130,7 @@ impl ModuleInfo {
|
112 | 130 | "author" => info.author = Some(expect_string(it)),
|
113 | 131 | "description" => info.description = Some(expect_string(it)),
|
114 | 132 | "license" => info.license = expect_string_ascii(it),
|
115 |
| - "alias" => info.alias = Some(expect_string_ascii(it)), |
| 133 | + "alias" => info.alias = Some(expect_string_array(it)), |
116 | 134 | _ => panic!(
|
117 | 135 | "Unknown key \"{}\". Valid keys are: {:?}.",
|
118 | 136 | key, EXPECTED_KEYS
|
@@ -163,8 +181,10 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
|
163 | 181 | modinfo.emit("description", &description);
|
164 | 182 | }
|
165 | 183 | modinfo.emit("license", &info.license);
|
166 |
| - if let Some(alias) = info.alias { |
167 |
| - modinfo.emit("alias", &alias); |
| 184 | + if let Some(aliases) = info.alias { |
| 185 | + for alias in aliases { |
| 186 | + modinfo.emit("alias", &alias); |
| 187 | + } |
168 | 188 | }
|
169 | 189 |
|
170 | 190 | // Built-in modules also export the `file` modinfo string.
|
|
0 commit comments