context: add add_synonym

This commit is contained in:
Michael Sippel 2023-09-04 06:17:14 +02:00
parent 40500aa60e
commit e5d824c808
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 17 additions and 7 deletions

View file

@ -119,11 +119,11 @@ 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());
ctx.add_list_typename("Sequence");
ctx.add_synonym("Seq", "Sequence");
ctx.add_list_typename("SepSeq");
ctx.add_typename("NestedNode");
ctx.add_typename("TerminalEvent");
crate::editors::list::init_ctx( &mut ctx );
crate::editors::char::init_ctx( &mut ctx );
@ -181,8 +181,12 @@ impl Context {
self.type_dict.write().unwrap().add_varname(vn.to_string())
}
pub fn add_list_typename(&mut self, tn: String) {
let tid = self.add_typename(&tn);
pub fn add_synonym(&mut self, new: &str, old: &str) {
self.type_dict.write().unwrap().add_synonym(new.to_string(), old.to_string());
}
pub fn add_list_typename(&mut self, tn: &str) {
let tid = self.add_typename(tn);
self.list_types.push( tid );
}

View file

@ -46,6 +46,12 @@ impl TypeDict {
tyid
}
pub fn add_synonym(&mut self, new: String, old: String) {
if let Some(tyid) = self.get_typeid(&old) {
self.typenames.insert(new, tyid);
}
}
pub fn get_typename(&self, tid: &TypeID) -> Option<String> {
self.typenames.my.get(tid).cloned()
}