2022-05-08 23:30:49 +02:00
|
|
|
use {
|
|
|
|
crate::{
|
2023-01-02 13:18:55 +01:00
|
|
|
type_system::{TypeTerm, Context},
|
2022-12-19 11:26:07 +01:00
|
|
|
integer::{DigitEditor, PosIntEditor},
|
2022-12-18 01:39:01 +01:00
|
|
|
list::{PTYListEditor},
|
2022-06-19 23:13:21 +02:00
|
|
|
sequence::{decorator::{SeqDecorStyle}},
|
2022-11-18 00:21:29 +01:00
|
|
|
sum::SumEditor,
|
2022-11-13 15:26:25 +01:00
|
|
|
char_editor::CharEditor,
|
2022-12-19 11:26:07 +01:00
|
|
|
type_term_editor::TypeTermEditor,
|
2022-11-13 15:26:25 +01:00
|
|
|
Nested
|
2022-05-08 23:30:49 +02:00
|
|
|
},
|
2022-06-19 23:13:21 +02:00
|
|
|
std::sync::{Arc, RwLock},
|
2022-05-08 23:30:49 +02:00
|
|
|
};
|
|
|
|
|
2023-01-02 13:18:55 +01:00
|
|
|
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_typename("Vec".into());
|
|
|
|
|
|
|
|
ctx
|
|
|
|
}
|
|
|
|
|
2022-11-19 01:45:57 +01:00
|
|
|
pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
2022-12-18 01:39:01 +01:00
|
|
|
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
2022-11-18 00:21:29 +01:00
|
|
|
|
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
"Char", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, _depth: usize| {
|
2022-12-19 11:26:07 +01:00
|
|
|
Some(CharEditor::new_node(&ctx))
|
2022-11-18 00:21:29 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2022-11-19 01:45:57 +01:00
|
|
|
|
2022-11-18 00:21:29 +01:00
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
"List", Arc::new(
|
|
|
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
2022-11-18 00:21:29 +01:00
|
|
|
match ty {
|
|
|
|
TypeTerm::Type {
|
2022-12-18 01:39:01 +01:00
|
|
|
id: _, args
|
2022-11-18 00:21:29 +01:00
|
|
|
} => {
|
|
|
|
if args.len() > 0 {
|
2022-12-18 01:20:17 +01:00
|
|
|
// todo: factor style out of type arGS
|
2022-11-18 00:21:29 +01:00
|
|
|
let style = if args.len() > 1 {
|
|
|
|
match args[1] {
|
|
|
|
TypeTerm::Num(0) => SeqDecorStyle::Plain,
|
|
|
|
TypeTerm::Num(1) => SeqDecorStyle::HorizontalSexpr,
|
|
|
|
TypeTerm::Num(2) => SeqDecorStyle::VerticalSexpr,
|
|
|
|
TypeTerm::Num(3) => SeqDecorStyle::DoubleQuote,
|
|
|
|
TypeTerm::Num(4) => SeqDecorStyle::Tuple,
|
|
|
|
TypeTerm::Num(5) => SeqDecorStyle::EnumSet,
|
|
|
|
TypeTerm::Num(6) => SeqDecorStyle::Path,
|
|
|
|
_ => SeqDecorStyle::HorizontalSexpr
|
|
|
|
}
|
2022-12-18 01:20:17 +01:00
|
|
|
} else {
|
2022-11-18 00:21:29 +01:00
|
|
|
SeqDecorStyle::HorizontalSexpr
|
|
|
|
};
|
|
|
|
|
|
|
|
let delim = if args.len() > 1 {
|
|
|
|
match args[1] {
|
2022-12-19 11:26:07 +01:00
|
|
|
TypeTerm::Num(0) => None,
|
2022-12-18 01:20:17 +01:00
|
|
|
TypeTerm::Num(1) => Some(' '),
|
|
|
|
TypeTerm::Num(2) => Some('\n'),
|
|
|
|
TypeTerm::Num(3) => None,
|
|
|
|
TypeTerm::Num(4) => Some(','),
|
|
|
|
TypeTerm::Num(5) => Some(','),
|
|
|
|
TypeTerm::Num(6) => Some('/'),
|
|
|
|
_ => None
|
2022-11-18 00:21:29 +01:00
|
|
|
}
|
|
|
|
}else {
|
2022-12-18 01:20:17 +01:00
|
|
|
None
|
2022-11-18 00:21:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Some(
|
2022-12-19 11:26:07 +01:00
|
|
|
PTYListEditor::new(
|
|
|
|
ctx.clone(),
|
|
|
|
args[0].clone(),
|
2022-11-18 00:21:29 +01:00
|
|
|
style,
|
|
|
|
delim,
|
|
|
|
depth
|
2022-12-19 11:26:07 +01:00
|
|
|
).into_node()
|
2022-11-18 00:21:29 +01:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2022-10-14 23:42:35 +02:00
|
|
|
}
|
2022-11-18 00:21:29 +01:00
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
2022-11-19 01:45:57 +01:00
|
|
|
)
|
|
|
|
);
|
2022-11-18 00:21:29 +01:00
|
|
|
|
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
"Symbol", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2022-11-19 01:45:57 +01:00
|
|
|
Context::make_editor(
|
2022-12-19 11:26:07 +01:00
|
|
|
&ctx,
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx.read().unwrap().type_term_from_str("( List Char 0 )").unwrap(),
|
2022-11-18 00:21:29 +01:00
|
|
|
depth
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2022-11-19 01:45:57 +01:00
|
|
|
|
2022-11-18 00:21:29 +01:00
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
"String", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2022-11-19 01:45:57 +01:00
|
|
|
Context::make_editor(
|
2022-12-19 11:26:07 +01:00
|
|
|
&ctx,
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx.read().unwrap().type_term_from_str("( List Char 3 )").unwrap(),
|
|
|
|
depth
|
2022-11-18 00:21:29 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2022-11-19 01:45:57 +01:00
|
|
|
|
2022-11-18 00:21:29 +01:00
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
"TypeTerm", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2022-12-19 11:26:07 +01:00
|
|
|
Some(TypeTermEditor::new(ctx, depth).into_node())
|
2022-11-18 00:21:29 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2022-12-18 01:20:17 +01:00
|
|
|
|
|
|
|
ctx.write().unwrap().add_typename("TerminalEvent".into());
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
2022-12-18 01:39:01 +01:00
|
|
|
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
2022-11-19 01:45:57 +01:00
|
|
|
|
2022-12-18 01:20:17 +01:00
|
|
|
ctx.write().unwrap().add_typename("MachineInt".into());
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx.write().unwrap().add_typename("BigEndian".into());
|
2022-12-19 11:26:07 +01:00
|
|
|
|
|
|
|
//ctx.write().unwrap().add_typename("Digit".into());
|
|
|
|
|
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
|
|
|
"Digit", Arc::new(
|
|
|
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, _depth: usize| {
|
|
|
|
match ty {
|
|
|
|
TypeTerm::Type {
|
|
|
|
id: _, args
|
|
|
|
} => {
|
|
|
|
if args.len() > 0 {
|
|
|
|
match args[0] {
|
|
|
|
TypeTerm::Num(radix) => {
|
|
|
|
Some(
|
|
|
|
DigitEditor::new(ctx.clone(), radix as u32).into_node()
|
|
|
|
)
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
|
|
|
"PosInt", Arc::new(
|
2022-12-19 11:26:07 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, _depth: usize| {
|
2022-11-19 01:45:57 +01:00
|
|
|
match ty {
|
|
|
|
TypeTerm::Type {
|
2022-12-18 01:39:01 +01:00
|
|
|
id: _, args
|
2022-11-19 01:45:57 +01:00
|
|
|
} => {
|
|
|
|
if args.len() > 0 {
|
|
|
|
match args[0] {
|
|
|
|
TypeTerm::Num(radix) => {
|
|
|
|
Some(
|
2022-12-19 11:26:07 +01:00
|
|
|
PosIntEditor::new(ctx.clone(), radix as u32).into_node()
|
2022-11-19 01:45:57 +01:00
|
|
|
)
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2022-11-18 00:21:29 +01:00
|
|
|
|
|
|
|
ctx
|
2022-05-08 23:30:49 +02:00
|
|
|
}
|
|
|
|
|
2022-11-19 01:45:57 +01:00
|
|
|
pub fn init_os_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
2022-12-18 01:39:01 +01:00
|
|
|
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
2022-11-19 01:45:57 +01:00
|
|
|
|
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
|
|
|
"PathSegment", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2022-11-19 01:45:57 +01:00
|
|
|
Context::make_editor(
|
2022-12-19 11:26:07 +01:00
|
|
|
&ctx,
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx.read().unwrap().type_term_from_str("( List Char 0 )").unwrap(),
|
|
|
|
depth
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
ctx.write().unwrap().add_editor_ctor(
|
|
|
|
"Path", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2022-11-19 01:45:57 +01:00
|
|
|
Context::make_editor(
|
2022-12-19 11:26:07 +01:00
|
|
|
&ctx,
|
2022-11-19 01:45:57 +01:00
|
|
|
ctx.read().unwrap().type_term_from_str("( List PathSegment 6 )").unwrap(),
|
|
|
|
depth+1
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
ctx
|
|
|
|
}
|
2022-05-08 23:30:49 +02:00
|
|
|
|
2022-11-18 00:21:29 +01:00
|
|
|
|