Introduce a macro for empty iterators.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/// Create iterators for ast nodes where it only has to iterate over children
|
||||
macro_rules! simple_iter {
|
||||
macro_rules! children_iter {
|
||||
($astnodetype:ty, $itertype:ident, $innertype:ty) => {
|
||||
pub struct $itertype<'r, 's> {
|
||||
next: $innertype,
|
||||
@@ -27,4 +27,35 @@ macro_rules! simple_iter {
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use simple_iter;
|
||||
pub(crate) use children_iter;
|
||||
|
||||
/// Create iterators for ast nodes that do not contain any ast node children.
|
||||
macro_rules! empty_iter {
|
||||
($astnodetype:ty, $itertype:ident) => {
|
||||
pub struct $itertype<'r, 's> {
|
||||
phantom: PhantomData<&'r $astnodetype>,
|
||||
}
|
||||
|
||||
impl<'r, 's> Iterator for $itertype<'r, 's> {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, 's> IntoIterator for &'r $astnodetype {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
type IntoIter = $itertype<'r, 's>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
$itertype {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use empty_iter;
|
||||
|
||||
Reference in New Issue
Block a user