use crate::expression_tree::node::operator::Operator;
pub struct OperatorNotation{
map: [String; 5],
}
impl OperatorNotation{
pub fn ascii() -> Self{
Self { map: [
"~".to_string(),
"&".to_string(),
"v".to_string(),
"->".to_string(),
"<->".to_string(),
]
}
}
pub fn mathematical() -> Self{
Self { map: [
"¬".to_string(),
"∧".to_string(),
"∨".to_string(),
"➞".to_string(),
"⟷".to_string(),
]
}
}
pub fn mathematical_ascii() -> Self{
Self { map: [
"~".to_string(),
"^".to_string(),
"v".to_string(),
"->".to_string(),
"<->".to_string(),
]
}
}
pub fn bits() -> Self{
Self { map: [
"¬".to_string(),
"⋅".to_string(),
"+".to_string(),
"➞".to_string(),
"⟷".to_string(),
]
}
}
pub fn bits_ascii() -> Self{
Self { map: [
"~".to_string(),
"*".to_string(),
"+".to_string(),
"->".to_string(),
"<->".to_string(),
]
}
}
pub fn boolean() -> Self{
Self { map: [
"!".to_string(),
"&".to_string(),
"|".to_string(),
"➞".to_string(),
"⟷".to_string(),
]
}
}
pub fn boolean_ascii() -> Self{
Self { map: [
"!".to_string(),
"&".to_string(),
"|".to_string(),
"->".to_string(),
"<->".to_string(),
]
}
}
pub fn get_notation(&self, op: Operator) -> &str{
&self.map[op as usize]
}
pub fn get_operator(&self, notation: &str) -> Option<Operator>{
for (i, n) in self.map.iter().enumerate(){
if notation == n{
return Some(match i{
0 => Operator::NOT,
1 => Operator::AND,
2 => Operator::OR,
3 => Operator::CON,
4 => Operator::BICON,
_ => panic!("Unsupported operator inside of set_notation"),
});
}
}
None
}
pub fn get_prefix_operator(&self, expression: &str) -> Option<Operator>{
for (i, n) in self.map.iter().enumerate(){
if expression.starts_with(n){
return Some(match i{
0 => Operator::NOT,
1 => Operator::AND,
2 => Operator::OR,
3 => Operator::CON,
4 => Operator::BICON,
_ => panic!("Unsupported operator inside of set_notation"),
});
}
}
None
}
pub fn set_notation(&mut self, op: Operator, notation: String) -> Result<(), Operator>{
for (i, n) in self.map.iter().enumerate(){
if i == op as usize{ continue; }
if notation.starts_with(n) || n.starts_with(¬ation){
return Err(match i{
0 => Operator::NOT,
1 => Operator::AND,
2 => Operator::OR,
3 => Operator::CON,
4 => Operator::BICON,
_ => panic!("Unsupported operator inside of set_notation"),
});
}
}
self.map[op as usize] = notation;
Ok(())
}
}
impl Default for OperatorNotation{
fn default() -> Self {
Self { map: [
"¬".to_string(),
"&".to_string(),
"∨".to_string(),
"➞".to_string(),
"⟷".to_string(),
]
}
}
}