2022-03-11 14:48:51 -06:00
|
|
|
//@ run-pass
|
|
|
|
|
|
|
|
#![feature(macro_metavar_expr)]
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Example<'a> {
|
|
|
|
_indexes: &'a [(u32, u32)],
|
|
|
|
_counts: &'a [u32],
|
|
|
|
_nested: Vec<Example<'a>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! example {
|
|
|
|
( $( [ $( ( $( $x:ident )* ) )* ] )* ) => {
|
|
|
|
Example {
|
|
|
|
_indexes: &[],
|
2023-12-01 18:19:22 -06:00
|
|
|
_counts: &[${count($x, 0)}, ${count($x, 1)}, ${count($x, 2)}],
|
2022-03-11 14:48:51 -06:00
|
|
|
_nested: vec![
|
|
|
|
$(
|
|
|
|
Example {
|
2024-05-10 14:12:39 -05:00
|
|
|
_indexes: &[(${index()}, ${len()})],
|
2023-12-01 18:19:22 -06:00
|
|
|
_counts: &[${count($x, 0)}, ${count($x, 1)}],
|
2022-03-11 14:48:51 -06:00
|
|
|
_nested: vec![
|
|
|
|
$(
|
|
|
|
Example {
|
2024-05-10 14:12:39 -05:00
|
|
|
_indexes: &[(${index(1)}, ${len(1)}), (${index()}, ${len()})],
|
2023-12-01 18:19:22 -06:00
|
|
|
_counts: &[${count($x)}],
|
2022-03-11 14:48:51 -06:00
|
|
|
_nested: vec![
|
|
|
|
$(
|
|
|
|
Example {
|
|
|
|
_indexes: &[
|
2024-05-10 14:12:39 -05:00
|
|
|
(${index(2)}, ${len(2)}),
|
|
|
|
(${index(1)}, ${len(1)}),
|
|
|
|
(${index()}, ${len()})
|
2022-03-11 14:48:51 -06:00
|
|
|
],
|
|
|
|
_counts: &[],
|
|
|
|
_nested: vec![],
|
2023-12-01 18:19:22 -06:00
|
|
|
${ignore($x)}
|
2022-03-11 14:48:51 -06:00
|
|
|
}
|
|
|
|
),*
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),*
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),*
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static EXPECTED: &str = concat!(
|
2023-12-01 18:19:22 -06:00
|
|
|
"Example { _indexes: [], _counts: [13, 4, 2], _nested: [",
|
2022-03-11 14:48:51 -06:00
|
|
|
concat!(
|
2023-12-01 18:19:22 -06:00
|
|
|
"Example { _indexes: [(0, 2)], _counts: [10, 3], _nested: [",
|
2022-03-11 14:48:51 -06:00
|
|
|
concat!(
|
|
|
|
"Example { _indexes: [(0, 2), (0, 3)], _counts: [4], _nested: [",
|
|
|
|
concat!(
|
|
|
|
"Example { _indexes: [(0, 2), (0, 3), (0, 4)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (0, 3), (1, 4)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (0, 3), (2, 4)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (0, 3), (3, 4)], _counts: [], _nested: [] }",
|
|
|
|
),
|
|
|
|
"] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (1, 3)], _counts: [4], _nested: [",
|
|
|
|
concat!(
|
|
|
|
"Example { _indexes: [(0, 2), (1, 3), (0, 4)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (1, 3), (1, 4)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (1, 3), (2, 4)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (1, 3), (3, 4)], _counts: [], _nested: [] }",
|
|
|
|
),
|
|
|
|
"] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (2, 3)], _counts: [2], _nested: [",
|
|
|
|
concat!(
|
|
|
|
"Example { _indexes: [(0, 2), (2, 3), (0, 2)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(0, 2), (2, 3), (1, 2)], _counts: [], _nested: [] }",
|
|
|
|
),
|
|
|
|
"] }",
|
|
|
|
),
|
|
|
|
"] }, ",
|
2023-12-01 18:19:22 -06:00
|
|
|
"Example { _indexes: [(1, 2)], _counts: [3, 1], _nested: [",
|
2022-03-11 14:48:51 -06:00
|
|
|
concat!(
|
|
|
|
"Example { _indexes: [(1, 2), (0, 1)], _counts: [3], _nested: [",
|
|
|
|
concat!(
|
|
|
|
"Example { _indexes: [(1, 2), (0, 1), (0, 3)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(1, 2), (0, 1), (1, 3)], _counts: [], _nested: [] }, ",
|
|
|
|
"Example { _indexes: [(1, 2), (0, 1), (2, 3)], _counts: [], _nested: [] }",
|
|
|
|
),
|
|
|
|
"] }",
|
|
|
|
),
|
|
|
|
"] }",
|
|
|
|
),
|
|
|
|
"] }",
|
|
|
|
);
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let e = example! {
|
|
|
|
[ ( A B C D ) ( E F G H ) ( I J ) ]
|
|
|
|
[ ( K L M ) ]
|
|
|
|
};
|
|
|
|
let debug = format!("{:?}", e);
|
|
|
|
assert_eq!(debug, EXPECTED);
|
|
|
|
}
|