Add greek mappings and parsing

pull/1/head
trivernis 4 years ago
parent 3f1632e212
commit 809d30a6c8

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

@ -1,5 +1,6 @@
use crate::tokens::constants::accents::*;
use crate::tokens::constants::arrows::*;
use crate::tokens::constants::greek::*;
use crate::tokens::constants::grouping::*;
use crate::tokens::constants::logical::*;
use crate::tokens::constants::misc::*;
@ -7,7 +8,7 @@ use crate::tokens::constants::operations::*;
use crate::tokens::constants::relations::*;
use crate::tokens::constants::TokenPattern;
use crate::tokens::{Accent, Arrow, Grouping, Logical, Misc, Operation, Relation};
use crate::tokens::{Accent, Arrow, Greek, Grouping, Logical, Misc, Operation, Relation};
use std::cell::RefCell;
use std::collections::HashMap;
@ -193,7 +194,7 @@ pub fn get_arrow_mapping() -> Vec<HashMap<TokenPattern, Arrow>> {
]
}
pub fn get_accent_mapping() -> Vec<HashMap<TokenPattern, Accent>> {
pub fn get_accent_mappings() -> Vec<HashMap<TokenPattern, Accent>> {
vec![hashmap! {
G_HAT => Accent::Hat,
G_UNDERLINE => Accent::Underline,
@ -209,3 +210,44 @@ pub fn get_accent_mapping() -> Vec<HashMap<TokenPattern, Accent>> {
G_CANCEL => Accent::Cancel,
}]
}
pub fn get_greek_mappings() -> Vec<HashMap<TokenPattern, Greek>> {
vec![hashmap! {
G_ALPHA => Greek::Alpha,
G_BETA => Greek::Beta,
G_GAMMA => Greek::Gamma,
G_BIGGAMMA => Greek::BigGamma,
G_DELTA => Greek::Delta,
G_BIGDELTA => Greek::BigDelta,
G_EPSILON => Greek::Epsilon,
G_VAREPSILON => Greek::VarEpsilon,
G_ZETA => Greek::Zeta,
G_ETA => Greek::Eta,
G_THETA => Greek::Theta,
G_BIGTHETA => Greek::BigTheta,
G_VARTHETA => Greek::VarTheta,
G_IOTA => Greek::Iota,
G_KAPPA => Greek::Kappa,
G_LAMBDA => Greek::Lambda,
G_BIGLAMBDA => Greek::BigLambda,
G_MU => Greek::Mu,
G_NU => Greek::Nu,
G_XI => Greek::Xi,
G_BIGXI => Greek::BigXi,
G_PI => Greek::Pi,
G_BIGPI => Greek::BigPi,
G_RHO => Greek::Rho,
G_SIGMA => Greek::Sigma,
G_BIGSIGMA => Greek::BigSigma,
G_TAU => Greek::Tau,
G_UPSILON => Greek::Upsilon,
G_PHI => Greek::Phi,
G_BIGPHI => Greek::BigPhi,
G_VARPHI => Greek::VarPhi,
G_CHI => Greek::Chi,
G_PSI => Greek::Psi,
G_BIGPSI => Greek::BigPsi,
G_OMEGA => Greek::Omega,
G_BIGOMEGA => Greek::BigOmega,
}]
}

@ -211,7 +211,9 @@ pub enum Greek {
VarPhi,
Chi,
Psi,
BigPsi,
Omega,
BigOmega,
}
#[derive(Debug, Clone)]

Loading…
Cancel
Save