mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
break down engine modules
This commit is contained in:
parent
f6c603bf73
commit
905486edbd
16 changed files with 376 additions and 352 deletions
|
|
@ -55,52 +55,8 @@ impl<T: AsRef<str> + PartialEq + Default + Clone + std::fmt::Debug> EdnItem<T> {
|
|||
EdnIterator::new(&self)
|
||||
}
|
||||
}
|
||||
enum EdnIterator<'a, T>{
|
||||
Nil,
|
||||
Sym(&'a T),
|
||||
Exp(Vec<EdnIterator<'a, T>>)
|
||||
}
|
||||
impl<'a, T: AsRef<str>> EdnIterator<'a, T> {
|
||||
fn new (item: &'a EdnItem<T>) -> Self {
|
||||
use EdnItem::*;
|
||||
match item {
|
||||
Sym(t) => Self::Sym(t),
|
||||
Exp(i) => Self::Exp(i.iter().map(EdnIterator::new).collect()),
|
||||
_ => Self::Nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a, T: AsRef<str>> Iterator for EdnIterator<'a, T> {
|
||||
type Item = &'a T;
|
||||
fn next (&mut self) -> Option<Self::Item> {
|
||||
use EdnIterator::*;
|
||||
match self {
|
||||
Sym(t) => {
|
||||
let t = *t;
|
||||
*self = Nil;
|
||||
Some(t)
|
||||
},
|
||||
Exp(v) => match v.as_mut_slice() {
|
||||
[a] => if let Some(next) = a.next() {
|
||||
Some(next)
|
||||
} else {
|
||||
*self = Exp(v.split_off(1));
|
||||
self.next()
|
||||
},
|
||||
_ => {
|
||||
*self = Nil;
|
||||
None
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
*self = Nil;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl EdnItem<String> {
|
||||
fn from (other: EdnItem<impl AsRef<str>>) -> EdnItem<String> {
|
||||
pub fn from (other: EdnItem<impl AsRef<str>>) -> EdnItem<String> {
|
||||
use EdnItem::*;
|
||||
match other {
|
||||
Nil => Nil,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue