simplify
This commit is contained in:
@@ -30,6 +30,25 @@ pub trait AstNode:
|
|||||||
fn syntax(&self) -> &SyntaxNode;
|
fn syntax(&self) -> &SyntaxNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AstChildren<'a, N> {
|
||||||
|
inner: SyntaxNodeChildren<'a>,
|
||||||
|
ph: PhantomData<N>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, N> AstChildren<'a, N> {
|
||||||
|
fn new(parent: &'a SyntaxNode) -> Self {
|
||||||
|
AstChildren { inner: parent.children(), ph: PhantomData }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
|
||||||
|
type Item = &'a N;
|
||||||
|
fn next(&mut self) -> Option<&'a N> {
|
||||||
|
self.inner.by_ref().find_map(N::cast)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Attr {
|
impl Attr {
|
||||||
pub fn is_inner(&self) -> bool {
|
pub fn is_inner(&self) -> bool {
|
||||||
let tt = match self.value() {
|
let tt = match self.value() {
|
||||||
@@ -331,29 +350,6 @@ fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> {
|
|||||||
AstChildren::new(parent.syntax())
|
AstChildren::new(parent.syntax())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AstChildren<'a, N> {
|
|
||||||
inner: SyntaxNodeChildren<'a>,
|
|
||||||
ph: PhantomData<N>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, N> AstChildren<'a, N> {
|
|
||||||
fn new(parent: &'a SyntaxNode) -> Self {
|
|
||||||
AstChildren { inner: parent.children(), ph: PhantomData }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
|
|
||||||
type Item = &'a N;
|
|
||||||
fn next(&mut self) -> Option<&'a N> {
|
|
||||||
loop {
|
|
||||||
if let Some(n) = N::cast(self.inner.next()?) {
|
|
||||||
return Some(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum StructFlavor<'a> {
|
pub enum StructFlavor<'a> {
|
||||||
Tuple(&'a PosFieldDefList),
|
Tuple(&'a PosFieldDefList),
|
||||||
|
|||||||
Reference in New Issue
Block a user