From e5d824c808867d5a208cdf635f0ae2fbb638eb7d Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 4 Sep 2023 06:17:14 +0200 Subject: [PATCH] context: add add_synonym --- nested/src/type_system/context.rs | 18 +++++++++++------- nested/src/type_system/dict.rs | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/nested/src/type_system/context.rs b/nested/src/type_system/context.rs index f302637..c6a6df6 100644 --- a/nested/src/type_system/context.rs +++ b/nested/src/type_system/context.rs @@ -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 ); } diff --git a/nested/src/type_system/dict.rs b/nested/src/type_system/dict.rs index 1832af2..b8fd44c 100644 --- a/nested/src/type_system/dict.rs +++ b/nested/src/type_system/dict.rs @@ -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 { self.typenames.my.get(tid).cloned() }