From b507fe22ce104ca622ecd8d832014a6d230a5a07 Mon Sep 17 00:00:00 2001 From: monsterkrampe Date: Thu, 5 Jun 2025 10:36:39 +0200 Subject: [PATCH] Make AdfParser publically accessible --- lib/src/parser.rs | 50 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/src/parser.rs b/lib/src/parser.rs index 2603e5a..5542b9b 100644 --- a/lib/src/parser.rs +++ b/lib/src/parser.rs @@ -20,28 +20,28 @@ use crate::datatypes::adf::VarContainer; /// A representation of a formula, still using the strings from the input. #[derive(Clone, PartialEq, Eq)] -pub enum Formula<'a> { +pub enum Formula { /// `c(f)` in the input format. Bot, /// `c(v)` in the input format. Top, /// Some atomic variable in the input format. - Atom(&'a str), + Atom(String), /// Negation of a subformula. - Not(Box>), + Not(Box), /// Conjunction of two subformulae. - And(Box>, Box>), + And(Box, Box), /// Disjunction of two subformulae. - Or(Box>, Box>), + Or(Box, Box), /// Implication of two subformulae. - Imp(Box>, Box>), + Imp(Box, Box), /// Exclusive-Or of two subformulae. - Xor(Box>, Box>), + Xor(Box, Box), /// If and only if connective between two formulae. - Iff(Box>, Box>), + Iff(Box, Box), } -impl Formula<'_> { +impl Formula { pub(crate) fn to_boolean_expr( &self, ) -> biodivine_lib_bdd::boolean_expression::BooleanExpression { @@ -90,7 +90,7 @@ impl Formula<'_> { } } -impl std::fmt::Debug for Formula<'_> { +impl std::fmt::Debug for Formula { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Formula::Atom(a) => { @@ -132,14 +132,14 @@ impl std::fmt::Debug for Formula<'_> { /// /// Note that the parser can be utilised by an [ADF][`crate::adf::Adf`] to initialise it with minimal overhead. #[derive(Debug)] -pub struct AdfParser<'a> { - namelist: Arc>>, - dict: Arc>>, - formulae: RefCell>>, - formulaname: RefCell>, +pub struct AdfParser { + pub namelist: Arc>>, + pub dict: Arc>>, + pub formulae: RefCell>, + pub formulaname: RefCell>, } -impl Default for AdfParser<'_> { +impl Default for AdfParser { fn default() -> Self { AdfParser { namelist: Arc::new(RwLock::new(Vec::new())), @@ -150,10 +150,7 @@ impl Default for AdfParser<'_> { } } -impl<'a, 'b> AdfParser<'b> -where - 'a: 'b, -{ +impl<'a> AdfParser { #[allow(dead_code)] fn parse_statements(&'a self) -> impl FnMut(&'a str) -> IResult<&'a str, ()> { move |input| { @@ -212,9 +209,9 @@ where } } -impl<'a> AdfParser<'a> { +impl AdfParser { /// Creates a new parser, utilising the already existing [VarContainer] - pub fn with_var_container(var_container: VarContainer) -> AdfParser<'a> { + pub fn with_var_container(var_container: VarContainer) -> AdfParser { AdfParser { namelist: var_container.names(), dict: var_container.mappings(), @@ -224,7 +221,7 @@ impl<'a> AdfParser<'a> { } } -impl AdfParser<'_> { +impl AdfParser { /// after an update to the namelist, all indizes are updated fn regenerate_indizes(&self) { self.namelist @@ -284,7 +281,7 @@ impl AdfParser<'_> { } fn atomic_term(input: &str) -> IResult<&str, Formula> { - AdfParser::atomic(input).map(|(input, result)| (input, Formula::Atom(result))) + AdfParser::atomic(input).map(|(input, result)| (input, Formula::Atom(result.to_string()))) } fn formula(input: &str) -> IResult<&str, Formula> { @@ -504,7 +501,10 @@ mod test { assert_eq!(parser.dict_value("b"), Some(2usize)); assert_eq!( format!("{:?}", parser.ac_at(1).unwrap()), - format!("{:?}", Formula::Not(Box::new(Formula::Atom("a")))) + format!( + "{:?}", + Formula::Not(Box::new(Formula::Atom("a".to_string()))) + ) ); assert_eq!(parser.formula_count(), 3); assert_eq!(parser.formula_order(), vec![0, 2, 1]);