mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
This commit is contained in:
parent
d99b20c99d
commit
a145e332de
2 changed files with 239 additions and 243 deletions
|
|
@ -30,37 +30,34 @@ impl<'s, I: Debug + Ord, D: Dsl + From<Cst<'s>>> InputMap<I, D> {
|
|||
Self::from_source(read_and_leak(path)?)
|
||||
}
|
||||
/// Create input layer collection from string.
|
||||
pub fn from_source (source: impl AsRef<str>) -> Usually<Self> {
|
||||
Self::from_dsl(D::from(Cst::from(source.as_ref())))
|
||||
pub fn from_source (source: &'s str) -> Usually<Self> {
|
||||
Self::from_dsl(D::from(Cst(CstConstIter(source))))
|
||||
}
|
||||
/// Create input layer collection from DSL.
|
||||
pub fn from_dsl (dsl: D) -> Usually<Self> {
|
||||
use Val::*;
|
||||
let mut input_map: BTreeMap<I, Vec<InputBinding<D>>> = Default::default();
|
||||
match dsl.exp() {
|
||||
Some(exp) => match exp.head() {
|
||||
Some(Str(path)) => {
|
||||
let path = PathBuf::from(path.as_ref());
|
||||
for (key, val) in InputMap::<I, D>::from_path(&path)?.0.into_iter() {
|
||||
todo!("import {path:?} {key:?} {val:?}");
|
||||
if !input_map.contains_key(&key) {
|
||||
input_map.insert(key, vec![]);
|
||||
}
|
||||
match dsl.exp_head() {
|
||||
Str(path) => {
|
||||
let path = PathBuf::from(path.as_ref());
|
||||
for (key, val) in InputMap::<I, D>::from_path(&path)?.0.into_iter() {
|
||||
todo!("import {path:?} {key:?} {val:?}");
|
||||
if !input_map.contains_key(&key) {
|
||||
input_map.insert(key, vec![]);
|
||||
}
|
||||
},
|
||||
Some(Sym(sym)) => {
|
||||
//let key: I = sym.into();
|
||||
//if !input_map.contains_key(&key) {
|
||||
//input_map.insert(key, vec![]);
|
||||
//}
|
||||
todo!("binding {sym:?} {:?}", exp.tail());
|
||||
},
|
||||
Some(Key("if")) => {
|
||||
todo!("conditional binding {:?}", exp.tail());
|
||||
},
|
||||
_ => return Err(format!("invalid form in keymap: {exp:?}").into())
|
||||
}
|
||||
},
|
||||
_ => return Err(format!("not an expression: {dsl:?}").into())
|
||||
Sym(sym) => {
|
||||
//let key: I = sym.into();
|
||||
//if !input_map.contains_key(&key) {
|
||||
//input_map.insert(key, vec![]);
|
||||
//}
|
||||
todo!("binding {sym:?} {:?}", dsl.exp_tail());
|
||||
},
|
||||
Key(s) if s.as_ref() == "if" => {
|
||||
todo!("conditional binding {:?}", dsl.exp_tail());
|
||||
},
|
||||
_ => return Err(format!("invalid form in keymap: {dsl:?}").into())
|
||||
}
|
||||
Ok(Self(input_map))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue