Add arrow mapping and parsing

pull/1/head
trivernis 4 years ago
parent 46c2e99099
commit 88a64f7353

@ -1,9 +1,9 @@
use crate::tokens::constants::TokenPattern;
use crate::tokens::mappings::{
get_grouping_mappings, get_logical_mappings, get_misc_mappings, get_operation_mappings,
get_relation_mapping,
get_arrow_mapping, get_grouping_mappings, get_logical_mappings, get_misc_mappings,
get_operation_mappings, get_relation_mapping,
};
use crate::tokens::{Grouping, Logical, Misc, Operation, Relation, Token};
use crate::tokens::{Arrow, Grouping, Logical, Misc, Operation, Relation, Token};
use charred::tapemachine::CharTapeMachine;
use std::collections::HashMap;
@ -93,4 +93,18 @@ impl Tokenizer {
}
None
}
fn parse_arrows(&mut self) -> Option<Arrow> {
lazy_static! {
static ref ARROW_MAPPINGS: Vec<HashMap<TokenPattern, Arrow>> = get_arrow_mapping();
}
for mapping in ARROW_MAPPINGS.iter() {
for key in mapping.keys() {
if self.ctm.check_any_str_sequence(*key) {
return Some(mapping[key].clone());
}
}
}
None
}
}

@ -1,10 +1,12 @@
use crate::tokens::constants::arrows::*;
use crate::tokens::constants::grouping::*;
use crate::tokens::constants::logical::*;
use crate::tokens::constants::misc::*;
use crate::tokens::constants::operations::*;
use crate::tokens::constants::relations::*;
use crate::tokens::constants::TokenPattern;
use crate::tokens::{Grouping, Logical, Misc, Operation, Relation};
use crate::tokens::{Arrow, Grouping, Logical, Misc, Operation, Relation};
use std::cell::RefCell;
use std::collections::HashMap;
@ -167,3 +169,25 @@ pub fn get_grouping_mappings() -> Vec<HashMap<TokenPattern, Grouping>> {
},
]
}
pub fn get_arrow_mapping() -> Vec<HashMap<TokenPattern, Arrow>> {
vec![
hashmap! {
G_TWOHEADRIGHTARROW => Arrow::TwoHeadRightArrow,
G_TWOHEADRIGHTARROWTAIL => Arrow::TwoHeadRightArrowTail
},
hashmap! {
G_UPARROW => Arrow::UpArrow,
G_DOWNARROW => Arrow::DownArrow,
G_RIGHTARROW => Arrow::RightArrow,
G_TO => Arrow::To,
G_RIGHTARROWTAIL => Arrow::RightArrowTail,
G_MAPSTO => Arrow::MapsTo,
G_LEFTARROW => Arrow::LeftArrow,
G_LEFTRIGHTARROW => Arrow::LeftRightArrow,
G_BIGRIGHTARROW => Arrow::BigRightArrow,
G_BIGLEFTARROW => Arrow::BigLeftArrow,
G_BIGLEFTRIGHTARROW => Arrow::BigLeftRightArrow,
},
]
}

Loading…
Cancel
Save