81 lines
2.6 KiB
Rust
81 lines
2.6 KiB
Rust
#![allow(mixed_script_confusables)]
|
|
|
|
mod morphism;
|
|
mod parser;
|
|
mod c_gen;
|
|
|
|
use {
|
|
ariadne::{Color, Label, Report, ReportKind, Source},
|
|
chumsky::prelude::*,
|
|
laddertypes::{
|
|
parser::ParseLadderType, BimapTypeDict, MorphismType
|
|
},
|
|
std::sync::{Arc, RwLock},
|
|
tiny_ansi::TinyAnsi,
|
|
|
|
|
|
crate::{
|
|
morphism::LdmcMorphism,
|
|
parser::morphism_base_parser,
|
|
}
|
|
};
|
|
|
|
fn main() {
|
|
let mut type_dict = Arc::new(RwLock::new(BimapTypeDict::new()));
|
|
let mut morphism_base = laddertypes::MorphismBase::<LdmcMorphism>::new(vec![
|
|
//type_dict.parse("Seq~MsbCont").expect(""),
|
|
//type_dict.parse("Seq~<ValueTerminated '\\0'>").expect(""),
|
|
type_dict.parse("Seq~<LengthPrefix native.UInt64>").expect("")
|
|
]);
|
|
|
|
let mut args = std::env::args().skip(1);
|
|
let src_type_arg = args.next().expect("src type expected");
|
|
let dst_type_arg = args.next().expect("dst type expected");
|
|
|
|
for mb_path in args {
|
|
let src = std::fs::read_to_string(mb_path.clone()).expect("read");
|
|
let result = morphism_base_parser(type_dict.clone()).parse(src.clone());
|
|
match result {
|
|
Ok((includes, morphisms)) => {
|
|
eprintln!("[{}] parse ok.", mb_path.bright_yellow());
|
|
println!("{}", includes);
|
|
for m in morphisms {
|
|
morphism_base.add_morphism(LdmcMorphism::Primitive(m));
|
|
}
|
|
}
|
|
Err(errs) => {
|
|
errs.into_iter().for_each(|e| {
|
|
Report::build(ReportKind::Error, (), e.span().start)
|
|
.with_message(e.to_string())
|
|
.with_label(
|
|
Label::new(e.span())
|
|
.with_message(e)
|
|
.with_color(Color::Red),
|
|
)
|
|
.finish()
|
|
.print(Source::from(&src))
|
|
.unwrap()
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
let src_type = type_dict.parse( src_type_arg.as_str() ).expect("");
|
|
let dst_type = type_dict.parse( dst_type_arg.as_str() ).expect("");
|
|
|
|
let path = morphism_base.find_morphism_path(MorphismType {
|
|
src_type: src_type.clone(),
|
|
dst_type: dst_type.clone(),
|
|
});
|
|
|
|
match path {
|
|
Some(path) => {
|
|
c_gen::generate_main(&mut type_dict, path, src_type, dst_type);
|
|
}
|
|
None => {
|
|
eprintln!("Error: could not find morphism path");
|
|
std::process::exit(-1);
|
|
}
|
|
}
|
|
}
|