From f19a36d5e9f3bb2078da440747b6c98172d875bd Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 3 Aug 2020 13:25:53 +0200 Subject: [PATCH] Add relation mappings and parsing --- src/tokenizer/mod.rs | 19 +++++++++++++++++-- src/tokens/mappings.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/tokenizer/mod.rs b/src/tokenizer/mod.rs index c19780b..9dcc191 100644 --- a/src/tokenizer/mod.rs +++ b/src/tokenizer/mod.rs @@ -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 { + lazy_static! { + static ref RELATION_MAPPINGS: Vec> = + 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 + } } diff --git a/src/tokens/mappings.rs b/src/tokens/mappings.rs index 7fb6785..c9c019e 100644 --- a/src/tokens/mappings.rs +++ b/src/tokens/mappings.rs @@ -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> { }, ] } + +pub fn get_relation_mapping() -> Vec> { + 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, + }, + ] +}