2023-09-08 13:40:06 +02:00
|
|
|
|
|
2023-08-18 00:16:16 +02:00
|
|
|
|
use {
|
2023-09-08 13:40:06 +02:00
|
|
|
|
r3vi::{
|
|
|
|
|
view::{OuterViewPort, singleton::*}
|
|
|
|
|
},
|
2023-11-12 18:07:20 +01:00
|
|
|
|
laddertypes::{TypeTerm},
|
2023-08-18 00:16:16 +02:00
|
|
|
|
crate::{
|
2023-11-28 20:52:25 +01:00
|
|
|
|
repr_tree::{Context},
|
|
|
|
|
repr_tree::{MorphismTypePattern},
|
2023-08-18 00:16:16 +02:00
|
|
|
|
editors::{
|
|
|
|
|
list::*,
|
2023-08-21 16:31:44 +02:00
|
|
|
|
integer::*
|
2023-08-18 00:16:16 +02:00
|
|
|
|
},
|
|
|
|
|
},
|
2023-08-21 16:31:44 +02:00
|
|
|
|
std::sync::{Arc, RwLock}
|
2023-08-18 00:16:16 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-08-21 15:49:07 +02:00
|
|
|
|
pub fn init_ctx(ctx: &mut Context) {
|
2023-08-18 00:16:16 +02:00
|
|
|
|
ctx.add_typename("MachineInt".into());
|
|
|
|
|
ctx.add_typename("u32".into());
|
|
|
|
|
ctx.add_typename("u64".into());
|
|
|
|
|
ctx.add_typename("LittleEndian".into());
|
|
|
|
|
ctx.add_typename("BigEndian".into());
|
|
|
|
|
|
|
|
|
|
ctx.add_node_ctor(
|
|
|
|
|
"Digit", Arc::new(
|
2023-09-08 13:40:06 +02:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
2023-08-18 00:16:16 +02:00
|
|
|
|
match ty {
|
|
|
|
|
TypeTerm::App(args) => {
|
|
|
|
|
if args.len() > 1 {
|
|
|
|
|
match args[1] {
|
|
|
|
|
TypeTerm::Num(radix) => {
|
|
|
|
|
let node = DigitEditor::new(ctx.clone(), radix as u32).into_node(depth);
|
|
|
|
|
Some(
|
|
|
|
|
node
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ctx.add_list_typename("PosInt".into());
|
|
|
|
|
let pattern = MorphismTypePattern {
|
|
|
|
|
src_tyid: ctx.get_typeid("List"),
|
|
|
|
|
dst_tyid: ctx.get_typeid("PosInt").unwrap()
|
|
|
|
|
};
|
|
|
|
|
ctx.add_morphism(pattern,
|
|
|
|
|
Arc::new(
|
|
|
|
|
|mut node, dst_type| {
|
|
|
|
|
// todo: check src_type parameter to be ( Digit radix )
|
|
|
|
|
|
|
|
|
|
match dst_type {
|
|
|
|
|
TypeTerm::App(args) => {
|
|
|
|
|
if args.len() > 1 {
|
|
|
|
|
match args[1] {
|
|
|
|
|
TypeTerm::Num(_radix) => {
|
2023-11-24 21:26:17 +01:00
|
|
|
|
/* FIXME
|
2023-08-18 00:16:16 +02:00
|
|
|
|
PTYListController::for_node(
|
|
|
|
|
&mut node,
|
|
|
|
|
Some(','),
|
|
|
|
|
None,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
PTYListStyle::for_node(
|
|
|
|
|
&mut node,
|
|
|
|
|
("0d", "", "")
|
|
|
|
|
);
|
2023-11-24 21:26:17 +01:00
|
|
|
|
*/
|
2023-08-18 00:16:16 +02:00
|
|
|
|
Some(node)
|
|
|
|
|
},
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ctx.add_node_ctor(
|
|
|
|
|
"PosInt", Arc::new(
|
2023-09-08 13:40:06 +02:00
|
|
|
|
|ctx0: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
2023-08-18 00:16:16 +02:00
|
|
|
|
match dst_typ.clone() {
|
|
|
|
|
TypeTerm::App(args) => {
|
|
|
|
|
if args.len() > 1 {
|
|
|
|
|
match args[1] {
|
|
|
|
|
TypeTerm::Num(radix) => {
|
|
|
|
|
let ctx = ctx0.read().unwrap();
|
|
|
|
|
let mut node = Context::make_node(
|
|
|
|
|
&ctx0,
|
|
|
|
|
TypeTerm::App(vec![
|
|
|
|
|
TypeTerm::TypeID(ctx.get_typeid("List").unwrap()),
|
|
|
|
|
TypeTerm::TypeID(
|
|
|
|
|
ctx.get_typeid("Digit").unwrap()
|
|
|
|
|
)
|
|
|
|
|
.num_arg(radix)
|
|
|
|
|
.clone()
|
|
|
|
|
.into()
|
|
|
|
|
]),
|
2023-09-08 13:40:06 +02:00
|
|
|
|
depth.map(|d| d+1)
|
2023-08-18 00:16:16 +02:00
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
node = node.morph(dst_typ);
|
|
|
|
|
|
|
|
|
|
Some(node)
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ctx.add_typename("Date".into());
|
|
|
|
|
ctx.add_typename("ISO-8601".into());
|
|
|
|
|
ctx.add_typename("TimeSince".into());
|
|
|
|
|
ctx.add_typename("UnixEpoch".into());
|
|
|
|
|
ctx.add_typename("AnnoDomini".into());
|
|
|
|
|
ctx.add_typename("Epoch".into());
|
|
|
|
|
ctx.add_typename("Duration".into());
|
|
|
|
|
ctx.add_typename("Seconds".into());
|
|
|
|
|
ctx.add_typename("ℕ".into());
|
|
|
|
|
}
|
|
|
|
|
|