Add logical mappings and parsing

pull/1/head
trivernis 4 years ago
parent f19a36d5e9
commit 3daf942a3c

@ -1,5 +1,7 @@
use crate::tokens::mappings::{get_misc_mappings, get_operation_mappings, get_relation_mapping};
use crate::tokens::{Misc, Operation, Relation, Token};
use crate::tokens::mappings::{
get_logical_mappings, get_misc_mappings, get_operation_mappings, get_relation_mapping,
};
use crate::tokens::{Logical, Misc, Operation, Relation, Token};
use charred::tapemachine::CharTapeMachine;
use std::collections::HashMap;
@ -60,4 +62,19 @@ impl Tokenizer {
}
None
}
fn parse_logical(&mut self) -> Option<Logical> {
lazy_static! {
static ref LOGICAL_MAPPINGS: Vec<HashMap<&'static [&'static str], Logical>> =
get_logical_mappings();
}
for mapping in LOGICAL_MAPPINGS.iter() {
for key in mapping.keys() {
if self.ctm.check_any_str_sequence(*key) {
return Some(mapping[key].clone());
}
}
}
None
}
}

@ -1,7 +1,8 @@
use crate::tokens::constants::logical::*;
use crate::tokens::constants::misc::*;
use crate::tokens::constants::operations::*;
use crate::tokens::constants::relations::*;
use crate::tokens::{Misc, Operation, Relation};
use crate::tokens::{Logical, Misc, Operation, Relation};
use std::cell::RefCell;
use std::collections::HashMap;
@ -120,3 +121,24 @@ pub fn get_relation_mapping() -> Vec<HashMap<&'static [&'static str], Relation>>
},
]
}
pub fn get_logical_mappings() -> Vec<HashMap<&'static [&'static str], Logical>> {
vec![
hashmap! {
G_IFF => Logical::Iff,
},
hashmap! {
G_AND => Logical::And,
G_OR => Logical::Or,
G_NOT => Logical::Not,
G_IMPLIES => Logical::Implies,
G_IF => Logical::If,
G_FORALL => Logical::ForAll,
G_EXISTS => Logical::Exists,
G_BOT => Logical::Bot,
G_TOP => Logical::Top,
G_VDASH => Logical::VDash,
G_MODELS => Logical::Models,
},
]
}

@ -116,6 +116,7 @@ pub enum Logical {
Not,
Implies,
If,
Iff,
ForAll,
Exists,
Bot,

Loading…
Cancel
Save