mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-31 10:56:41 +01:00
This commit is contained in:
parent
d06e1c41f8
commit
8a5bc7b6ea
4 changed files with 67 additions and 36 deletions
|
|
@ -1,30 +1,30 @@
|
|||
use crate::*;
|
||||
use ::dizzle::{Dsl, DslExpr, DslWord, DslNs};
|
||||
use ::dizzle::{Language, Expression, Symbol, Namespace};
|
||||
|
||||
pub trait View<O, U> {
|
||||
fn view_expr <'a> (&'a self, output: &mut O, expr: &'a impl DslExpr) -> Usually<U> {
|
||||
fn view_expr <'a> (&'a self, _output: &mut O, expr: &'a impl Expression) -> Usually<U> {
|
||||
Err(format!("View::view_expr: no exprs defined: {expr:?}").into())
|
||||
}
|
||||
fn view_word <'a> (&'a self, output: &mut O, word: &'a impl DslWord) -> Usually<U> {
|
||||
fn view_word <'a> (&'a self, _output: &mut O, word: &'a impl Symbol) -> Usually<U> {
|
||||
Err(format!("View::view_word: no words defined: {word:?}").into())
|
||||
}
|
||||
fn view <'a> (&'a self, output: &mut O, dsl: &'a impl Dsl) -> Usually<U> {
|
||||
fn view <'a> (&'a self, output: &mut O, dsl: &'a impl Language) -> Usually<U> {
|
||||
if let Ok(Some(expr)) = dsl.expr() {
|
||||
self.view_expr(output, &expr)
|
||||
} else if let Ok(Some(word)) = dsl.word() {
|
||||
self.view_word(output, &word)
|
||||
} else {
|
||||
panic!("{dsl:?}: invalid")
|
||||
Err(format!("{dsl:?}: invalid").into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn evaluate_output_expression <'a, O: Out + 'a, S> (
|
||||
state: &S, output: &mut O, expr: &'a impl DslExpr
|
||||
state: &S, output: &mut O, expr: &'a impl Expression
|
||||
) -> Usually<bool> where
|
||||
S: View<O, ()>
|
||||
+ for<'b>DslNs<'b, bool>
|
||||
+ for<'b>DslNs<'b, O::Unit>
|
||||
+ for<'b>Namespace<'b, bool>
|
||||
+ for<'b>Namespace<'b, O::Unit>
|
||||
{
|
||||
// First element of expression is used for dispatch.
|
||||
// Dispatch is proto-namespaced using separator character
|
||||
|
|
@ -43,12 +43,12 @@ pub fn evaluate_output_expression <'a, O: Out + 'a, S> (
|
|||
match frags.next() {
|
||||
|
||||
Some("when") => output.place(&When::new(
|
||||
state.from(arg0?)?.unwrap(),
|
||||
state.resolve(arg0?)?.unwrap(),
|
||||
Thunk::new(move|output: &mut O|state.view(output, &arg1).unwrap())
|
||||
)),
|
||||
|
||||
Some("either") => output.place(&Either::new(
|
||||
state.from(arg0?)?.unwrap(),
|
||||
state.resolve(arg0?)?.unwrap(),
|
||||
Thunk::new(move|output: &mut O|state.view(output, &arg1).unwrap()),
|
||||
Thunk::new(move|output: &mut O|state.view(output, &arg2).unwrap())
|
||||
)),
|
||||
|
|
@ -96,9 +96,9 @@ pub fn evaluate_output_expression <'a, O: Out + 'a, S> (
|
|||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
|
||||
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap());
|
||||
match axis {
|
||||
Some("xy") | None => Fixed::XY(state.from(arg0?)?.unwrap(), state.from(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Fixed::X(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Fixed::Y(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("xy") | None => Fixed::XY(state.resolve(arg0?)?.unwrap(), state.resolve(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Fixed::X(state.resolve(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Fixed::Y(state.resolve(arg0?)?.unwrap(), cb),
|
||||
frag => unimplemented!("fixed/{frag:?} ({expr:?}) ({head:?}) ({:?})",
|
||||
head.src()?.unwrap_or_default().split("/").next())
|
||||
}
|
||||
|
|
@ -109,9 +109,9 @@ pub fn evaluate_output_expression <'a, O: Out + 'a, S> (
|
|||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
|
||||
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap());
|
||||
match axis {
|
||||
Some("xy") | None => Min::XY(state.from(arg0?)?.unwrap(), state.from(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Min::X(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Min::Y(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("xy") | None => Min::XY(state.resolve(arg0?)?.unwrap(), state.resolve(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Min::X(state.resolve(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Min::Y(state.resolve(arg0?)?.unwrap(), cb),
|
||||
frag => unimplemented!("min/{frag:?}")
|
||||
}
|
||||
}),
|
||||
|
|
@ -121,9 +121,9 @@ pub fn evaluate_output_expression <'a, O: Out + 'a, S> (
|
|||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
|
||||
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap());
|
||||
match axis {
|
||||
Some("xy") | None => Max::XY(state.from(arg0?)?.unwrap(), state.from(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Max::X(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Max::Y(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("xy") | None => Max::XY(state.resolve(arg0?)?.unwrap(), state.resolve(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Max::X(state.resolve(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Max::Y(state.resolve(arg0?)?.unwrap(), cb),
|
||||
frag => unimplemented!("max/{frag:?}")
|
||||
}
|
||||
}),
|
||||
|
|
@ -133,9 +133,9 @@ pub fn evaluate_output_expression <'a, O: Out + 'a, S> (
|
|||
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("fixed: unsupported axis {axis:?}") };
|
||||
let cb = Thunk::new(move|output: &mut O|state.view(output, &arg).unwrap());
|
||||
match axis {
|
||||
Some("xy") | None => Push::XY(state.from(arg0?)?.unwrap(), state.from(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Push::X(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Push::Y(state.from(arg0?)?.unwrap(), cb),
|
||||
Some("xy") | None => Push::XY(state.resolve(arg0?)?.unwrap(), state.resolve(arg1?)?.unwrap(), cb),
|
||||
Some("x") => Push::X(state.resolve(arg0?)?.unwrap(), cb),
|
||||
Some("y") => Push::Y(state.resolve(arg0?)?.unwrap(), cb),
|
||||
frag => unimplemented!("push/{frag:?}")
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue