move TypeTerm editor to editors module; remove make_editor.rs and distribute context initialization into editor submodules
This commit is contained in:
parent
4464a72f29
commit
249e811c77
13 changed files with 215 additions and 306 deletions
|
@ -7,7 +7,7 @@ use {
|
|||
buffer::singleton::*
|
||||
},
|
||||
crate::{
|
||||
type_system::{Context, ReprTree},
|
||||
type_system::{Context, ReprTree, TypeTerm},
|
||||
terminal::{TerminalAtom, TerminalStyle},
|
||||
tree::{NestedNode, TreeNavResult},
|
||||
commander::{ObjCommander}
|
||||
|
@ -16,6 +16,14 @@ use {
|
|||
std::sync::RwLock
|
||||
};
|
||||
|
||||
pub fn init_ctx( ctx: &mut Context ) {
|
||||
ctx.add_node_ctor(
|
||||
"Char",
|
||||
Arc::new(|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, _depth: usize| {
|
||||
Some(CharEditor::new_node(ctx))
|
||||
}));
|
||||
}
|
||||
|
||||
pub struct CharEditor {
|
||||
ctx: Arc<RwLock<Context>>,
|
||||
data: SingletonBuffer<char>
|
||||
|
|
|
@ -15,10 +15,7 @@ use {
|
|||
cgmath::Point2
|
||||
};
|
||||
|
||||
pub fn init_integer_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
||||
let ctx0 = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
||||
|
||||
let mut ctx = ctx0.write().unwrap();
|
||||
pub fn init_ctx(ctx: &mut Context) {
|
||||
ctx.add_typename("MachineInt".into());
|
||||
ctx.add_typename("u32".into());
|
||||
ctx.add_typename("u64".into());
|
||||
|
@ -141,8 +138,5 @@ pub fn init_integer_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
|||
ctx.add_typename("Duration".into());
|
||||
ctx.add_typename("Seconds".into());
|
||||
ctx.add_typename("ℕ".into());
|
||||
|
||||
drop(ctx);
|
||||
ctx0
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@ pub use {
|
|||
add::Add,
|
||||
editor::{DigitEditor, PosIntEditor},
|
||||
radix::RadixProjection,
|
||||
ctx::init_integer_ctx
|
||||
ctx::init_ctx
|
||||
};
|
||||
|
||||
|
|
45
nested/src/editors/list/ctx.rs
Normal file
45
nested/src/editors/list/ctx.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use {
|
||||
r3vi::{
|
||||
view::{port::UpdateTask, OuterViewPort, singleton::*, sequence::*},
|
||||
buffer::{singleton::*, vec::*}
|
||||
},
|
||||
crate::{
|
||||
type_system::{Context, TypeTerm, ReprTree},
|
||||
editors::list::{ListEditor, ListCursor, ListCursorMode, ListCmd, PTYListController, PTYListStyle},
|
||||
tree::{NestedNode, TreeNav, TreeCursor},
|
||||
diagnostics::Diagnostics
|
||||
},
|
||||
std::sync::{Arc, RwLock}
|
||||
};
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
pub fn init_ctx(ctx: &mut Context) {
|
||||
ctx.add_list_typename("ListCmd".into());
|
||||
ctx.add_list_typename("List".into());
|
||||
|
||||
ctx.add_node_ctor(
|
||||
"List", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
||||
match ty {
|
||||
TypeTerm::App(args) => {
|
||||
if args.len() > 1 {
|
||||
let typ = args[1].clone();
|
||||
|
||||
let mut node = ListEditor::new(ctx.clone(), typ).into_node(depth);
|
||||
|
||||
PTYListController::for_node( &mut node, Some(','), Some('}') );
|
||||
PTYListStyle::for_node( &mut node, ("{",", ","}") );
|
||||
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -28,37 +28,6 @@ pub struct ListEditor {
|
|||
}
|
||||
|
||||
impl ListEditor {
|
||||
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
|
||||
let mut ctx = ctx.write().unwrap();
|
||||
|
||||
ctx.add_list_typename("ListCmd".into());
|
||||
|
||||
ctx.add_list_typename("List".into());
|
||||
ctx.add_node_ctor(
|
||||
"List", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
||||
match ty {
|
||||
TypeTerm::App(args) => {
|
||||
if args.len() > 1 {
|
||||
let typ = args[1].clone();
|
||||
|
||||
let mut node = ListEditor::new(ctx.clone(), typ).into_node(depth);
|
||||
|
||||
PTYListController::for_node( &mut node, Some(','), Some('}') );
|
||||
PTYListStyle::for_node( &mut node, ("{",", ","}") );
|
||||
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
ctx: Arc<RwLock<Context>>,
|
||||
typ: TypeTerm,
|
||||
|
@ -353,7 +322,6 @@ impl ListEditor {
|
|||
let depth = item.depth;
|
||||
|
||||
if let Some(head_editor) = item.editor.get() {
|
||||
|
||||
eprintln!("listlistsplit:editor = {:?}", Arc::into_raw(head_editor.clone()));
|
||||
|
||||
let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap();
|
||||
|
@ -419,7 +387,6 @@ impl ListEditor {
|
|||
idx: Some(idx - 1), mode: ListCursorMode::Select
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,14 @@ pub mod nav;
|
|||
pub mod segment;
|
||||
pub mod pty_editor;
|
||||
pub mod cmd;
|
||||
pub mod ctx;
|
||||
|
||||
pub use {
|
||||
cursor::{ListCursor, ListCursorMode},
|
||||
editor::ListEditor,
|
||||
segment::{ListSegment, ListSegmentSequence},
|
||||
pty_editor::{PTYListStyle, PTYListController},
|
||||
cmd::ListCmd
|
||||
cmd::ListCmd,
|
||||
ctx::init_ctx
|
||||
};
|
||||
|
||||
|
|
|
@ -176,24 +176,28 @@ impl PTYListController {
|
|||
|
||||
match cur.mode {
|
||||
ListCursorMode::Insert => {
|
||||
eprintln!("PTYList(insert): create new child and forward cmd");
|
||||
let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap();
|
||||
new_edit.goto(TreeCursor::home());
|
||||
|
||||
match new_edit.send_cmd_obj(cmd_obj.clone()) {
|
||||
TreeNavResult::Continue => {
|
||||
eprintln!("PTYList(insert): child returned cont");
|
||||
e.insert(Arc::new(RwLock::new(new_edit)));
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
TreeNavResult::Exit => TreeNavResult::Exit
|
||||
TreeNavResult::Exit => {
|
||||
eprintln!("PTYList(insert): child returned exit");
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
},
|
||||
ListCursorMode::Select => {
|
||||
if let Some(mut item) = e.get_item_mut() {
|
||||
|
||||
eprintln!("PTYList: forward any cmd to current child item");
|
||||
eprintln!("PTYList(select): forward any cmd to current child item");
|
||||
let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone());
|
||||
let child_close_char = item.read().unwrap().close_char.get();
|
||||
eprintln!("PTYList: returned");
|
||||
eprintln!("PTYList(select): child returned");
|
||||
|
||||
match res {
|
||||
TreeNavResult::Continue => TreeNavResult::Continue,
|
||||
|
@ -224,7 +228,6 @@ impl PTYListController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
use r3vi::view::singleton::SingletonView;
|
||||
use crate::commander::ObjCommander;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
pub mod char;
|
||||
pub mod integer;
|
||||
|
||||
pub mod list;
|
||||
pub mod product;
|
||||
pub mod sum;
|
||||
|
||||
pub mod char;
|
||||
pub mod integer;
|
||||
pub mod typeterm;
|
||||
|
||||
|
|
117
nested/src/editors/typeterm/ctx.rs
Normal file
117
nested/src/editors/typeterm/ctx.rs
Normal file
|
@ -0,0 +1,117 @@
|
|||
use {
|
||||
r3vi::{
|
||||
buffer::singleton::*,
|
||||
view::{singleton::*, sequence::*, OuterViewPort},
|
||||
projection::flatten_grid::*,
|
||||
projection::flatten_singleton::*
|
||||
},
|
||||
crate::{
|
||||
type_system::{Context, TypeID, TypeTerm, ReprTree, MorphismTypePattern},
|
||||
terminal::{TerminalEvent, TerminalStyle},
|
||||
editors::{sum::*, list::{ListCursorMode, ListEditor, PTYListStyle, PTYListController}, typeterm::{State, TypeTermEditor}},
|
||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||
commander::ObjCommander,
|
||||
PtySegment
|
||||
},
|
||||
termion::event::{Key},
|
||||
std::{sync::{Arc, RwLock}, any::Any},
|
||||
cgmath::{Vector2, Point2}
|
||||
};
|
||||
|
||||
pub fn init_ctx(ctx: &mut Context) {
|
||||
ctx.add_list_typename("Type".into()); // = Lit | Sym | App | Ladder
|
||||
ctx.add_list_typename("Type::Lit".into()); // = Num | char
|
||||
ctx.add_list_typename("Type::Lit::Num".into()); // [0-9]*
|
||||
ctx.add_list_typename("Type::Lit::Char".into()); // .
|
||||
ctx.add_list_typename("Type::Sym".into()); // = Fun | Var
|
||||
ctx.add_list_typename("Type::Sym::Fun".into()); // [a-zA-Z][a-zA-Z0-9]*
|
||||
ctx.add_list_typename("Type::Sym::Var".into()); // [a-zA-Z][a-zA-Z0-9]*
|
||||
ctx.add_list_typename("Type::App".into()); // = <T1 T2 ...>
|
||||
ctx.add_list_typename("Type::Ladder".into()); // = T1~T2~...
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type").unwrap() },
|
||||
Arc::new(move |mut node, _dst_type:_| {
|
||||
let mut new_node = TypeTermEditor::with_node( node.ctx.clone(), node.depth.get(), node.clone(), State::Any );
|
||||
Some(new_node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Ladder").unwrap() },
|
||||
Arc::new(|mut node, _dst_type: _| {
|
||||
PTYListController::for_node( &mut node, Some('~'), None );
|
||||
PTYListStyle::for_node( &mut node, ("","~","") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::App").unwrap() },
|
||||
Arc::new( |mut node, _dst_type: _| {
|
||||
PTYListController::for_node( &mut node, Some(' '), Some('>') );
|
||||
PTYListStyle::for_node( &mut node, ("<"," ",">") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Sym").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Sym::Fun").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Sym::Var").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
|
||||
// display variables blue color
|
||||
if let Some(v) = node.view {
|
||||
node.view = Some(
|
||||
v.map_item(|i,p| p.add_style_front(TerminalStyle::fg_color((5, 120, 240)))));
|
||||
}
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("PosInt"), dst_tyid: ctx.get_typeid("Type::Lit::Num").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Lit::Char").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
let mut grid = r3vi::buffer::index_hashmap::IndexBuffer::new();
|
||||
|
||||
grid.insert_iter(
|
||||
vec![
|
||||
(Point2::new(0,0), crate::terminal::make_label("'")),
|
||||
(Point2::new(1,0), node.view.clone().unwrap()),
|
||||
(Point2::new(2,0), crate::terminal::make_label("'")),
|
||||
]
|
||||
);
|
||||
|
||||
node.close_char.set(Some('\''));
|
||||
node.view = Some(
|
||||
grid.get_port()
|
||||
.flatten()
|
||||
);
|
||||
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_node_ctor("Type", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
||||
Some(TypeTermEditor::new_node(ctx, depth))
|
||||
}));
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
mod ctx;
|
||||
|
||||
pub use ctx::init_ctx;
|
||||
|
||||
use {
|
||||
r3vi::{
|
||||
buffer::singleton::*,
|
||||
|
@ -19,7 +23,7 @@ use {
|
|||
};
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
enum State {
|
||||
pub enum State {
|
||||
Any,
|
||||
Num,
|
||||
Char,
|
||||
|
@ -45,104 +49,6 @@ pub struct TypeTermEditor {
|
|||
}
|
||||
|
||||
impl TypeTermEditor {
|
||||
pub fn init_ctx(ctx: &mut Context) {
|
||||
ctx.add_list_typename("Type".into()); // = Lit | Sym | App | Ladder
|
||||
ctx.add_list_typename("Type::Lit".into()); // = Num | char
|
||||
ctx.add_list_typename("Type::Lit::Num".into()); // [0-9]*
|
||||
ctx.add_list_typename("Type::Lit::Char".into()); // .
|
||||
ctx.add_list_typename("Type::Sym".into()); // = Fun | Var
|
||||
ctx.add_list_typename("Type::Sym::Fun".into()); // [a-zA-Z][a-zA-Z0-9]*
|
||||
ctx.add_list_typename("Type::Sym::Var".into()); // [a-zA-Z][a-zA-Z0-9]*
|
||||
ctx.add_list_typename("Type::App".into()); // = <T1 T2 ...>
|
||||
ctx.add_list_typename("Type::Ladder".into()); // = T1~T2~...
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type").unwrap() },
|
||||
Arc::new(move |mut node, _dst_type:_| {
|
||||
let mut new_node = TypeTermEditor::with_node( node.ctx.clone(), node.depth.get(), node.clone(), State::Any );
|
||||
Some(new_node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Ladder").unwrap() },
|
||||
Arc::new(|mut node, _dst_type: _| {
|
||||
PTYListController::for_node( &mut node, Some('~'), None );
|
||||
PTYListStyle::for_node( &mut node, ("","~","") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::App").unwrap() },
|
||||
Arc::new( |mut node, _dst_type: _| {
|
||||
PTYListController::for_node( &mut node, Some(' '), Some('>') );
|
||||
PTYListStyle::for_node( &mut node, ("<"," ",">") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Sym").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Sym::Fun").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Sym::Var").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
|
||||
// display variables blue color
|
||||
if let Some(v) = node.view {
|
||||
node.view = Some(
|
||||
v.map_item(|i,p| p.add_style_front(TerminalStyle::fg_color((5, 120, 240)))));
|
||||
}
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("PosInt"), dst_tyid: ctx.get_typeid("Type::Lit::Num").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Lit::Char").unwrap() },
|
||||
Arc::new(|mut node, _dst_type:_| {
|
||||
let mut grid = r3vi::buffer::index_hashmap::IndexBuffer::new();
|
||||
|
||||
grid.insert_iter(
|
||||
vec![
|
||||
(Point2::new(0,0), crate::terminal::make_label("'")),
|
||||
(Point2::new(1,0), node.view.clone().unwrap()),
|
||||
(Point2::new(2,0), crate::terminal::make_label("'")),
|
||||
]
|
||||
);
|
||||
|
||||
node.close_char.set(Some('\''));
|
||||
node.view = Some(
|
||||
grid.get_port()
|
||||
.flatten()
|
||||
);
|
||||
|
||||
Some(node)
|
||||
}));
|
||||
|
||||
ctx.add_node_ctor("Type", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
||||
Some(TypeTermEditor::new_node(ctx, depth))
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn from_type_term(ctx: Arc<RwLock<Context>>, depth: usize, term: &TypeTerm) -> NestedNode {
|
||||
let mut node = TypeTermEditor::new_node(ctx.clone(), depth);
|
||||
node.goto(TreeCursor::home());
|
|
@ -115,6 +115,25 @@ pub struct Context {
|
|||
parent: Option<Arc<RwLock<Context>>>,
|
||||
}
|
||||
|
||||
impl Default for Context {
|
||||
fn default() -> Context {
|
||||
let mut ctx = Context::new();
|
||||
|
||||
ctx.add_list_typename("Seq".into());
|
||||
ctx.add_list_typename("Sequence".into());
|
||||
ctx.add_list_typename("SepSeq".into());
|
||||
ctx.add_typename("NestedNode".into());
|
||||
ctx.add_typename("TerminalEvent".into());
|
||||
|
||||
crate::editors::list::init_ctx( &mut ctx );
|
||||
crate::editors::char::init_ctx( &mut ctx );
|
||||
crate::editors::integer::init_ctx( &mut ctx );
|
||||
crate::editors::typeterm::init_ctx( &mut ctx );
|
||||
|
||||
ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<TypeTerm> for (&Arc<RwLock<Context>>, &str) {
|
||||
fn into(self) -> TypeTerm {
|
||||
self.0.read().unwrap().type_term_from_str(self.1).expect("could not parse type term")
|
||||
|
@ -396,3 +415,4 @@ impl Context {
|
|||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
|
|
|
@ -1,152 +0,0 @@
|
|||
use {
|
||||
crate::{
|
||||
type_system::{Context, TypeTerm, ReprTree},
|
||||
editors::{
|
||||
char::*,
|
||||
list::*,
|
||||
integer::*,
|
||||
product::*
|
||||
},
|
||||
tree::{NestedNode},
|
||||
diagnostics::{Diagnostics},
|
||||
type_system::{MorphismTypePattern},
|
||||
},
|
||||
std::sync::{Arc, RwLock},
|
||||
cgmath::Point2
|
||||
};
|
||||
|
||||
pub fn init_mem_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
||||
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
||||
|
||||
ctx.write().unwrap().add_node_ctor(
|
||||
"Vec", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
||||
match ty {
|
||||
TypeTerm::App(args) => {
|
||||
if args.len() > 1 {
|
||||
let buf = r3vi::buffer::vec::VecBuffer::<char>::new();
|
||||
let data = ReprTree::new_leaf(
|
||||
ctx.read().unwrap().type_term_from_str("( Char )").unwrap(),
|
||||
buf.get_port().into()
|
||||
);
|
||||
|
||||
Some(
|
||||
NestedNode::new(ctx, data, depth)
|
||||
.set_editor(Arc::new(RwLock::new(buf)))
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
ctx
|
||||
}
|
||||
|
||||
pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
||||
let ctx0 = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
||||
|
||||
ListEditor::init_ctx( &ctx0 );
|
||||
|
||||
let mut ctx = ctx0.write().unwrap();
|
||||
// TODO:: CharEditor::init_ctx( &ctx );
|
||||
|
||||
ctx.add_node_ctor(
|
||||
"Char", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, _depth: usize| {
|
||||
Some(CharEditor::new_node(ctx))
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
ctx.add_list_typename("Seq".into());
|
||||
ctx.add_list_typename("Sequence".into());
|
||||
ctx.add_list_typename("SepSeq".into());
|
||||
ctx.add_typename("NestedNode".into());
|
||||
|
||||
ctx.add_list_typename("Symbol".into());
|
||||
let pattern = MorphismTypePattern {
|
||||
src_tyid: ctx.get_typeid("List"),
|
||||
dst_tyid: ctx.get_typeid("Symbol").unwrap()
|
||||
};
|
||||
ctx.add_morphism(pattern,
|
||||
Arc::new(
|
||||
|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, None, None );
|
||||
PTYListStyle::for_node( &mut node, ("","","") );
|
||||
|
||||
Some(node)
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
ctx.add_node_ctor(
|
||||
"Symbol", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: usize| {
|
||||
let mut node = Context::make_node(
|
||||
&ctx,
|
||||
(&ctx, "( List Char )").into(),
|
||||
depth+1
|
||||
).expect("nested node");
|
||||
|
||||
node = node.morph(dst_typ);
|
||||
|
||||
Some(node)
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
ctx.add_list_typename("String".into());
|
||||
let pattern = MorphismTypePattern {
|
||||
src_tyid: ctx.get_typeid("List"),
|
||||
dst_tyid: ctx.get_typeid("String").unwrap()
|
||||
};
|
||||
ctx.add_morphism(pattern,
|
||||
Arc::new(
|
||||
|mut node, _dst_type:_| {
|
||||
PTYListController::for_node( &mut node, None, Some('\"') );
|
||||
PTYListStyle::for_node( &mut node, ("\"","","\"") );
|
||||
Some(node)
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
ctx.add_node_ctor(
|
||||
"String", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: usize| {
|
||||
let mut node = Context::make_node(
|
||||
&ctx,
|
||||
TypeTerm::App(vec![
|
||||
TypeTerm::TypeID(ctx.read().unwrap().get_typeid("List").unwrap()),
|
||||
TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap())
|
||||
]),
|
||||
depth+1
|
||||
).unwrap();
|
||||
|
||||
node = node.morph(dst_typ);
|
||||
|
||||
Some(node)
|
||||
}
|
||||
)
|
||||
);
|
||||
/*
|
||||
ctx.add_list_typename("TypeTerm".into());
|
||||
ctx.add_node_ctor(
|
||||
"TypeTerm", Arc::new(
|
||||
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
||||
Some(TypeTermEditor::new(ctx, depth).into_node(depth))
|
||||
}
|
||||
)
|
||||
);
|
||||
*/
|
||||
ctx.add_typename("TerminalEvent".into());
|
||||
|
||||
drop(ctx);
|
||||
ctx0
|
||||
}
|
||||
|
||||
|
|
@ -4,15 +4,12 @@ pub mod dict;
|
|||
pub mod term;
|
||||
//pub mod ladder;
|
||||
pub mod repr_tree;
|
||||
pub mod make_editor;
|
||||
pub mod editor;
|
||||
|
||||
pub use {
|
||||
dict::*,
|
||||
// ladder::*,
|
||||
repr_tree::*,
|
||||
term::*,
|
||||
context::{Context, MorphismMode, MorphismType, MorphismTypePattern},
|
||||
make_editor::*
|
||||
context::{Context, MorphismMode, MorphismType, MorphismTypePattern}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue