Add relation mappings and parsing

pull/1/head
trivernis 4 years ago
parent b7acd1b426
commit f19a36d5e9

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

@ -1,6 +1,7 @@
use crate::tokens::constants::misc::*;
use crate::tokens::constants::operations::*;
use crate::tokens::{Misc, Operation};
use crate::tokens::constants::relations::*;
use crate::tokens::{Misc, Operation, Relation};
use std::cell::RefCell;
use std::collections::HashMap;
@ -88,3 +89,34 @@ pub fn get_misc_mappings() -> Vec<HashMap<&'static [&'static str], Misc>> {
},
]
}
pub fn get_relation_mapping() -> Vec<HashMap<&'static [&'static str], Relation>> {
vec![
hashmap! {
G_SUBSETEQ => Relation::SubSetEq,
G_SUPSETEQ => Relation::SupSetEq,
G_LE => Relation::Le,
G_GE => Relation::Ge,
G_SUCCEQ => Relation::SuccEq,
G_PRECEQ => Relation::PrecEq,
},
hashmap! {
G_SUCC => Relation::Succ,
},
hashmap! {
G_EQ => Relation::Eq,
G_NE => Relation::Ne,
G_LT => Relation::Lt,
G_GT => Relation::Gt,
G_PREC => Relation::Prec,
G_IN => Relation::In,
G_NOTIN => Relation::NotIn,
G_SUBSET => Relation::SubSet,
G_SUPSET => Relation::SupSet,
G_EQUIV => Relation::Equiv,
G_CONG => Relation::Cong,
G_APPROX => Relation::Approx,
G_PROP => Relation::PropTo,
},
]
}

Loading…
Cancel
Save