refactor(dsl): use traits instead of enums
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-07-20 03:19:24 +03:00
parent d72a3b5b8f
commit 73eb935282
6 changed files with 362 additions and 541 deletions

View file

@ -54,30 +54,20 @@ impl<E: Clone + Ord, C> EventMap<E, C> {
}
/// Create event map from string.
pub fn from_source (source: impl AsRef<str>) -> Usually<Self> where E: From<Arc<str>> {
Self::from_dsl(Cst::from(source.as_ref()))
Self::from_dsl(source.as_ref())
}
/// Create event map from DSL tokenizer.
pub fn from_dsl (mut dsl: impl Dsl) -> Usually<Self> where E: From<Arc<str>> {
use Val::*;
let mut map: Self = Default::default();
loop {
match dsl.exp_next().unwrap() {
Str(path) => {
map.0.extend(Self::from_path(PathBuf::from(path.as_ref() as &str))?.0)
},
Exp(_, e) => match e.head() {
Key(k) if k.as_ref() == "if" => {
todo!("conditional binding {:?}", dsl.tail());
},
Sym(s) => {
let key: Arc<str> = s.as_ref().into();
let key: E = key.into();
map.add(key, Binding::from_dsl(e)?);
todo!("binding {s:?} {:?}", dsl.tail());
},
_ => panic!(),
},
_ => panic!(),
while let Some(dsl) = dsl.exp_next()? {
if let Some(path) = dsl.text()? {
map.0.extend(Self::from_path(PathBuf::from(path.as_ref() as &str))?.0)
} else if dsl.exp_head()?.key()? == Some("if") {
todo!()
//map.add(sym.into(), Binding::from_dsl(dsl.exp_tail())?);
} else if let Some(sym) = dsl.exp_head()?.sym()? {
todo!()
//map.add(sym.into(), Binding::from_dsl(dsl.exp_tail())?);
}
}
Ok(map)