Add accent mapping and parsing

pull/1/head
trivernis 4 years ago
parent 88a64f7353
commit 3f1632e212

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

@ -1,3 +1,4 @@
use crate::tokens::constants::accents::*;
use crate::tokens::constants::arrows::*;
use crate::tokens::constants::grouping::*;
use crate::tokens::constants::logical::*;
@ -6,7 +7,7 @@ use crate::tokens::constants::operations::*;
use crate::tokens::constants::relations::*;
use crate::tokens::constants::TokenPattern;
use crate::tokens::{Arrow, Grouping, Logical, Misc, Operation, Relation};
use crate::tokens::{Accent, Arrow, Grouping, Logical, Misc, Operation, Relation};
use std::cell::RefCell;
use std::collections::HashMap;
@ -191,3 +192,20 @@ pub fn get_arrow_mapping() -> Vec<HashMap<TokenPattern, Arrow>> {
},
]
}
pub fn get_accent_mapping() -> Vec<HashMap<TokenPattern, Accent>> {
vec![hashmap! {
G_HAT => Accent::Hat,
G_UNDERLINE => Accent::Underline,
G_OVERLINE => Accent::Overline,
G_VEC => Accent::Vec,
G_DOT => Accent::Dot,
G_DDOT => Accent::DDot,
G_OVERSET => Accent::OverSet,
G_UNDERSET => Accent::UnderSet,
G_UNDERBRACE => Accent::UnderBrace,
G_OVERBRACE => Accent::OverBrace,
G_COLOR => Accent::Color,
G_CANCEL => Accent::Cancel,
}]
}

Loading…
Cancel
Save