improve encode_type_to_symbol to handle complex types

This commit is contained in:
Michael Sippel 2025-03-15 18:22:46 +01:00
parent 186c12fc5d
commit ffd190890d
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -96,9 +96,31 @@ struct LdmcPrimCMorphism {
fn encode_type_to_symbol(dict: &mut impl TypeDict, t: &laddertypes::TypeTerm)-> String {
match t {
laddertypes::TypeTerm::Char(c) => {
format!("{}", (*c as u64))
match c {
'.' => format!("_dot_"),
_ =>
format!("{}", (*c as u64))
}
},
t => dict.unparse(t)
laddertypes::TypeTerm::Num(n) => {
format!("{}", n)
}
laddertypes::TypeTerm::TypeID(ty_id) => {
if let Some(name) = dict.get_typename(ty_id) {
format!("{}", name.replace(".", "_dot_"))
} else {
format!("")
}
}
laddertypes::TypeTerm::Ladder(rs) |
laddertypes::TypeTerm::App(rs) => {
let mut s = String::new();
for r in rs {
s.push('_');
s.push_str(&encode_type_to_symbol(dict, r));
}
s
}
}
}