mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
Compare commits
No commits in common. "21f7f6b38afc966b7b45af442935d48c8c5067d3" and "0d4ba4a54ef0528a0a45b58e21a1e4aa7ed5eaf9" have entirely different histories.
21f7f6b38a
...
0d4ba4a54e
8 changed files with 121 additions and 132 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
|
@ -304,9 +304,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.15.3"
|
version = "0.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
|
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"allocator-api2",
|
"allocator-api2",
|
||||||
"equivalent",
|
"equivalent",
|
||||||
|
|
@ -791,9 +791,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "1.0.7"
|
version = "1.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
|
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"errno",
|
"errno",
|
||||||
|
|
@ -928,13 +928,13 @@ dependencies = [
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"getrandom 0.3.2",
|
"getrandom 0.3.2",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 1.0.7",
|
"rustix 1.0.5",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri"
|
name = "tengri"
|
||||||
version = "0.13.0"
|
version = "0.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tengri_dsl",
|
"tengri_dsl",
|
||||||
"tengri_input",
|
"tengri_input",
|
||||||
|
|
@ -944,7 +944,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_dsl"
|
name = "tengri_dsl"
|
||||||
version = "0.13.0"
|
version = "0.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"konst",
|
"konst",
|
||||||
|
|
@ -955,7 +955,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_input"
|
name = "tengri_input"
|
||||||
version = "0.13.0"
|
version = "0.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tengri_dsl",
|
"tengri_dsl",
|
||||||
"tengri_tui",
|
"tengri_tui",
|
||||||
|
|
@ -963,7 +963,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_output"
|
name = "tengri_output"
|
||||||
version = "0.13.0"
|
version = "0.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proptest",
|
"proptest",
|
||||||
"proptest-derive",
|
"proptest-derive",
|
||||||
|
|
@ -974,7 +974,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_tui"
|
name = "tengri_tui"
|
||||||
version = "0.13.0"
|
version = "0.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic_float",
|
"atomic_float",
|
||||||
"better-panic",
|
"better-panic",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.13.0"
|
version = "0.12.0"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,101 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
||||||
self.as_ref().map(|s|s.get_or_fail(dsl)).expect("no provider")
|
self.as_ref().map(|s|s.get_or_fail(dsl)).expect("no provider")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implement `Context` for a context and type.
|
||||||
|
#[macro_export] macro_rules! provide {
|
||||||
|
// Provide a value to the EDN template
|
||||||
|
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||||
|
impl Context<$type> for $State {
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
fn get (&$self, dsl: &Value) -> Option<$type> {
|
||||||
|
use Value::*;
|
||||||
|
Some(match dsl { $(Sym($pat) => $expr,)* _ => return None })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Provide a value more generically
|
||||||
|
($lt:lifetime: $type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||||
|
impl<$lt> Context<$lt, $type> for $State {
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
fn get (&$lt $self, dsl: &Value) -> Option<$type> {
|
||||||
|
use Value::*;
|
||||||
|
Some(match dsl { $(Sym($pat) => $expr,)* _ => return None })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement `Context` for a context and numeric type.
|
||||||
|
///
|
||||||
|
/// This enables support for numeric literals.
|
||||||
|
#[macro_export] macro_rules! provide_num {
|
||||||
|
// Provide a value that may also be a numeric literal in the EDN, to a generic implementation.
|
||||||
|
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||||
|
impl<$T: $Trait> Context<$type> for $T {
|
||||||
|
fn get (&$self, dsl: &Value) -> Option<$type> {
|
||||||
|
use Value::*;
|
||||||
|
Some(match dsl { $(Sym($pat) => $expr,)* Num(n) => *n as $type, _ => return None })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Provide a value that may also be a numeric literal in the EDN, to a concrete implementation.
|
||||||
|
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||||
|
impl Context<$type> for $State {
|
||||||
|
fn get (&$self, dsl: &Value) -> Option<$type> {
|
||||||
|
use Value::*;
|
||||||
|
Some(match dsl { $(Sym($pat) => $expr,)* Num(n) => *n as $type, _ => return None })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement `Context` for a context and the boolean type.
|
||||||
|
///
|
||||||
|
/// This enables support for boolean literals.
|
||||||
|
#[macro_export] macro_rules! provide_bool {
|
||||||
|
// Provide a value that may also be a numeric literal in the EDN, to a generic implementation.
|
||||||
|
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||||
|
impl<$T: $Trait> Context<$type> for $T {
|
||||||
|
fn get (&$self, dsl: &Value) -> Option<$type> {
|
||||||
|
use Value::*;
|
||||||
|
Some(match dsl {
|
||||||
|
Num(n) => match *n { 0 => false, _ => true },
|
||||||
|
Sym(":false") | Sym(":f") => false,
|
||||||
|
Sym(":true") | Sym(":t") => true,
|
||||||
|
$(Sym($pat) => $expr,)*
|
||||||
|
_ => return Context::get(self, dsl)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Provide a value that may also be a numeric literal in the EDN, to a concrete implementation.
|
||||||
|
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||||
|
impl Context<$type> for $State {
|
||||||
|
fn get (&$self, dsl: &Value) -> Option<$type> {
|
||||||
|
use Value::*;
|
||||||
|
Some(match dsl {
|
||||||
|
Num(n) => match *n { 0 => false, _ => true },
|
||||||
|
Sym(":false") | Sym(":f") => false,
|
||||||
|
Sym(":true") | Sym(":t") => true,
|
||||||
|
$(Sym($pat) => $expr,)*
|
||||||
|
_ => return None
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] #[test] fn test_edn_context () {
|
||||||
|
struct Test;
|
||||||
|
provide_bool!(bool: |self: Test|{
|
||||||
|
":provide-bool" => true
|
||||||
|
});
|
||||||
|
let test = Test;
|
||||||
|
assert_eq!(test.get(&Value::Sym(":false")), Some(false));
|
||||||
|
assert_eq!(test.get(&Value::Sym(":true")), Some(true));
|
||||||
|
assert_eq!(test.get(&Value::Sym(":provide-bool")), Some(true));
|
||||||
|
assert_eq!(test.get(&Value::Sym(":missing-bool")), None);
|
||||||
|
assert_eq!(test.get(&Value::Num(0)), Some(false));
|
||||||
|
assert_eq!(test.get(&Value::Num(1)), Some(true));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,6 @@ impl<'a> Iterator for TokenIter<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a str> for TokenIter<'a> {
|
|
||||||
fn from (source: &'a str) -> Self{
|
|
||||||
Self(SourceIter(source))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<SourceIter<'a>> for TokenIter<'a> {
|
impl<'a> From<SourceIter<'a>> for TokenIter<'a> {
|
||||||
fn from (source: SourceIter<'a>) -> Self{
|
fn from (source: SourceIter<'a>) -> Self{
|
||||||
Self(source)
|
Self(source)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement `Context` for one or more base structs, types, and keys. */
|
|
||||||
#[macro_export] macro_rules! expose {
|
#[macro_export] macro_rules! expose {
|
||||||
($([$self:ident:$State:ty] $(([$($Type:tt)*] $(($pat:literal $expr:expr))*))*)*) => {
|
($([$self:ident:$State:ty] $(([$($Type:tt)*] $(($pat:literal $expr:expr))*))*)*) => {
|
||||||
$(expose!(@impl [$self: $State] { $([$($Type)*] => { $($pat => $expr),* })* });)*
|
$(expose!(@impl [$self: $State] { $([$($Type)*] => { $($pat => $expr),* })* });)*
|
||||||
|
|
@ -52,90 +51,6 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement `Context` for a context and type.
|
|
||||||
#[macro_export] macro_rules! provide {
|
|
||||||
// Provide a value to the EDN template
|
|
||||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
|
||||||
impl Context<$type> for $State {
|
|
||||||
#[allow(unreachable_code)]
|
|
||||||
fn get (&$self, dsl: &Value) -> Option<$type> {
|
|
||||||
use Value::*;
|
|
||||||
Some(match dsl { $(Sym($pat) => $expr,)* _ => return None })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Provide a value more generically
|
|
||||||
($lt:lifetime: $type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
|
||||||
impl<$lt> Context<$lt, $type> for $State {
|
|
||||||
#[allow(unreachable_code)]
|
|
||||||
fn get (&$lt $self, dsl: &Value) -> Option<$type> {
|
|
||||||
use Value::*;
|
|
||||||
Some(match dsl { $(Sym($pat) => $expr,)* _ => return None })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implement `Context` for a context and numeric type.
|
|
||||||
///
|
|
||||||
/// This enables support for numeric literals.
|
|
||||||
#[macro_export] macro_rules! provide_num {
|
|
||||||
// Provide a value that may also be a numeric literal in the EDN, to a generic implementation.
|
|
||||||
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
|
||||||
impl<$T: $Trait> Context<$type> for $T {
|
|
||||||
fn get (&$self, dsl: &Value) -> Option<$type> {
|
|
||||||
use Value::*;
|
|
||||||
Some(match dsl { $(Sym($pat) => $expr,)* Num(n) => *n as $type, _ => return None })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Provide a value that may also be a numeric literal in the EDN, to a concrete implementation.
|
|
||||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
|
||||||
impl Context<$type> for $State {
|
|
||||||
fn get (&$self, dsl: &Value) -> Option<$type> {
|
|
||||||
use Value::*;
|
|
||||||
Some(match dsl { $(Sym($pat) => $expr,)* Num(n) => *n as $type, _ => return None })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implement `Context` for a context and the boolean type.
|
|
||||||
///
|
|
||||||
/// This enables support for boolean literals.
|
|
||||||
#[macro_export] macro_rules! provide_bool {
|
|
||||||
// Provide a value that may also be a numeric literal in the EDN, to a generic implementation.
|
|
||||||
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
|
||||||
impl<$T: $Trait> Context<$type> for $T {
|
|
||||||
fn get (&$self, dsl: &Value) -> Option<$type> {
|
|
||||||
use Value::*;
|
|
||||||
Some(match dsl {
|
|
||||||
Num(n) => match *n { 0 => false, _ => true },
|
|
||||||
Sym(":false") | Sym(":f") => false,
|
|
||||||
Sym(":true") | Sym(":t") => true,
|
|
||||||
$(Sym($pat) => $expr,)*
|
|
||||||
_ => return Context::get(self, dsl)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Provide a value that may also be a numeric literal in the EDN, to a concrete implementation.
|
|
||||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
|
||||||
impl Context<$type> for $State {
|
|
||||||
fn get (&$self, dsl: &Value) -> Option<$type> {
|
|
||||||
use Value::*;
|
|
||||||
Some(match dsl {
|
|
||||||
Num(n) => match *n { 0 => false, _ => true },
|
|
||||||
Sym(":false") | Sym(":f") => false,
|
|
||||||
Sym(":true") | Sym(":t") => true,
|
|
||||||
$(Sym($pat) => $expr,)*
|
|
||||||
_ => return None
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export] macro_rules! impose {
|
#[macro_export] macro_rules! impose {
|
||||||
([$self:ident:$Struct:ty] $(($Command:ty : $(($cmd:literal $args:tt $result:expr))*))*) => {
|
([$self:ident:$Struct:ty] $(($Command:ty : $(($cmd:literal $args:tt $result:expr))*))*) => {
|
||||||
$(atom_command!($Command: |$self: $Struct| { $(($cmd $args $result))* });)*
|
$(atom_command!($Command: |$self: $Struct| { $(($cmd $args $result))* });)*
|
||||||
|
|
|
||||||
|
|
@ -114,20 +114,6 @@ mod dsl_macros;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_dsl_context () {
|
|
||||||
struct Test;
|
|
||||||
provide_bool!(bool: |self: Test|{
|
|
||||||
":provide-bool" => true
|
|
||||||
});
|
|
||||||
let test = Test;
|
|
||||||
assert_eq!(test.get(&Value::Sym(":false")), Some(false));
|
|
||||||
assert_eq!(test.get(&Value::Sym(":true")), Some(true));
|
|
||||||
assert_eq!(test.get(&Value::Sym(":provide-bool")), Some(true));
|
|
||||||
assert_eq!(test.get(&Value::Sym(":missing-bool")), None);
|
|
||||||
assert_eq!(test.get(&Value::Num(0)), Some(false));
|
|
||||||
assert_eq!(test.get(&Value::Num(1)), Some(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
//#[cfg(test)] #[test] fn test_examples () -> Result<(), ParseError> {
|
//#[cfg(test)] #[test] fn test_examples () -> Result<(), ParseError> {
|
||||||
//// Let's pretend to render some view.
|
//// Let's pretend to render some view.
|
||||||
//let source = include_str!("../../tek/src/view_arranger.edn");
|
//let source = include_str!("../../tek/src/view_arranger.edn");
|
||||||
|
|
|
||||||
|
|
@ -70,18 +70,14 @@ impl<'a, S, C: DslCommand<'a, S>, I: DslInput> KeyMap<'a, S, C, I> for TokenIter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type InputLayerCond<'a, S> = Box<dyn Fn(&S)->bool + Send + Sync + 'a>;
|
|
||||||
|
|
||||||
/// A collection of pre-configured mappings of input events to commands,
|
/// A collection of pre-configured mappings of input events to commands,
|
||||||
/// which may be made available subject to given conditions.
|
/// which may be made available subject to given conditions.
|
||||||
pub struct InputMap<'a, S, C, I, M>
|
pub struct InputMap<'a, S, C: DslCommand<'a, S>, I: DslInput, M: KeyMap<'a, S, C, I> + Send + Sync> {
|
||||||
where
|
|
||||||
C: DslCommand<'a, S>,
|
|
||||||
I: DslInput,
|
|
||||||
M: KeyMap<'a, S, C, I> + Send + Sync
|
|
||||||
{
|
|
||||||
__: &'a PhantomData<(S, C, I)>,
|
__: &'a PhantomData<(S, C, I)>,
|
||||||
pub layers: Vec<(InputLayerCond<'a, S>, M)>,
|
pub layers: Vec<(
|
||||||
|
fn(&S)->bool,
|
||||||
|
M
|
||||||
|
)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S, C, I, M> Default for InputMap<'a, S, C, I, M>
|
impl<'a, S, C, I, M> Default for InputMap<'a, S, C, I, M>
|
||||||
|
|
@ -112,15 +108,15 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn add_layer (&mut self, keymap: M) -> &mut Self {
|
pub fn add_layer (&mut self, keymap: M) -> &mut Self {
|
||||||
self.add_layer_if(Box::new(|_|true), keymap);
|
self.add_layer_if(|_|true, keymap);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn layer_if (mut self, condition: InputLayerCond<'a, S>, keymap: M) -> Self {
|
pub fn layer_if (mut self, condition: fn(&S)->bool, keymap: M) -> Self {
|
||||||
self.add_layer_if(condition, keymap);
|
self.add_layer_if(condition, keymap);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn add_layer_if (&mut self, condition: InputLayerCond<'a, S>, keymap: M) -> &mut Self {
|
pub fn add_layer_if (&mut self, condition: fn(&S)->bool, keymap: M) -> &mut Self {
|
||||||
self.layers.push((Box::new(condition), keymap));
|
self.layers.push((condition, keymap));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,14 @@ use crate::*;
|
||||||
#[cfg(feature = "dsl")]
|
#[cfg(feature = "dsl")]
|
||||||
pub struct View<'a, T>(
|
pub struct View<'a, T>(
|
||||||
pub &'a T,
|
pub &'a T,
|
||||||
pub TokenIter<'a>
|
pub SourceIter<'a>
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "dsl")]
|
#[cfg(feature = "dsl")]
|
||||||
impl<'a, O: Output + 'a, T: ViewContext<'a, O>> Content<O> for View<'a, T> {
|
impl<'a, O: Output + 'a, T: ViewContext<'a, O>> Content<O> for View<'a, T> {
|
||||||
fn content (&self) -> impl Render<O> {
|
fn content (&self) -> impl Render<O> {
|
||||||
let mut iter = self.1.clone();
|
let iter = self.1.clone();
|
||||||
while let Some(Token { value, .. }) = iter.next() {
|
while let Some((Token { value, .. }, _)) = iter.next() {
|
||||||
if let Some(content) = self.0.get_content(&value) {
|
if let Some(content) = self.0.get_content(&value) {
|
||||||
return Some(content)
|
return Some(content)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue