diff --git a/src/ast/any_node.rs b/src/ast/any_node.rs index f11655e..a4bc539 100644 --- a/src/ast/any_node.rs +++ b/src/ast/any_node.rs @@ -1,10 +1,34 @@ use crate::ast::*; use crate::parser::*; +// ----------------------------------------------------------------------------- + include!(concat!(env!("OUT_DIR"), "/any_node.rs")); pub struct AnyNodes<'a>(pub Vec>); +// ----------------------------------------------------------------------------- + +pub struct Iter<'a> { + pub next: AnyNodes<'a>, +} + +impl<'a> Iterator for Iter<'a> { + type Item = AnyNode<'a>; + + fn next(&mut self) -> Option { + let ret = self.next.0.pop(); + if let Some(x) = ret.clone() { + let mut x = x.next(); + x.0.reverse(); + self.next.0.append(&mut x.0); + } + ret + } +} + +// ----------------------------------------------------------------------------- + impl<'a> From>> for AnyNodes<'a> { fn from(x: Vec>) -> Self { AnyNodes(x) @@ -91,20 +115,81 @@ where } } -pub struct Iter<'a> { - pub next: AnyNodes<'a>, -} - -impl<'a> Iterator for Iter<'a> { - type Item = AnyNode<'a>; - - fn next(&mut self) -> Option { - let ret = self.next.0.pop(); - if let Some(x) = ret.clone() { - let mut x = x.next(); - x.0.reverse(); - self.next.0.append(&mut x.0); - } - ret +impl<'a, T> From<&'a Paren<'a, T>> for AnyNodes<'a> +where + &'a T: Into>, +{ + fn from(x: &'a Paren<'a, T>) -> Self { + let mut ret = Vec::new(); + let (a, b, c) = &x.nodes; + let mut a: AnyNodes<'a> = a.into(); + let mut c: AnyNodes<'a> = c.into(); + ret.append(&mut a.0); + ret.append(&mut b.into().0); + ret.append(&mut c.0); + ret.into() + } +} + +impl<'a, T> From<&'a Brace<'a, T>> for AnyNodes<'a> +where + &'a T: Into>, +{ + fn from(x: &'a Brace<'a, T>) -> Self { + let mut ret = Vec::new(); + let (a, b, c) = &x.nodes; + let mut a: AnyNodes<'a> = a.into(); + let mut c: AnyNodes<'a> = c.into(); + ret.append(&mut a.0); + ret.append(&mut b.into().0); + ret.append(&mut c.0); + ret.into() + } +} + +impl<'a, T> From<&'a Bracket<'a, T>> for AnyNodes<'a> +where + &'a T: Into>, +{ + fn from(x: &'a Bracket<'a, T>) -> Self { + let mut ret = Vec::new(); + let (a, b, c) = &x.nodes; + let mut a: AnyNodes<'a> = a.into(); + let mut c: AnyNodes<'a> = c.into(); + ret.append(&mut a.0); + ret.append(&mut b.into().0); + ret.append(&mut c.0); + ret.into() + } +} + +impl<'a, T> From<&'a ApostropheBrace<'a, T>> for AnyNodes<'a> +where + &'a T: Into>, +{ + fn from(x: &'a ApostropheBrace<'a, T>) -> Self { + let mut ret = Vec::new(); + let (a, b, c) = &x.nodes; + let mut a: AnyNodes<'a> = a.into(); + let mut c: AnyNodes<'a> = c.into(); + ret.append(&mut a.0); + ret.append(&mut b.into().0); + ret.append(&mut c.0); + ret.into() + } +} + +impl<'a, T, U> From<&'a List> for AnyNodes<'a> +where + &'a T: Into>, + &'a U: Into>, +{ + fn from(x: &'a List) -> Self { + let mut ret = Vec::new(); + let (t, u) = &x.nodes; + let mut u: AnyNodes<'a> = u.into(); + ret.append(&mut t.into().0); + ret.append(&mut u.0); + ret.into() } } diff --git a/src/parser/expressions/expressions.rs b/src/parser/expressions/expressions.rs index 38789eb..00c14ba 100644 --- a/src/parser/expressions/expressions.rs +++ b/src/parser/expressions/expressions.rs @@ -1,3 +1,4 @@ +use crate::ast::*; use crate::parser::*; use nom::branch::*; use nom::combinator::*; diff --git a/src/parser/general/attributes.rs b/src/parser/general/attributes.rs index a9e65cf..1a5cd65 100644 --- a/src/parser/general/attributes.rs +++ b/src/parser/general/attributes.rs @@ -1,3 +1,4 @@ +use crate::ast::*; use crate::parser::*; use nom::combinator::*; use nom::sequence::*; diff --git a/src/parser/general/identifiers.rs b/src/parser/general/identifiers.rs index 688399c..26803d3 100644 --- a/src/parser/general/identifiers.rs +++ b/src/parser/general/identifiers.rs @@ -1,3 +1,4 @@ +use crate::ast::*; use crate::parser::*; use nom::branch::*; use nom::bytes::complete::*; diff --git a/src/parser/utils.rs b/src/parser/utils.rs index daa8521..bf3524e 100644 --- a/src/parser/utils.rs +++ b/src/parser/utils.rs @@ -42,8 +42,8 @@ pub struct ApostropheBrace<'a, T: 'a> { } #[derive(Debug)] -pub struct List { - pub nodes: (T, Vec<(U, T)>), +pub struct List { + pub nodes: (U, Vec<(T, U)>), } // -----------------------------------------------------------------------------