foliage-rs/src/utils.rs

103 lines
2.7 KiB
Rust
Raw Normal View History

2020-07-07 08:15:52 +02:00
use crate::flavor::VariableDeclaration as _;
2020-05-19 15:39:20 +02:00
pub struct BoundVariableDeclarations<'p, F>
where
F: crate::flavor::Flavor,
{
2020-07-07 08:15:52 +02:00
pub parent: &'p VariableDeclarationStackLayer<'p, F>,
pub variable_declarations: std::rc::Rc<crate::VariableDeclarations<F>>,
}
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
2020-05-19 15:39:20 +02:00
impl<'p, F> BoundVariableDeclarations<'p, F>
where
F: crate::flavor::Flavor,
{
2020-05-19 15:39:20 +02:00
pub fn new(parent: &'p VariableDeclarationStackLayer<'p, F>,
variable_declarations: std::rc::Rc<crate::VariableDeclarations<F>>) -> Self
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
{
Self
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
{
parent,
variable_declarations,
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
}
}
}
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
2020-05-19 15:39:20 +02:00
pub enum VariableDeclarationStackLayer<'p, F>
where
F: crate::flavor::Flavor,
{
2020-05-19 15:39:20 +02:00
Free(std::cell::RefCell<crate::VariableDeclarations<F>>),
Bound(BoundVariableDeclarations<'p, F>),
}
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
2020-05-19 15:39:20 +02:00
impl<'p, F> VariableDeclarationStackLayer<'p, F>
where
F: crate::flavor::Flavor,
{
pub fn free() -> Self
{
2020-04-17 03:13:18 +02:00
Self::Free(std::cell::RefCell::new(vec![]))
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
}
2020-05-19 15:39:20 +02:00
pub fn bound(parent: &'p VariableDeclarationStackLayer<'p, F>,
variable_declarations: std::rc::Rc<crate::VariableDeclarations<F>>) -> Self
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
{
Self::Bound(BoundVariableDeclarations::new(parent, variable_declarations))
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
}
2020-05-19 15:39:20 +02:00
pub fn find(&self, variable_name: &str) -> Option<std::rc::Rc<F::VariableDeclaration>>
{
match self
{
2020-04-17 03:13:18 +02:00
VariableDeclarationStackLayer::Free(free_variable_declarations) =>
{
2020-04-17 03:13:18 +02:00
if let Some(variable_declaration) = free_variable_declarations.borrow().iter()
.find(|x| x.matches_name(variable_name))
{
return Some(std::rc::Rc::clone(&variable_declaration));
}
None
},
2020-04-17 03:13:18 +02:00
VariableDeclarationStackLayer::Bound(bound_variable_declarations) =>
{
2020-04-17 03:13:18 +02:00
if let Some(variable_declaration) = bound_variable_declarations
.variable_declarations.iter()
.find(|x| x.matches_name(variable_name))
{
return Some(std::rc::Rc::clone(&variable_declaration));
}
2020-04-17 03:13:18 +02:00
bound_variable_declarations.parent.find(variable_name)
},
}
}
2020-05-19 15:39:20 +02:00
pub fn free_variable_declarations_do_mut<F1, F2>(&self, f: F1) -> F2
where
2020-05-19 15:39:20 +02:00
F1: Fn(&mut crate::VariableDeclarations<F>) -> F2,
{
match self
{
VariableDeclarationStackLayer::Free(free_variable_declarations)
=> f(&mut free_variable_declarations.borrow_mut()),
VariableDeclarationStackLayer::Bound(bound_variable_declarations)
=> bound_variable_declarations.parent.free_variable_declarations_do_mut(f),
}
}
2020-05-19 15:39:20 +02:00
pub fn free_variable_declarations_do<F1, F2>(&self, f: F1) -> F2
where
2020-05-19 15:39:20 +02:00
F1: Fn(&crate::VariableDeclarations<F>) -> F2,
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
{
match self
{
2020-04-17 03:13:18 +02:00
VariableDeclarationStackLayer::Free(free_variable_declarations)
=> f(&free_variable_declarations.borrow()),
VariableDeclarationStackLayer::Bound(bound_variable_declarations)
=> bound_variable_declarations.parent.free_variable_declarations_do(f),
}
Start reimplementing parser Implement name parsing Start parsing terms Implement word boundaries Implement strings Add pipe character to allowed word boundaries Implement booleans Require word boundaries around names Implement variable parsing Finish implementing term parsing Add term parsing test Test associativity of multiplication Make parse feature the default Fix term parsing and finish tests Start parsing formulas Continue parsing formulas Finish implementing formula parsing Move boolean parser to separate module Move integer parser to separate module Move special integer parser to separate module Move string parser to separate module Address warnings Fix negation parser Refactor term parser tests Address clippy warning Disallow reserved keywords as names Add missing word boundary character Check that names don’t start with special characters Minor refactoring Add note Test conjunction parser Test disjunction parser Parentheses for stronger checks Add note Fix implication parser and output Split formatting functionality into two files Test term formatting Add unit test for function declaration formatting Work in progress Fix implication formatting Refactor precedence rules Start testing formula formatter Minor formatting Test remaining formula types Add unit tests for precedence-0 formulas and lower Before larger refactoring Refactor precedence rules for formulas Remove ChildPosition enum Fix Address warnings Remove unneeded precedence implementation Test negation Test quantified formulas Clean up tests Clean up tests Test conjunction Test disjunction Start testing implications Refactor parenthesis requirement check Fix precedence of implication Continue testing implication Test biconditionals Experimental method for testing all permutations Rewrite tests for clarity Rewrite tests for clarity Add type annotations Rewrite tests for clarity Reorganize tests Finish testing biconditionals Support empty n-aries Support quantified expressions with 0 parameters Rewrite term formatting tests for clarity Reorganize term formatter tests Refactor parenthesis rules for terms Remove unneeded parentheses enum Refactoring Refactoring Minor clean-up Minor clean-up Simplify representation of quantified formulas Remove redundant indirection Remove redundant indirection
2020-02-25 15:36:34 +01:00
}
}