From 9a80044a89500b8d5b55185af9d8ef4959f56914 Mon Sep 17 00:00:00 2001 From: elvis Date: Sun, 24 Aug 2025 03:35:32 +0200 Subject: [PATCH] Finished refactoring --- src/rsprocess/assert/dsl.rs | 119 +++++------ src/rsprocess/assert/fmt.rs | 331 +++++++++++++++++++++++++++---- src/rsprocess/assert/mod.rs | 4 + src/rsprocess/assert/rsassert.rs | 50 +++-- src/rsprocess/assert/tests.rs | 2 +- src/rsprocess/grammar.lalrpop | 191 +++++++++--------- src/rsprocess/graph.rs | 10 +- src/rsprocess/mod.rs | 31 ++- src/rsprocess/presets.rs | 6 +- src/rsprocess/structure.rs | 17 -- src/rsprocess/translator.rs | 51 +---- 11 files changed, 511 insertions(+), 301 deletions(-) delete mode 100644 src/rsprocess/structure.rs diff --git a/src/rsprocess/assert/dsl.rs b/src/rsprocess/assert/dsl.rs index 741edf2..4f5becf 100644 --- a/src/rsprocess/assert/dsl.rs +++ b/src/rsprocess/assert/dsl.rs @@ -7,12 +7,12 @@ use super::super::{translator, graph, set, process, system, label}; /// AssertExpression type IntegerType = i64; -#[derive(Debug, Clone)] -pub struct RSassert { +#[derive(Clone)] +pub struct Assert { pub tree: Tree } -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum Tree { Concat(Box>, Box>), If(Box>, Box>), @@ -22,15 +22,15 @@ pub enum Tree { For(Variable, Range, Box>), } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Clone, PartialEq, Eq, Hash)] pub enum Variable { Id(String), Special(S) } /// Trait needed for special variables. -pub(super) trait SpecialVariables: std::fmt::Display + std::fmt::Debug - + Sized + Eq + Copy + std::hash::Hash +pub(super) trait SpecialVariables: translator::PrintableWithTranslator + + std::fmt::Debug + Sized + Eq + Copy + std::hash::Hash { /// Returns the type of the specific special variable. fn type_of(&self) -> AssertionTypes; @@ -46,7 +46,7 @@ pub(super) trait SpecialVariables: std::fmt::Display + std::fmt::Debug fn correct_type(&self, other: &AssertReturnValue) -> bool; } -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum Expression { True, False, @@ -61,13 +61,13 @@ pub enum Expression { Binary(Binary, Box>, Box>), } -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum Range { IterateOverSet(Box>), IterateInRange(Box>, Box>), } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum Unary { Not, Rand, @@ -79,7 +79,7 @@ pub enum Unary { Qualifier(Qualifier), } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum QualifierRestricted { Entities, Context, @@ -90,32 +90,32 @@ pub enum QualifierRestricted { Products, } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum QualifierLabel { AvailableEntities, AllReactants, AllInhibitors, } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum QualifierSystem { Entities, Context, } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum QualifierEdge { Source, Target, } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum QualifierNode { Neighbours, System, } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum Qualifier { System(QualifierSystem), Label(QualifierLabel), @@ -124,7 +124,7 @@ pub enum Qualifier { Node(QualifierNode), } -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] pub enum Binary { And, Or, @@ -149,7 +149,7 @@ pub enum Binary { CommonSubStr, } -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq)] pub(super) enum AssertionTypes { Boolean, Integer, @@ -168,7 +168,7 @@ pub(super) enum AssertionTypes { Edge, } -#[derive(Debug, Clone, Hash, PartialEq, Eq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub enum AssertReturnValue { Boolean(bool), Integer(IntegerType), @@ -335,7 +335,7 @@ impl Unary { }, (op, type_exp) => { Err(format!("Expression has incompatible type with operation: \ - {type_exp} with operation {op}.")) + {type_exp:?} with operation {op:?}.")) } } } @@ -473,8 +473,8 @@ impl Binary { Ok(AssertionTypes::String) }, _ => { - Err(format!("Expressions have incompatible types: {t1} and \ - {t2} with operation {self}.")) + Err(format!("Expressions have incompatible types: {t1:?} and \ + {t2:?} with operation {self:?}.")) } } } @@ -492,7 +492,8 @@ impl AssertReturnValue { Ok(()) }, (s, q, val) => { - Err(format!("Cannot assign {val} to {s} with qualifier {q}")) + Err(format!("Cannot assign {val:?} to {s:?} with qualifier \ + {q:?}")) } } } @@ -530,8 +531,8 @@ impl TypeContext { if ty_return == ty { Ok(()) } else { - Err(format!("Return statements don't agree: {ty_return} and \ - {ty} found.")) + Err(format!("Return statements don't agree: {ty_return:?} and \ + {ty:?} found.")) } } else { self.return_ty = Some(ty); @@ -556,8 +557,8 @@ impl TypeContext { (Variable::Id(v), Some(q)) => { match self.data.entry(v.clone()) { std::collections::hash_map::Entry::Vacant(_ve) => { - Err(format!("Variable {v} as no assignment while \ - trying to assign to qualification {q}, \ + Err(format!("Variable {v:?} as no assignment while \ + trying to assign to qualification {q:?}, \ assign first a value.")) }, std::collections::hash_map::Entry::Occupied(oe) => { @@ -568,9 +569,9 @@ impl TypeContext { Ok(()) }, (t, q, ty) => { - Err(format!("Variable {v} has type {t}, but \ - was assigned with qualifier {q} \ - value with type {ty}")) + Err(format!("Variable {v:?} has type {t:?}, \ + but was assigned with qualifier \ + {q:?} value with type {ty:?}.")) } } } @@ -580,17 +581,18 @@ impl TypeContext { if s.type_of() == ty { Ok(()) } else { - Err(format!("Variable {s} has type {} but was \ - assigned a value of type {ty}.", s.type_of())) + Err(format!("Variable {s:?} has type {:?} but was \ + assigned a value of type {ty:?}.", + s.type_of())) } }, (Variable::Special(s), Some(q)) => { if s.type_qualified(q)? == ty { Ok(()) } else { - Err(format!("Variable {s} has type {} but was \ - assigned a value of type {ty} with qualifier \ - {q}.", s.type_of())) + Err(format!("Variable {s:?} has type {:?} but was \ + assigned a value of type {ty:?} with \ + qualifier {q:?}.", s.type_of())) } } } @@ -604,7 +606,7 @@ impl TypeContext { where S: SpecialVariables { let v = match v { Variable::Special(s) => - return Err(format!("Protected word {s} used in for \ + return Err(format!("Protected word {s:?} used in for \ assignment.")), Variable::Id(v) => v }; @@ -622,7 +624,7 @@ impl TypeContext { Ok(()) }, _ => { - Err(format!("Range has incorrect type {ty}.")) + Err(format!("Range has incorrect type {ty:?}.")) }, } } @@ -640,7 +642,7 @@ impl TypeContext { if let Some(ty) = self.data.get(v) { Ok(*ty) } else { - Err(format!("Could not find variable {v}.")) + Err(format!("Could not find variable {v:?}.")) } }, } @@ -671,8 +673,8 @@ impl Context { (Variable::Id(v), Some(q)) => { match self.data.entry(v.clone()) { std::collections::hash_map::Entry::Vacant(_ve) => { - Err(format!("Variable {v} as no assignment while \ - trying to assign to qualification {q}, \ + Err(format!("Variable {v:?} as no assignment while \ + trying to assign to qualification {q:?}, \ assign first a value.")) }, std::collections::hash_map::Entry::Occupied(mut oe) => { @@ -684,9 +686,9 @@ impl Context { Ok(()) }, (val, q, newval) => { - Err(format!("Variable {v} has value {val}, but \ - was assigned with qualifier {q} \ - new value {newval}.")) + Err(format!("Variable {v:?} has value {val:?}, \ + but was assigned with qualifier \ + {q:?} new value {newval:?}.")) } } } @@ -701,16 +703,16 @@ impl Context { } Ok(()) } else { - Err(format!("Trying to assign {val} to variable {s}.")) + Err(format!("Trying to assign {val:?} to variable {s:?}.")) } }, (Variable::Special(s), Some(q)) => { if let Some(s) = self.special.get_mut(s) { s.assign_qualified(*q, val) } else { - Err(format!("Trying to assign {val} to variable {s} with \ - qualifier {q} but no value for {val} was found\ - .")) + Err(format!("Trying to assign {val:?} to variable {s:?} \ + with qualifier {q:?} but no value for {val:?} \ + was found.")) } } } @@ -725,12 +727,14 @@ impl Context { Variable::Id(var) => { self.data.get(var) .cloned() - .ok_or(format!("Variable {v} used, but no value assigned.")) + .ok_or(format!("Variable {v:?} used, but no value \ + assigned.")) }, Variable::Special(s) => { self.special.get(s) .cloned() - .ok_or(format!("Variable {v} used but no value assigned.")) + .ok_or(format!("Variable {v:?} used but no value \ + assigned.")) }, } } @@ -771,7 +775,7 @@ impl AssertReturnValue { (AssertReturnValue::Element(el), Unary::ToStr) => { Ok(AssertReturnValue::String( translator.decode(el).ok_or( - format!("Could not find element {el}.") + format!("Could not find element {el:?}.") )? )) }, @@ -811,7 +815,8 @@ impl AssertReturnValue { Ok(q.get(&sys)) } (val, u) => { - Err(format!("Incompatible unary operation {u} on value {val}.")) + Err(format!("Incompatible unary operation {u:?} on value \ + {val:?}.")) } } } @@ -897,8 +902,8 @@ impl AssertReturnValue { String(s) }, (b, val1, val2) => - return Err(format!("Operation {b} on values {val1} and {val2} \ - could not be executed.")) + return Err(format!("Operation {b:?} on values {val1:?} and \ + {val2:?} could not be executed.")) }) } } @@ -1008,7 +1013,7 @@ where S: SpecialVariables { Ok(AssertionTypes::RangeInteger) } else { Err(format!("Expressions in range are not integers, but are: \ - {type_exp1} and {type_exp2}.")) + {type_exp1:?} and {type_exp2:?}.")) } }, Range::IterateOverSet(exp) => { @@ -1019,7 +1024,7 @@ where S: SpecialVariables { AssertionTypes::RangeNeighbours => Ok(AssertionTypes::RangeNeighbours), _ => Err(format!("Expressions in range is not a set or \ - neighbours of a node, but is: {type_exp}.")) + neighbours of a node, but is: {type_exp:?}.")) } } } @@ -1106,7 +1111,7 @@ where S: SpecialVariables { .collect::>() .into_iter()) } - _ => Err(format!("{val} is not a set in for cycle.")) + _ => Err(format!("{val:?} is not a set in for cycle.")) } }, Range::IterateInRange(exp1, exp2) => { @@ -1118,8 +1123,8 @@ where S: SpecialVariables { Ok((i1..i2).map(AssertReturnValue::Integer) .collect::>().into_iter()), (val1, val2) => - Err(format!("{val1}..{val2} is not a valid integer range \ - in for cycle.")) + Err(format!("{val1:?}..{val2:?} is not a valid integer \ + range in for cycle.")) } } } diff --git a/src/rsprocess/assert/fmt.rs b/src/rsprocess/assert/fmt.rs index 8437702..a4c3545 100644 --- a/src/rsprocess/assert/fmt.rs +++ b/src/rsprocess/assert/fmt.rs @@ -3,44 +3,47 @@ // ----------------------------------------------------------------------------- use std::fmt; use super::dsl::*; +use super::super::translator::{Formatter, PrintableWithTranslator, Translator}; -impl fmt::Display for RSassert where S: fmt::Display { +impl fmt::Debug for Assert where S: fmt::Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "label {{\n{}\n}}", self.tree) + write!(f, "label {{\n{:?}\n}}", self.tree) } } -impl fmt::Display for Tree where S: fmt::Display { +impl fmt::Debug for Tree where S: fmt::Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Concat(t1, t2) => {write!(f, "{t1};\n{t2}")}, - Self::If(exp, t) => {write!(f, "if {exp} {{\n{t}\n}}")}, + Self::Concat(t1, t2) => {write!(f, "{t1:?};\n{t2:?}")}, + Self::If(exp, t) => {write!(f, "if {exp:?} {{\n{t:?}\n}}")}, Self::IfElse(exp, t1, t2) => { - write!(f, "if {exp} {{\n{t1}\n}} else {{\n{t2}\n}}") + write!(f, "if {exp:?} {{\n{t1:?}\n}} else {{\n{t2:?}\n}}") }, Self::Assignment(v, q, exp) => { if let Some(q) = q { - write!(f, "{v}.{q} = {exp}") + write!(f, "{v:?}.{q:?} = {exp:?}") } else { - write!(f, "{v} = {exp}") + write!(f, "{v:?} = {exp:?}") } }, - Self::Return(exp) => {write!(f, "return {exp}")}, - Self::For(v, r, t) => {write!(f, "for {v} in {r} {{\n{t}\n}}")}, + Self::Return(exp) => {write!(f, "return {exp:?}")}, + Self::For(v, r, t) => { + write!(f, "for {v:?} in {r:?} {{\n{t:?}\n}}") + }, } } } -impl fmt::Display for Variable where S: fmt::Display { +impl fmt::Debug for Variable where S: fmt::Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Special(s) => {write!(f, "{s}")}, - Self::Id(s) => {write!(f, "{s}")} + Self::Special(s) => {write!(f, "{s:?}")}, + Self::Id(s) => {write!(f, "{s:?}")} } } } -impl fmt::Display for Expression where S: fmt::Display { +impl fmt::Debug for Expression where S: fmt::Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::True => {write!(f, "True")}, @@ -49,24 +52,24 @@ impl fmt::Display for Expression where S: fmt::Display { Self::Label(rslabel) => {write!(f, "{{debug: {rslabel:?}}}")}, Self::Set(set) => {write!(f, "{{debug: {set:?}}}")}, Self::Element(el) => {write!(f, "'{{debug: {el:?}}}'")}, - Self::String(s) => {write!(f, r#""{s}""#)}, - Self::Var(v) => {write!(f, "{v}")}, + Self::String(s) => {write!(f, r#""{s:?}""#)}, + Self::Var(v) => {write!(f, "{v:?}")}, Self::Unary(u, exp) => { if u.is_prefix() { - write!(f, "{u}({exp})") + write!(f, "{u:?}({exp:?})") } else if u.is_suffix() { - write!(f, "{exp}{u}") + write!(f, "{exp:?}{u:?}") } else { unreachable!() } }, Self::Binary(b, exp1, exp2) => { if b.is_prefix() { - write!(f, "{b}({exp1}, {exp2})") + write!(f, "{b:?}({exp1:?}, {exp2:?})") } else if b.is_suffix() { - write!(f, "({exp1}, {exp2}){b}") + write!(f, "({exp1:?}, {exp2:?}){b:?}") } else if b.is_infix() { - write!(f, "({exp1} {b} {exp2})") + write!(f, "({exp1:?} {b:?} {exp2:?})") } else { unreachable!() } @@ -75,16 +78,16 @@ impl fmt::Display for Expression where S: fmt::Display { } } -impl fmt::Display for Range where S: fmt::Display { +impl fmt::Debug for Range where S: fmt::Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::IterateOverSet(exp) => {write!(f, "{{{exp}}}")}, - Self::IterateInRange(exp1, exp2) => {write!(f, "{exp1}..{exp2}")} + Self::IterateOverSet(exp) => write!(f, "{{{exp:?}}}"), + Self::IterateInRange(exp1, exp2) => write!(f, "{exp1:?}..{exp2:?}") } } } -impl fmt::Display for Unary { +impl fmt::Debug for Unary { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Not => write!(f, "not"), @@ -93,12 +96,12 @@ impl fmt::Display for Unary { Self::Length => write!(f, ".length"), Self::ToStr => write!(f, ".tostr"), Self::ToEl => write!(f, ".toel"), - Self::Qualifier(q) => write!(f, ".{q}"), + Self::Qualifier(q) => write!(f, ".{q:?}"), } } } -impl fmt::Display for QualifierRestricted { +impl fmt::Debug for QualifierRestricted { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Entities => write!(f, "Entities"), @@ -112,7 +115,7 @@ impl fmt::Display for QualifierRestricted { } } -impl fmt::Display for QualifierLabel { +impl fmt::Debug for QualifierLabel { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::AvailableEntities => write!(f, "AvailableEntities"), @@ -122,7 +125,7 @@ impl fmt::Display for QualifierLabel { } } -impl fmt::Display for QualifierSystem { +impl fmt::Debug for QualifierSystem { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Context => write!(f, "context"), @@ -131,7 +134,7 @@ impl fmt::Display for QualifierSystem { } } -impl fmt::Display for QualifierEdge { +impl fmt::Debug for QualifierEdge { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Source => write!(f, "source"), @@ -140,7 +143,7 @@ impl fmt::Display for QualifierEdge { } } -impl fmt::Display for QualifierNode { +impl fmt::Debug for QualifierNode { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Neighbours => write!(f, "neighbours"), @@ -149,19 +152,19 @@ impl fmt::Display for QualifierNode { } } -impl fmt::Display for Qualifier { +impl fmt::Debug for Qualifier { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Label(q) => write!(f, "{q}"), - Self::Restricted(q) => write!(f, "{q}"), - Self::System(q) => write!(f, "{q}"), - Self::Edge(q) => write!(f, "{q}"), - Self::Node(q) => write!(f, "{q}"), + Self::Label(q) => write!(f, "{q:?}"), + Self::Restricted(q) => write!(f, "{q:?}"), + Self::System(q) => write!(f, "{q:?}"), + Self::Edge(q) => write!(f, "{q:?}"), + Self::Node(q) => write!(f, "{q:?}"), } } } -impl fmt::Display for Binary { +impl fmt::Debug for Binary { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::And => write!(f, "&&"), @@ -188,12 +191,12 @@ impl fmt::Display for Binary { } } -impl fmt::Display for AssertReturnValue { +impl fmt::Debug for AssertReturnValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Boolean(b) => write!(f, "{b}"), - Self::Integer(i) => write!(f, "{i}"), - Self::String(s) => write!(f, r#""{s}""#), + Self::Boolean(b) => write!(f, "{b:?}"), + Self::Integer(i) => write!(f, "{i:?}"), + Self::String(s) => write!(f, r#""{s:?}""#), Self::Label(l) => write!(f, "{{debug: {l:?}}}"), Self::Set(set) => write!(f, "{{debug: {set:?}}}"), Self::Element(el) => write!(f, "{{debug: {el:?}}}"), @@ -207,7 +210,7 @@ impl fmt::Display for AssertReturnValue { } } -impl fmt::Display for AssertionTypes { +impl fmt::Debug for AssertionTypes { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Boolean => write!(f, "boolean"), @@ -227,3 +230,245 @@ impl fmt::Display for AssertionTypes { } } } + +// ----------------------------------------------------------------------------- + +impl PrintableWithTranslator for Assert +where S: PrintableWithTranslator { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + write!(f, "label {{\n{}\n}}", Formatter::from(translator, &self.tree)) + } +} + + +impl PrintableWithTranslator for Tree +where S: PrintableWithTranslator { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::Concat(t1, t2) => + write!(f, "{};\n{}", + Formatter::from(translator, &**t1), + Formatter::from(translator, &**t2)), + Self::If(exp, t) => + write!(f, "if {} {{\n{}\n}}", + Formatter::from(translator, &**exp), + Formatter::from(translator, &**t)), + Self::IfElse(exp, t1, t2) => { + write!(f, "if {} {{\n{}\n}} else {{\n{}\n}}", + Formatter::from(translator, &**exp), + Formatter::from(translator, &**t1), + Formatter::from(translator, &**t2)) + }, + Self::Assignment(v, q, exp) => { + if let Some(q) = q { + write!(f, "{}.{} = {}", + Formatter::from(translator, v), + Formatter::from(translator, q), + Formatter::from(translator, &**exp)) + } else { + write!(f, "{} = {}", + Formatter::from(translator, v), + Formatter::from(translator, &**exp)) + } + }, + Self::Return(exp) => + write!(f, "return {}", Formatter::from(translator, &**exp)), + Self::For(v, r, t) => { + write!(f, "for {} in {} {{\n{}\n}}", + Formatter::from(translator, v), + Formatter::from(translator, r), + Formatter::from(translator, &**t)) + }, + } + } +} + +impl PrintableWithTranslator for Variable +where S: PrintableWithTranslator { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::Special(s) => write!(f, "{}", Formatter::from(translator, s)), + Self::Id(s) => write!(f, "{s}") + } + } +} + +impl PrintableWithTranslator for Expression +where S: PrintableWithTranslator { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::True => write!(f, "True"), + Self::False => write!(f, "False"), + Self::Integer(i) => write!(f, "{i}"), + Self::Label(l) => + write!(f, "{}", Formatter::from(translator, &**l)), + Self::Set(set) => write!(f, "{}", Formatter::from(translator, set)), + Self::Element(el) => + write!(f, "'{}'", + translator.decode(*el).unwrap_or("Missing".into())), + Self::String(s) => write!(f, r#""{s}""#), + Self::Var(v) => write!(f, "{}", Formatter::from(translator, v)), + Self::Unary(u, exp) => { + if u.is_prefix() { + write!(f, "{}({})", + Formatter::from(translator, u), + Formatter::from(translator, &**exp)) + } else if u.is_suffix() { + write!(f, "{}{}", + Formatter::from(translator, &**exp), + Formatter::from(translator, u)) + } else { + unreachable!() + } + }, + Self::Binary(b, exp1, exp2) => { + if b.is_prefix() { + write!(f, "{}({}, {})", + Formatter::from(translator, b), + Formatter::from(translator, &**exp1), + Formatter::from(translator, &**exp2)) + } else if b.is_suffix() { + write!(f, "({}, {}){}", + Formatter::from(translator, &**exp1), + Formatter::from(translator, &**exp2), + Formatter::from(translator, b)) + } else if b.is_infix() { + write!(f, "({} {} {})", + Formatter::from(translator, &**exp1), + Formatter::from(translator, b), + Formatter::from(translator, &**exp2)) + } else { + unreachable!() + } + }, + } + } +} + +impl PrintableWithTranslator for Range +where S: PrintableWithTranslator { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::IterateOverSet(exp) => + write!(f, "{}", Formatter::from(translator, &**exp)), + Self::IterateInRange(exp1, exp2) => + write!(f, "{}..{}", + Formatter::from(translator, &**exp1), + Formatter::from(translator, &**exp2)) + } + } +} + +impl PrintableWithTranslator for Unary { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::Not => write!(f, "not"), + Self::Rand => write!(f, "rand"), + Self::Empty => write!(f, ".empty"), + Self::Length => write!(f, ".length"), + Self::ToStr => write!(f, ".tostr"), + Self::ToEl => write!(f, ".toel"), + Self::Qualifier(q) => + write!(f, ".{}", Formatter::from(translator, q)), + } + } +} + +impl PrintableWithTranslator for QualifierRestricted { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} + +impl PrintableWithTranslator for QualifierLabel { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} + +impl PrintableWithTranslator for QualifierSystem { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} + +impl PrintableWithTranslator for QualifierEdge { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} + +impl PrintableWithTranslator for QualifierNode { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} + +impl PrintableWithTranslator for Qualifier { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::Label(q) => + write!(f, "{}", Formatter::from(translator, q)), + Self::Restricted(q) => + write!(f, "{}", Formatter::from(translator, q)), + Self::System(q) => + write!(f, "{}", Formatter::from(translator, q)), + Self::Edge(q) => + write!(f, "{}", Formatter::from(translator, q)), + Self::Node(q) => + write!(f, "{}", Formatter::from(translator, q)), + } + } +} + +impl PrintableWithTranslator for Binary { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} + +impl PrintableWithTranslator for AssertReturnValue { + fn print(&self, f: &mut fmt::Formatter, translator: &Translator) + -> fmt::Result { + match self { + Self::Boolean(b) => write!(f, "{b}"), + Self::Integer(i) => write!(f, "{i}"), + Self::String(s) => write!(f, r#""{s}""#), + Self::Label(l) => + write!(f, "{}", Formatter::from(translator, l)), + Self::Set(set) => + write!(f, "{}", Formatter::from(translator, set)), + Self::Element(el) => + write!(f, "{}", + translator.decode(*el).unwrap_or("Missing".into())), + Self::Edge(edge) => write!(f, "{{edge: {edge:?}}}"), + Self::Node(node) => write!(f, "{{node: {node:?}}}"), + Self::Neighbours(node) => + write!(f, "{{node: {node:?}}}.neighbours"), + Self::System(sys) => + write!(f, "{}", Formatter::from(translator, sys)), + Self::Context(ctx) => + write!(f, "{}", Formatter::from(translator, ctx)), + } + } +} + +impl PrintableWithTranslator for AssertionTypes { + fn print(&self, f: &mut fmt::Formatter, _translator: &Translator) + -> fmt::Result { + write!(f, "{self:?}") + } +} diff --git a/src/rsprocess/assert/mod.rs b/src/rsprocess/assert/mod.rs index d8344ce..1899f24 100644 --- a/src/rsprocess/assert/mod.rs +++ b/src/rsprocess/assert/mod.rs @@ -1,6 +1,10 @@ pub mod dsl; pub mod rsassert; +pub mod types { + pub use super::rsassert::useful_types_edge_relabeler::*; +} + mod fmt; #[cfg(test)] diff --git a/src/rsprocess/assert/rsassert.rs b/src/rsprocess/assert/rsassert.rs index 5be4dc0..1b14f23 100644 --- a/src/rsprocess/assert/rsassert.rs +++ b/src/rsprocess/assert/rsassert.rs @@ -1,3 +1,5 @@ +use crate::rsprocess::translator::PrintableWithTranslator; + use super::dsl::*; use super::super::{translator, graph, set, system, label}; use std::collections::HashMap; @@ -23,7 +25,7 @@ pub mod useful_types_edge_relabeler { }; } - export_types!(RSassert, Tree, Variable, Expression, Range); + export_types!(Assert, Tree, Variable, Expression, Range); export_types_no_parameter!(Unary, QualifierRestricted, QualifierLabel, QualifierSystem, QualifierEdge, QualifierNode, @@ -35,13 +37,13 @@ pub mod useful_types_edge_relabeler { // Implementation for graph labeling in bisimulation. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub enum EdgeRelablerInput { Label, Edge, } -#[derive(Debug, Clone)] +#[derive(Clone)] enum EdgeRelablerInputValues { Label(label::Label), Edge(petgraph::graph::EdgeIndex), @@ -61,7 +63,7 @@ impl SpecialVariables for EdgeRelablerInput { (Self::Label, Qualifier::Restricted(_)) => Ok(AssertionTypes::Set), (s, q) => - Err(format!("Wrong use of qualifier {q} on variable {s}.")) + Err(format!("Wrong use of qualifier {q:?} on variable {s:?}.")) } } @@ -86,7 +88,7 @@ impl SpecialVariables for EdgeRelablerInput { } } -impl std::fmt::Display for EdgeRelablerInput { +impl std::fmt::Debug for EdgeRelablerInput { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Label => write!(f, "label"), @@ -95,7 +97,16 @@ impl std::fmt::Display for EdgeRelablerInput { } } -impl RSassert { +impl PrintableWithTranslator for EdgeRelablerInput { + fn print(&self, + f: &mut std::fmt::Formatter, + _translator: &translator::Translator) + -> std::fmt::Result { + write!(f, "{self:?}") + } +} + +impl Assert { pub fn typecheck(&self) -> Result<(), String> { let mut context = TypeContext::new(); let ty = typecheck(&self.tree, &mut context)?; @@ -113,11 +124,12 @@ impl RSassert { Ok(()), AssertionTypes::NoType => Err("No return type, at least one return statement \ - required.".into()), + required.".into()), AssertionTypes::RangeInteger | AssertionTypes::RangeSet | AssertionTypes::RangeNeighbours => - Err(format!("Returned type {ty} is not a valid return type.")), + Err(format!("Returned type {ty:?} is not a valid return \ + type.")), } } @@ -149,13 +161,13 @@ impl RSassert { // Implementation for node grouping. // ----------------------------------------------------------------------------- -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub enum NodeRelablerInput { Entities, Node, } -#[derive(Debug, Clone)] +#[derive(Clone)] enum NodeRelablerInputValues { Entities(set::Set), Node(petgraph::graph::NodeIndex), @@ -176,7 +188,7 @@ impl SpecialVariables for NodeRelablerInput { (Self::Node, Qualifier::Node(QualifierNode::Neighbours)) => Ok(AssertionTypes::RangeNeighbours), (s, q) => - Err(format!("Wrong use of qualifier {q} on variable {s}.")) + Err(format!("Wrong use of qualifier {q:?} on variable {s:?}.")) } } @@ -201,7 +213,7 @@ impl SpecialVariables for NodeRelablerInput { } } -impl std::fmt::Display for NodeRelablerInput { +impl std::fmt::Debug for NodeRelablerInput { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Entities => write!(f, "entities"), @@ -210,8 +222,17 @@ impl std::fmt::Display for NodeRelablerInput { } } +impl PrintableWithTranslator for NodeRelablerInput { + fn print(&self, + f: &mut std::fmt::Formatter, + _translator: &translator::Translator) + -> std::fmt::Result { + write!(f, "{self:?}") + } +} -impl RSassert { + +impl Assert { pub fn typecheck(&self) -> Result<(), String> { let mut context = TypeContext::new(); let ty = typecheck(&self.tree, &mut context)?; @@ -233,7 +254,8 @@ impl RSassert { AssertionTypes::RangeInteger | AssertionTypes::RangeSet | AssertionTypes::RangeNeighbours => - Err(format!("Returned type {ty} is not a valid return type.")), + Err(format!("Returned type {ty:?} is not a valid return \ + type.")), } } diff --git a/src/rsprocess/assert/tests.rs b/src/rsprocess/assert/tests.rs index 319ddde..2f70cae 100644 --- a/src/rsprocess/assert/tests.rs +++ b/src/rsprocess/assert/tests.rs @@ -7,7 +7,7 @@ use super::super::{ environment, label }; use super::rsassert::*; -type LocalAssert = RSassert; +type LocalAssert = Assert; #[test] fn return_true() { diff --git a/src/rsprocess/grammar.lalrpop b/src/rsprocess/grammar.lalrpop index a8b06f6..fd12e15 100644 --- a/src/rsprocess/grammar.lalrpop +++ b/src/rsprocess/grammar.lalrpop @@ -2,9 +2,8 @@ use std::rc::Rc; use std::str::FromStr; use lalrpop_util::ParseError; use crate::rsprocess::{set, reaction, process, environment, system, label}; -use crate::rsprocess::structure::rsassert; +use crate::rsprocess::assert::types; use crate::rsprocess::translator::{ Translator, IdType }; -use crate::rsprocess::presets::Instructions; use crate::rsprocess::presets; use crate::rsprocess::graph; @@ -270,181 +269,181 @@ Env_term: (IdType, process::Process) = { // ----------------------------------------------------------------------------- // AssertParser // ----------------------------------------------------------------------------- -pub Assert: Box = { +pub Assert: Box = { "label" "{" "}" => - Box::new(rsassert::RSassert{tree: f}), + Box::new(types::Assert{tree: f}), }; -AssertTree: rsassert::Tree = { +AssertTree: types::Tree = { ";" => - rsassert::Tree::Concat(Box::new(t1), Box::new(t2)), + types::Tree::Concat(Box::new(t1), Box::new(t2)), => t, } -AssertTree2: rsassert::Tree = { +AssertTree2: types::Tree = { #[precedence(level="1")] "if" "then" "{" "}" => - rsassert::Tree::If(Box::new(e), Box::new(t)), + types::Tree::If(Box::new(e), Box::new(t)), #[precedence(level="0")] "if" "then" "{" "}" "else" "{" "}" => - rsassert::Tree::IfElse(Box::new(e), Box::new(t1), Box::new(t2)), + types::Tree::IfElse(Box::new(e), Box::new(t1), Box::new(t2)), #[precedence(level="2")] "let" "=" => - rsassert::Tree::Assignment(v, q, Box::new(e)), + types::Tree::Assignment(v, q, Box::new(e)), #[precedence(level="3")] "return" => - rsassert::Tree::Return(Box::new(e)), + types::Tree::Return(Box::new(e)), #[precedence(level="4")] "for" "in" "{" "}" => - rsassert::Tree::For(v, r, Box::new(t)), + types::Tree::For(v, r, Box::new(t)), } -AssertVariable: rsassert::Variable = { +AssertVariable: types::Variable = { #[precedence(level="0")] - "label" => rsassert::Variable::Special(rsassert::Special::Label), + "label" => types::Variable::Special(types::Special::Label), #[precedence(level="1")] - "edge" => rsassert::Variable::Special(rsassert::Special::Edge), + "edge" => types::Variable::Special(types::Special::Edge), #[precedence(level="2")] - => rsassert::Variable::Id(v), + => types::Variable::Id(v), } -AssertExpression: rsassert::Expression = { +AssertExpression: types::Expression = { // Unary #[precedence(level="0")] => - rsassert::Expression::Unary(unp, Box::new(e)), + types::Expression::Unary(unp, Box::new(e)), #[precedence(level="2")] => - rsassert::Expression::Unary(uns, Box::new(e)), + types::Expression::Unary(uns, Box::new(e)), // binary #[precedence(level="3")] #[assoc(side="left")] => - rsassert::Expression::Binary(b, Box::new(e1), Box::new(e2)), + types::Expression::Binary(b, Box::new(e1), Box::new(e2)), #[precedence(level="1")] "(" "," ")" => - rsassert::Expression::Binary(b, Box::new(e1), Box::new(e2)), + types::Expression::Binary(b, Box::new(e1), Box::new(e2)), #[precedence(level="4")] "(" ")" => e, - "true" => rsassert::Expression::True, - "false" => rsassert::Expression::False, + "true" => types::Expression::True, + "false" => types::Expression::False, #[precedence(level="5")] - => rsassert::Expression::Var(v), + => types::Expression::Var(v), // If changing IntegerType in assert.rs, also change from Num to another // similar parser with different return type #[precedence(level="6")] - => rsassert::Expression::Integer(i), + => types::Expression::Integer(i), #[precedence(level="7")] - => rsassert::Expression::Label(Box::new(lab)), - => rsassert::Expression::Set(set), - "'" "'" => rsassert::Expression::Element(translator.encode(el)), + => types::Expression::Label(Box::new(lab)), + => types::Expression::Set(set), + "'" "'" => types::Expression::Element(translator.encode(el)), // strings #[precedence(level="8")] - PATH => rsassert::Expression::String(<>.trim_end_matches("\"") + PATH => types::Expression::String(<>.trim_end_matches("\"") .trim_start_matches("\"") .to_string()), } -AssertRange: rsassert::Range = { - "{" "}" => rsassert::Range::IterateOverSet(Box::new(e)), +AssertRange: types::Range = { + "{" "}" => types::Range::IterateOverSet(Box::new(e)), "{" ".." "}" => - rsassert::Range::IterateInRange(Box::new(e1), Box::new(e2)), + types::Range::IterateInRange(Box::new(e1), Box::new(e2)), } -AssertUnaryPrefix: rsassert::Unary = { - "not" => rsassert::Unary::Not, - "rand" => rsassert::Unary::Rand, +AssertUnaryPrefix: types::Unary = { + "not" => types::Unary::Not, + "rand" => types::Unary::Rand, } -AssertUnarySuffix: rsassert::Unary = { +AssertUnarySuffix: types::Unary = { #[precedence(level="0")] - "." "empty" => rsassert::Unary::Empty, - "." "length" => rsassert::Unary::Length, - "." "tostr" => rsassert::Unary::ToStr, - "." "toel" => rsassert::Unary::ToEl, + "." "empty" => types::Unary::Empty, + "." "length" => types::Unary::Length, + "." "tostr" => types::Unary::ToStr, + "." "toel" => types::Unary::ToEl, #[precedence(level="1")] - "." => rsassert::Unary::Qualifier(q), + "." => types::Unary::Qualifier(q), } -AssertQualifierRestricted: rsassert::QualifierRestricted = { - "Entities" => rsassert::QualifierRestricted::Entities, - "Context" => rsassert::QualifierRestricted::Context, - "Reactants" => rsassert::QualifierRestricted::Reactants, - "ReactantsAbsent" => rsassert::QualifierRestricted::ReactantsAbsent, - "Inhibitors" => rsassert::QualifierRestricted::Inhibitors, - "InhibitorsPresent" => rsassert::QualifierRestricted::InhibitorsPresent, - "Products" => rsassert::QualifierRestricted::Products, +AssertQualifierRestricted: types::QualifierRestricted = { + "Entities" => types::QualifierRestricted::Entities, + "Context" => types::QualifierRestricted::Context, + "Reactants" => types::QualifierRestricted::Reactants, + "ReactantsAbsent" => types::QualifierRestricted::ReactantsAbsent, + "Inhibitors" => types::QualifierRestricted::Inhibitors, + "InhibitorsPresent" => types::QualifierRestricted::InhibitorsPresent, + "Products" => types::QualifierRestricted::Products, } -AssertQualifierLabel: rsassert::QualifierLabel = { - "AvailableEntities" => rsassert::QualifierLabel::AvailableEntities, - "AllReactants" => rsassert::QualifierLabel::AllReactants, - "AllInhibitors" => rsassert::QualifierLabel::AllInhibitors, +AssertQualifierLabel: types::QualifierLabel = { + "AvailableEntities" => types::QualifierLabel::AvailableEntities, + "AllReactants" => types::QualifierLabel::AllReactants, + "AllInhibitors" => types::QualifierLabel::AllInhibitors, } -AssertQualifierSystem: rsassert::QualifierSystem = { - "SystemEntities" => rsassert::QualifierSystem::Entities, - "SystemContext" => rsassert::QualifierSystem::Context, +AssertQualifierSystem: types::QualifierSystem = { + "SystemEntities" => types::QualifierSystem::Entities, + "SystemContext" => types::QualifierSystem::Context, } -AssertQualifierEdge: rsassert::QualifierEdge = { - "source" => rsassert::QualifierEdge::Source, - "target" => rsassert::QualifierEdge::Target, +AssertQualifierEdge: types::QualifierEdge = { + "source" => types::QualifierEdge::Source, + "target" => types::QualifierEdge::Target, } -AssertQualifierNode: rsassert::QualifierNode = { - "neighbours" => rsassert::QualifierNode::Neighbours, - "system" => rsassert::QualifierNode::System, +AssertQualifierNode: types::QualifierNode = { + "neighbours" => types::QualifierNode::Neighbours, + "system" => types::QualifierNode::System, } -AssertQualifier: rsassert::Qualifier = { - => rsassert::Qualifier::System(q), - => rsassert::Qualifier::Label(q), - => rsassert::Qualifier::Restricted(q), - => rsassert::Qualifier::Edge(q), - => rsassert::Qualifier::Node(q), +AssertQualifier: types::Qualifier = { + => types::Qualifier::System(q), + => types::Qualifier::Label(q), + => types::Qualifier::Restricted(q), + => types::Qualifier::Edge(q), + => types::Qualifier::Node(q), } -AssertBinary: rsassert::Binary = { - "&&" => rsassert::Binary::And, - "||" => rsassert::Binary::Or, - "^^" => rsassert::Binary::Xor, - "<" => rsassert::Binary::Less, - "<=" => rsassert::Binary::LessEq, - ">" => rsassert::Binary::More, - ">=" => rsassert::Binary::MoreEq, - "==" => rsassert::Binary::Eq, - "!=" => rsassert::Binary::NotEq, - "+" => rsassert::Binary::Plus, - "-" => rsassert::Binary::Minus, - "*" => rsassert::Binary::Times, - "^" => rsassert::Binary::Exponential, - "/" => rsassert::Binary::Quotient, - "%" => rsassert::Binary::Reminder, - "::" => rsassert::Binary::Concat, +AssertBinary: types::Binary = { + "&&" => types::Binary::And, + "||" => types::Binary::Or, + "^^" => types::Binary::Xor, + "<" => types::Binary::Less, + "<=" => types::Binary::LessEq, + ">" => types::Binary::More, + ">=" => types::Binary::MoreEq, + "==" => types::Binary::Eq, + "!=" => types::Binary::NotEq, + "+" => types::Binary::Plus, + "-" => types::Binary::Minus, + "*" => types::Binary::Times, + "^" => types::Binary::Exponential, + "/" => types::Binary::Quotient, + "%" => types::Binary::Reminder, + "::" => types::Binary::Concat, } -AssertBinaryPrefix: rsassert::Binary = { - "substr" => rsassert::Binary::SubStr, - "min" => rsassert::Binary::Min, - "max" => rsassert::Binary::Max, - "commonsubstr" => rsassert::Binary::CommonSubStr, +AssertBinaryPrefix: types::Binary = { + "substr" => types::Binary::SubStr, + "min" => types::Binary::Min, + "max" => types::Binary::Max, + "commonsubstr" => types::Binary::CommonSubStr, } @@ -858,17 +857,17 @@ Instruction: presets::Instruction = { pub Run: presets::Instructions = { #[precedence(level="0")] > => - Instructions { system: presets::System::System { sys }, - instructions: instr }, + presets::Instructions { system: presets::System::System { sys }, + instructions: instr }, #[precedence(level="1")] => - Instructions { system: presets::System::System { sys }, - instructions: vec![] }, + presets::Instructions { system: presets::System::System { sys }, + instructions: vec![] }, #[precedence(level="2")] "Deserialize" "(" ")" > => - Instructions { system: presets::System::Deserialize { path }, - instructions: instr }, + presets::Instructions { system: presets::System::Deserialize { path }, + instructions: instr }, } diff --git a/src/rsprocess/graph.rs b/src/rsprocess/graph.rs index a503746..932d317 100644 --- a/src/rsprocess/graph.rs +++ b/src/rsprocess/graph.rs @@ -99,11 +99,11 @@ where { fn map_edges( &self, - edge_map: &super::structure::RSassert, + edge_map: &super::assert::types::Assert, translator: &mut super::translator::Translator ) -> Result< Graph + super::assert::types::AssertReturnValue, Ty, Ix> , String>; } @@ -112,9 +112,11 @@ impl<'a> MapEdges<'a, System, Label, Directed, u32> { fn map_edges( &self, - edge_map: &super::structure::RSassert, + edge_map: &super::assert::types::Assert, translator: &mut super::translator::Translator - )-> Result, String> { + )-> Result + , String> { use petgraph::graph::EdgeIndex; let mut g = Graph::with_capacity(self.node_count(), self.edge_count()); diff --git a/src/rsprocess/mod.rs b/src/rsprocess/mod.rs index 71ff7b7..0b6f1dd 100644 --- a/src/rsprocess/mod.rs +++ b/src/rsprocess/mod.rs @@ -1,27 +1,24 @@ //! Crate root -pub mod structure; - pub mod translator; +mod format_helpers; + +pub mod choices; +pub mod environment; +pub mod label; +pub mod process; +pub mod reaction; +pub mod set; +pub mod system; -pub mod graph; -pub mod transitions; -pub mod rsdot; -pub mod serialize; -pub mod presets; pub mod assert; pub mod bisimilarity; pub mod frequency; - -mod format_helpers; - -pub mod set; -pub mod reaction; -pub mod process; -pub mod choices; -pub mod environment; -pub mod system; -pub mod label; +pub mod graph; +pub mod presets; +pub mod rsdot; +pub mod serialize; +pub mod transitions; #[cfg(test)] mod system_test; diff --git a/src/rsprocess/presets.rs b/src/rsprocess/presets.rs index def7db1..0f3d978 100644 --- a/src/rsprocess/presets.rs +++ b/src/rsprocess/presets.rs @@ -87,7 +87,7 @@ pub enum Instruction { FastFrequency { experiment: String, so: SaveOptions }, Digraph { gso: Vec }, Bisimilarity { system_b: String, - edge_relabeler: Box, + edge_relabeler: Box, so: SaveOptions } } @@ -547,11 +547,11 @@ pub fn digraph(system: &mut EvaluatedSystem) -> Result<(), String> { /// Computes bisimularity of two provided systems pub fn bisimilar( system_a: &mut EvaluatedSystem, - edge_relabeler: &super::structure::RSassert, + edge_relabeler: &super::assert::types::Assert, system_b: String ) -> Result { - use super::structure::assert::AssertReturnValue; + use super::assert::types::AssertReturnValue; let system_b = read_file(system_a.get_translator(), system_b.to_string(), diff --git a/src/rsprocess/structure.rs b/src/rsprocess/structure.rs deleted file mode 100644 index 3cfa6d6..0000000 --- a/src/rsprocess/structure.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! Module for all basic structures. - -// ----------------------------------------------------------------------------- -// RSassert -// ----------------------------------------------------------------------------- - -pub type RSassert = - crate::rsprocess::assert::rsassert::useful_types_edge_relabeler::RSassert; - -pub mod assert { - pub use crate::rsprocess::assert::dsl::*; -} - -/// Export of useful values from submodule of submodule -pub mod rsassert { - pub use crate::rsprocess::assert::rsassert::useful_types_edge_relabeler::*; -} diff --git a/src/rsprocess/translator.rs b/src/rsprocess/translator.rs index b8610e4..9c75390 100644 --- a/src/rsprocess/translator.rs +++ b/src/rsprocess/translator.rs @@ -1,7 +1,8 @@ //! Module for translation and keeping track of strings. -use std::collections::HashMap; use serde::{Serialize, Deserialize}; +use std::collections::HashMap; +use std::fmt; /// precision for printing frequencies pub static PRECISION: &usize = &2; @@ -102,51 +103,3 @@ impl<'a, T> Formatter<'a, T> { } - - - - -use super::{ - structure::{ - RSassert - }, -}; -use std::fmt; - -macro_rules! translator_structure { - ($name:ident, $type:ty, $dataname:ident, $print_func:ident) => { - #[derive(Clone, Debug)] - #[allow(dead_code)] - pub struct $name<'a> { - translator: &'a Translator, - $dataname: &'a $type, - } - - #[allow(dead_code)] - impl <'a>$name<'a> { - pub fn from(translator: &'a Translator, $dataname: &'a $type) -> Self { - $name { translator, $dataname } - } - } - - impl<'a> fmt::Display for $name<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - $print_func(f, self.translator, self.$dataname) - } - } - }; -} - - -// RSassert - -#[allow(unused_variables)] -fn print_assert( - f: &mut fmt::Formatter, - translator: &Translator, - assert: &RSassert -) -> fmt::Result { - todo!() -} - -translator_structure!(RSassertDisplay, RSassert, assert, print_assert);