break down engine modules

This commit is contained in:
🪞👃🪞 2025-01-05 08:16:15 +01:00
parent f6c603bf73
commit 905486edbd
16 changed files with 376 additions and 352 deletions

View file

@ -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,

45
edn/src/edn_iter.rs Normal file
View file

@ -0,0 +1,45 @@
use crate::*;
pub enum EdnIterator<'a, T>{
Nil,
Sym(&'a T),
Exp(Vec<EdnIterator<'a, T>>)
}
impl<'a, T: AsRef<str>> EdnIterator<'a, T> {
pub 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
}
}
}
}

View file

@ -1,5 +1,3 @@
use crate::*;
#[macro_export] macro_rules! run_tek_edn {
($source:expr) => {
struct EdnRunner;

View file

@ -5,16 +5,13 @@ pub(crate) use std::{
fmt::{Debug, Formatter, Error as FormatError}
};
pub use ::tek_layout;
pub(crate) use ::tek_layout::{
*,
tek_engine::{Usually, Content, Render, Engine, Thunk}
};
mod edn_error; pub use self::edn_error::*;
mod edn_item; pub use self::edn_item::*;
mod edn_iter; pub use self::edn_iter::*;
mod edn_main; pub use self::edn_main::*;
mod edn_token; pub use self::edn_token::*;
mod edn_view; pub use self::edn_view::*;
mod edn_main; pub use self::edn_main::*;
#[cfg(test)] #[test] fn test_edn () -> Result<(), ParseError> {
use EdnItem::*;