mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
core, input: add flex_trait
This commit is contained in:
parent
360b404b69
commit
8cbd7dd8e8
7 changed files with 201 additions and 98 deletions
|
|
@ -54,20 +54,37 @@ 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(source.as_ref())
|
||||
Self::from_dsl(&mut source.as_ref())
|
||||
}
|
||||
/// Create event map from DSL tokenizer.
|
||||
pub fn from_dsl (mut dsl: impl Dsl) -> Usually<Self> where E: From<Arc<str>> {
|
||||
pub fn from_dsl <'s, D: DslExp<'s> + 's> (dsl: &'s mut D) -> Usually<Self> where E: From<Arc<str>> {
|
||||
let mut map: Self = Default::default();
|
||||
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())?);
|
||||
let mut head: Option<D> = dsl.head()?;
|
||||
let mut tail: Option<D> = dsl.tail()?;
|
||||
loop {
|
||||
if let Some(ref token) = head {
|
||||
if let Some(ref text) = token.text()? {
|
||||
map.0.extend(Self::from_path(PathBuf::from(text))?.0);
|
||||
continue
|
||||
}
|
||||
//if let Some(ref exp) = token.exp()? {
|
||||
////_ if let Some(sym) = token.head()?.sym()?.as_ref() => {
|
||||
////todo!()
|
||||
////},
|
||||
////_ if Some(&"if") == token.head()?.key()?.as_ref() => {
|
||||
////todo!()
|
||||
////},
|
||||
//return Err(format!("unexpected: {:?}", token.exp()).into())
|
||||
//}
|
||||
return Err(format!("unexpected: {token:?}").into())
|
||||
} else {
|
||||
break
|
||||
}
|
||||
if let Some(next) = tail {
|
||||
head = next.head()?;
|
||||
tail = next.tail()?;
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
Ok(map)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue