dsl goes fat
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-05-27 00:53:06 +03:00
parent 08a8dff93d
commit cb47c4d0ff
11 changed files with 513 additions and 492 deletions

View file

@ -23,34 +23,27 @@ impl InputLayers {
self.0.push(InputLayer(condition, binding));
self
}
pub fn handle <S: Eval<Ast, bool>, I, O: Command<S>> (&self, state: &mut S, input: I) -> Perhaps<O> {
pub fn handle <S: Eval<Ast, bool> + Eval<Ast, O>, I: Eval<Ast, bool>, O: Command<S>> (&self, state: &mut S, input: I) -> Perhaps<O> {
InputHandle(state, self.0.as_slice()).try_eval(input)
}
}
pub struct InputHandle<'a, S>(&'a mut S, &'a [InputLayer]);
impl<'a, S: Eval<Ast, bool>, I, O: Command<S>> Eval<I, O> for InputHandle<'a, S> {
impl<'a, S: Eval<Ast, bool> + Eval<Ast, O>, I: Eval<Ast, bool>, O: Command<S>> Eval<I, O> for InputHandle<'a, S> {
fn try_eval (&self, input: I) -> Perhaps<O> {
let Self(state, layers) = self;
for InputLayer(condition, binding) in layers.iter() {
let mut matches = true;
if let Some(condition) = condition {
matches = state.eval(*condition, ||"input: no condition")?;
matches = state.eval(condition.clone(), ||"input: no condition")?;
}
if matches {
if let AstValue::Exp(e) = binding.peek() {
if let Some(ast) = e.peek() {
if input.eval(ast.clone(), ||"InputLayers: input.eval(binding) failed")?
&& let Some(command) = state.try_eval(ast)? {
return Ok(Some(command))
}
} else {
unreachable!("InputLayer")
}
} else {
panic!("InputLayer: expected expression, got: {input:?}")
}
if matches
&& let Some(exp) = binding.exp()
&& let Some(ast) = exp.peek()
&& input.eval(ast.clone(), ||"InputLayers: input.eval(binding) failed")?
&& let Some(command) = state.try_eval(ast)? {
return Ok(Some(command))
}
}
Ok(None)

View file

@ -1,4 +1,5 @@
#![feature(associated_type_defaults)]
#![feature(if_let_guard)]
pub(crate) use tengri_core::*;