Impl From
This commit is contained in:
parent
69e6c35103
commit
c84ba8638b
@ -1,10 +1,34 @@
|
|||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/any_node.rs"));
|
include!(concat!(env!("OUT_DIR"), "/any_node.rs"));
|
||||||
|
|
||||||
pub struct AnyNodes<'a>(pub Vec<AnyNode<'a>>);
|
pub struct AnyNodes<'a>(pub Vec<AnyNode<'a>>);
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
pub struct Iter<'a> {
|
||||||
|
pub next: AnyNodes<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for Iter<'a> {
|
||||||
|
type Item = AnyNode<'a>;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
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<Vec<AnyNode<'a>>> for AnyNodes<'a> {
|
impl<'a> From<Vec<AnyNode<'a>>> for AnyNodes<'a> {
|
||||||
fn from(x: Vec<AnyNode<'a>>) -> Self {
|
fn from(x: Vec<AnyNode<'a>>) -> Self {
|
||||||
AnyNodes(x)
|
AnyNodes(x)
|
||||||
@ -91,20 +115,81 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Iter<'a> {
|
impl<'a, T> From<&'a Paren<'a, T>> for AnyNodes<'a>
|
||||||
pub next: AnyNodes<'a>,
|
where
|
||||||
|
&'a T: Into<AnyNodes<'a>>,
|
||||||
|
{
|
||||||
|
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> Iterator for Iter<'a> {
|
impl<'a, T> From<&'a Brace<'a, T>> for AnyNodes<'a>
|
||||||
type Item = AnyNode<'a>;
|
where
|
||||||
|
&'a T: Into<AnyNodes<'a>>,
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
impl<'a, T> From<&'a Bracket<'a, T>> for AnyNodes<'a>
|
||||||
let ret = self.next.0.pop();
|
where
|
||||||
if let Some(x) = ret.clone() {
|
&'a T: Into<AnyNodes<'a>>,
|
||||||
let mut x = x.next();
|
{
|
||||||
x.0.reverse();
|
fn from(x: &'a Bracket<'a, T>) -> Self {
|
||||||
self.next.0.append(&mut x.0);
|
let mut ret = Vec::new();
|
||||||
}
|
let (a, b, c) = &x.nodes;
|
||||||
ret
|
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<AnyNodes<'a>>,
|
||||||
|
{
|
||||||
|
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<T, U>> for AnyNodes<'a>
|
||||||
|
where
|
||||||
|
&'a T: Into<AnyNodes<'a>>,
|
||||||
|
&'a U: Into<AnyNodes<'a>>,
|
||||||
|
{
|
||||||
|
fn from(x: &'a List<T, U>) -> 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
use nom::branch::*;
|
use nom::branch::*;
|
||||||
use nom::combinator::*;
|
use nom::combinator::*;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
use nom::combinator::*;
|
use nom::combinator::*;
|
||||||
use nom::sequence::*;
|
use nom::sequence::*;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
use nom::branch::*;
|
use nom::branch::*;
|
||||||
use nom::bytes::complete::*;
|
use nom::bytes::complete::*;
|
||||||
|
@ -42,8 +42,8 @@ pub struct ApostropheBrace<'a, T: 'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct List<U, T> {
|
pub struct List<T, U> {
|
||||||
pub nodes: (T, Vec<(U, T)>),
|
pub nodes: (U, Vec<(T, U)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user