start implementing edn loader; remove PhantomData from some tek_layout constructs

This commit is contained in:
🪞👃🪞 2025-01-03 22:50:58 +01:00
parent f359768ba2
commit 2b07e7963e
20 changed files with 239 additions and 222 deletions

View file

@ -7,3 +7,4 @@ version = "0.2.0"
crossterm = "0.28.1"
ratatui = { version = "0.29.0", features = [ "unstable-widget-ref", "underline-color" ] }
better-panic = "0.3.0"
clojure-reader = "0.3.0"

36
engine/src/edn.rs Normal file
View file

@ -0,0 +1,36 @@
use crate::*;
use std::sync::{Arc, RwLock};
use std::collections::BTreeMap;
pub use clojure_reader::edn::Edn;
/// EDN parsing helper.
#[macro_export] macro_rules! edn {
($edn:ident { $($pat:pat => $expr:expr),* $(,)? }) => {
match $edn { $($pat => $expr),* }
};
($edn:ident in $args:ident { $($pat:pat => $expr:expr),* $(,)? }) => {
for $edn in $args {
edn!($edn { $($pat => $expr),* })
}
};
}
pub trait FromEdn<C>: Sized {
const ID: &'static str;
fn from_edn (context: C, expr: &[Edn<'_>]) -> Usually<Self>;
}
/// Implements the [FromEdn] trait.
#[macro_export] macro_rules! from_edn {
($id:expr => |$context:tt:$Context:ty, $args:ident| -> $T:ty $body:block) => {
impl FromEdn<$Context> for $T {
const ID: &'static str = $id;
fn from_edn <'e> ($context: $Context, $args: &[Edn<'e>]) -> Usually<Self> {
$body
}
}
}
}

View file

@ -4,6 +4,7 @@ mod input; pub use self::input::*;
mod output; pub use self::output::*;
pub mod tui;
pub mod edn;
pub use std::error::Error;