move morphism to editors/char mod

This commit is contained in:
Michael Sippel 2024-01-18 18:17:26 +01:00
parent caa0c9a5c0
commit 8471c7a90f
Signed by: senvas
GPG key ID: F96CF119C34B64A6
4 changed files with 54 additions and 80 deletions

View file

@ -28,6 +28,8 @@ async fn main() {
*/ */
let ctx = Arc::new(RwLock::new(Context::new())); let ctx = Arc::new(RwLock::new(Context::new()));
nested::editors::char::init_ctx( ctx.clone() );
/* structure of Repr-Tree /* structure of Repr-Tree
* *
* === Repr-Tree === * === Repr-Tree ===
@ -67,43 +69,6 @@ async fn main() {
port_edit.outer().into() port_edit.outer().into()
); );
rt_digit.write().unwrap()
.insert_leaf(
vec![ Context::parse(&ctx, "u32") ].into_iter(),
port_u32.outer().into()
);
let morphtype =
nested::repr_tree::MorphismType {
src_type: Context::parse(&ctx, "Char"),
dst_type: Context::parse(&ctx, "Char~EditTree")
};
ctx.write().unwrap()
.morphisms
.add_morphism(
morphtype,
{
let ctx =ctx.clone();
move |rt, σ| {
/* Create EditTree object
*/
let mut edittree_char = nested::editors::char::CharEditor::new_edit_tree(
ctx.clone(),
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
);
edittree_char = nested_tty::editors::edittree_make_char_view( edittree_char );
/* Insert EditTree into ReprTree
*/
rt.write().unwrap()
.insert_leaf(
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
SingletonBuffer::new(edittree_char).get_port().into()
);
}
}
);
/* /*
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<Seq Char>") ); let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<Seq Char>") );
@ -118,25 +83,24 @@ async fn main() {
/* setup projections between representations /* setup projections between representations
*/ */
/* eprintln!("rt_digit = {:?}", rt_digit);
// created by Char ==> Char~EditTree
let mut edittree_char =
nested::editors::char::CharEditor::new_edit_tree(
ctx.clone(),
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
);
*/
eprintln!("morph [ Char ==> Char~EditTree ]"); eprintln!("morph [ Char ==> Char~EditTree ]");
let rt_char = rt_digit.read().unwrap()
.descend(Context::parse(&ctx, "Char"))
.unwrap().clone();
eprintln!("rt_char = {:?}", rt_char);
ctx.read().unwrap() ctx.read().unwrap()
.morphisms .morphisms
.morph( .morph(
rt_digit.read().unwrap() rt_char.clone(),
.descend(Context::parse(&ctx, "Char"))
.unwrap().clone(),
&Context::parse(&ctx, "Char~EditTree") &Context::parse(&ctx, "Char~EditTree")
); );
eprintln!("rt_digit = {:?}", rt_char);
let edittree_char = let edittree_char =
ReprTree::descend_ladder( ReprTree::descend_ladder(
&rt_digit, &rt_digit,
@ -166,34 +130,17 @@ async fn main() {
node_edit_digit = nested_tty::editors::edittree_make_digit_view( node_edit_digit ); node_edit_digit = nested_tty::editors::edittree_make_digit_view( node_edit_digit );
let mut edit_digit = node_edit_digit.get_edit::< nested::editors::integer::DigitEditor >().unwrap(); let mut edit_digit = node_edit_digit.get_edit::< nested::editors::integer::DigitEditor >().unwrap();
/*
// created by <Digit 10> ==> <Digit 10>~U32 // created by <Digit 10> ==> <Digit 10>~U32
port_u32.attach_to( port_char.outer().map(|c| c.to_digit(16).unwrap_or(0)) ); port_u32.attach_to( port_char.outer().map(|c| c.to_digit(16).unwrap_or(0)) );
// port_u32.attach_to( edit_digit.read().unwrap().get_data_port().map(|d| d.unwrap_or(0)) ); // port_u32.attach_to( edit_digit.read().unwrap().get_data_port().map(|d| d.unwrap_or(0)) );
let port_proj_u32_to_char = port_u32.outer().map(|val| char::from_digit(val, 16).unwrap_or('?') ); let port_proj_u32_to_char = port_u32.outer().map(|val| char::from_digit(val, 16).unwrap_or('?') );
*/
let buf_edit_digit = r3vi::buffer::singleton::SingletonBuffer::new( node_edit_digit ); let buf_edit_digit = r3vi::buffer::singleton::SingletonBuffer::new( node_edit_digit );
port_edit.attach_to( buf_edit_digit.get_port() ); port_edit.attach_to( buf_edit_digit.get_port() );
/*
ctx.write().unwrap()
.morphisms
.add_morphism(
MorphismType {
src_type: Context::parse(&ctx, "Char"),
dst_type: Context::parse(&ctx, "Char~EditTree")
},
|rt, _σ| {
rt.write().unwrap()
.insert_branch(
Context::parse(&ctx, "")
);
}
)
*/
/* setup terminal /* setup terminal
*/ */
let app = TTYApplication::new({ let app = TTYApplication::new({
@ -224,7 +171,7 @@ async fn main() {
compositor compositor
.write() .write()
.unwrap() .unwrap()
.push(nested_tty::make_label(&label).offset(Vector2::new(0, 2))); .push(nested_tty::make_label(&label).offset(Vector2::new(0, 1)));
/* /*
compositor compositor
.write() .write()

View file

@ -16,14 +16,42 @@ use {
std::sync::RwLock std::sync::RwLock
}; };
pub fn init_ctx( ctx: &mut Context ) { pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
/*
ctx.add_node_ctor( let morphtype =
"Char", crate::repr_tree::MorphismType {
Arc::new(|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| { src_type: Context::parse(&ctx, "Char"),
Some(CharEditor::new_node(ctx, depth)) dst_type: Context::parse(&ctx, "Char~EditTree")
})); };
ctx.write().unwrap()
.morphisms
.add_morphism(
morphtype,
{
let ctx = ctx.clone();
move |rt, σ| {
/* Create EditTree object
*/ */
let mut edittree_char = CharEditor::new_edit_tree(
ctx.clone(),
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
);
/*
/* setup tty-view for EditTree
*/
edittree_char = nested_tty::editors::edittree_make_char_view( edittree_char );
*/
/* Insert EditTree into ReprTree
*/
let mut rt = rt.write().unwrap();
rt.insert_leaf(
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
SingletonBuffer::new(edittree_char).get_port().into()
);
}
}
);
} }
pub struct CharEditor { pub struct CharEditor {

View file

@ -26,10 +26,10 @@ pub struct ReprTree {
impl std::fmt::Debug for ReprTree { impl std::fmt::Debug for ReprTree {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "type: {:?}", self.type_tag)?; writeln!(f, "| type: {:?}", self.type_tag)?;
for (_k,x) in self.branches.iter() { for (_k,x) in self.branches.iter() {
write!(f, "child: {:?}", x)?; writeln!(f, "|--> child: {:?}", x)?;
} }
Ok(()) Ok(())

View file

@ -68,7 +68,6 @@ impl MorphismBase {
); );
if let Ok(σ) = unification_problem.solve() { if let Ok(σ) = unification_problem.solve() {
eprintln!("found matching morphism");
return Some((m, σ)); return Some((m, σ));
} }
} }