mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
wip: try to get a simplified parser going
This commit is contained in:
parent
fc82d6ff9b
commit
600d0b3aca
17 changed files with 676 additions and 133 deletions
118
edn/src/edn_layout.rs
Normal file
118
edn/src/edn_layout.rs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
use crate::*;
|
||||
|
||||
#[cfg(test)] #[test] fn test_edn_layout () -> Result<(), ParseError> {
|
||||
let source = include_str!("example.edn");
|
||||
let layout = Item::read_all(source)?;
|
||||
panic!("{layout:?}");
|
||||
let content = EdnLayout::from(&layout);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl<'a> From<&'a [Item]> for EdnLayout<'a> {
|
||||
fn from (items: &'a [Item]) -> Self {
|
||||
Self(items)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EdnLayout<'a, E>(&'a [Item]);
|
||||
impl<'a, E> EdnLayout<'a, E> {
|
||||
fn get_content (&self) -> impl Content<E> {
|
||||
}
|
||||
}
|
||||
|
||||
//pub struct EdnContent<'a, T>(T, &'a [Item]);
|
||||
|
||||
#[macro_export] macro_rules! edn_ns {
|
||||
($name:literal = $Host:ident<$E:ident: $Engine:path> |$args:ident| { $(
|
||||
($fn:literal
|
||||
$Struct:ident
|
||||
$(<$($G:ident$(: $Generic:ty)?),+>)?
|
||||
$(::$Variant:ident)?
|
||||
($($arg:expr),*))
|
||||
)* }) => {
|
||||
//pub trait $Host<$E: Engine> {
|
||||
//fn read_one <'e> (edn: &[Edn<'e>]) -> impl Content<$E> {
|
||||
//if let Some(Edn::Symbol(name)) = edn.get(0) {
|
||||
//match *name {
|
||||
//$(
|
||||
//$fn => $Struct$(::$Variant)?($($arg),+),
|
||||
//)*
|
||||
//_ => {}
|
||||
//}
|
||||
//} else {
|
||||
//panic!("invalid edn")
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
};
|
||||
}
|
||||
|
||||
edn_ns! {
|
||||
|
||||
"when" = When<A>(args[0].into(), args[1].into()),
|
||||
|
||||
"either" = Either<A, B>(args[0].into(), args[1].into(), args[2].into()),
|
||||
|
||||
"map" = Map<A, B, I, F, G>(args[0].into(), args[1].into()),
|
||||
|
||||
"fill" = edn_ns! {
|
||||
"x" = Fixed<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Fixed<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Fixed<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"fixed" = edn_ns! {
|
||||
"x" = Fixed<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Fixed<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Fixed<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"shrink" = edn_ns! {
|
||||
"x" = Shrink<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Shrink<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Shrink<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"expand" = edn_ns! {
|
||||
"x" = Expand<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Expand<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Expand<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"min" = edn_ns! {
|
||||
"x" = Min<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Min<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Min<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"max" = edn_ns! {
|
||||
"x" = Max<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Max<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Max<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"push" = edn_ns! {
|
||||
"x" = Push<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Push<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Push<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"pull" = edn_ns! {
|
||||
"x" = Pull<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Pull<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Pull<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"margin" = edn_ns! {
|
||||
"x" = Margin<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Margin<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Margin<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
"padding" = edn_ns! {
|
||||
"x" = Padding<T>::X(args[0].into(), args[1].into()),
|
||||
"y" = Padding<T>::Y(args[0].into(), args[1].into()),
|
||||
"xy" = Padding<T>::XY(args[0].into(), args[1].into(), args[2].into()),
|
||||
},
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue