Add misc mapping and parsing

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

@ -1,10 +1,5 @@
use crate::tokens::constants::operations::{
G_AST, G_BACKSLASH, G_BIDWEDGE, G_BIGCAP, G_BIGCUP, G_BIGVEE, G_BOWTIE, G_CAP, G_CDOT, G_CIRC,
G_CUP, G_DIV, G_LTIMES, G_MINUS, G_ODOT, G_OPLUS, G_PLUS, G_PROD, G_RTIMES, G_SLASH, G_STAR,
G_SUM, G_TIMES, G_VEE, G_WEDGE,
};
use crate::tokens::mappings::get_operation_mappings;
use crate::tokens::{Operation, Token};
use crate::tokens::mappings::{get_misc_mappings, get_operation_mappings};
use crate::tokens::{Misc, Operation, Token};
use charred::tapemachine::CharTapeMachine;
use std::collections::HashMap;
@ -21,6 +16,21 @@ impl Tokenizer {
}
}
fn parse_misc(&mut self) -> Option<Misc> {
lazy_static! {
static ref MISC_MAPPINGS: Vec<HashMap<&'static [&'static str], Misc>> =
get_misc_mappings();
}
for mapping in MISC_MAPPINGS.iter() {
for key in mapping.keys() {
if self.ctm.check_any_str_sequence(*key) {
return Some(mapping[key].clone());
}
}
}
None
}
fn parse_operation(&mut self) -> Option<Operation> {
lazy_static! {
static ref OPERATION_MAPPINGS: Vec<HashMap<&'static [&'static str], Operation>> =

@ -1,40 +1,40 @@
pub const A_FRAC: &str = "/";
pub const T_FRAC: &str = "frac";
pub const G_A_FRAC: &'static [&str] = &["/"];
pub const G_T_FRAC: &'static [&str] = &["frac"];
pub const G_POW: &'static[&str] = &["^"];
pub const G_SQRT: &'static[&str] = &["sqrt"];
pub const G_ROOT: &'static[&str] = &["root"];
pub const G_INT: &'static[&str] = &["int"];
pub const G_OINT: &'static[&str] = &["oint"];
pub const G_DEL: &'static[&str] = &["del", "partial"];
pub const G_GRAD: &'static[&str] = &["grad", "nbla"];
pub const G_PM: &'static[&str] = &["+-", "pm"];
pub const G_EMPTYSET: &'static[&str] = &["O/", "emptyset"];
pub const GINFTY: &'static[&str] = &["oo", "infty"];
pub const G_ALEPH: &'static[&str] = &["aleph"];
pub const G_THEREFORE: &'static[&str] = &[":.", "therefore"];
pub const G_BECAUSE: &'static[&str] = &[":'", "because"];
pub const G_ELDOTS: &'static[&str] = &["|...|", "|ldots|"];
pub const G_ECDOTS: &'static[&str] = &["|cdots|"];
pub const G_VDOTS: &'static[&str] = &["vdots"];
pub const G_DDOTS: &'static[&str] = &["ddots"];
pub const G_EPIPES: &'static[&str] = &["|\\ |"];
pub const G_QUAD: &'static[&str] = &["|quad|"];
pub const G_ANGLE: &'static[&str] = &["/_", "angle"];
pub const G_FROWN: &'static[&str] = &["frown"];
pub const G_TRIANGLE: &'static[&str] = &["/_\\", "triangle"];
pub const G_DIAMOND: &'static[&str] = &["diamond"];
pub const G_SQUARE: &'static[&str] = &["square"];
pub const G_LFLOOR: &'static[&str] = &["|__", "lfloor"];
pub const G_RFLOOR: &'static[&str] = &["__|", "rfloor"];
pub const G_LCEILING: &'static[&str] = &["|~", "lceiling"];
pub const G_RCEILING: &'static[&str] = &["~|", "rceiling"];
pub const G_POW: &'static [&str] = &["^"];
pub const G_SQRT: &'static [&str] = &["sqrt"];
pub const G_ROOT: &'static [&str] = &["root"];
pub const G_INT: &'static [&str] = &["int"];
pub const G_OINT: &'static [&str] = &["oint"];
pub const G_DEL: &'static [&str] = &["del", "partial"];
pub const G_GRAD: &'static [&str] = &["grad", "nbla"];
pub const G_PM: &'static [&str] = &["+-", "pm"];
pub const G_EMPTYSET: &'static [&str] = &["O/", "emptyset"];
pub const G_INFTY: &'static [&str] = &["oo", "infty"];
pub const G_ALEPH: &'static [&str] = &["aleph"];
pub const G_THEREFORE: &'static [&str] = &[":.", "therefore"];
pub const G_BECAUSE: &'static [&str] = &[":'", "because"];
pub const G_ELDOTS: &'static [&str] = &["|...|", "|ldots|"];
pub const G_ECDOTS: &'static [&str] = &["|cdots|"];
pub const G_VDOTS: &'static [&str] = &["vdots"];
pub const G_DDOTS: &'static [&str] = &["ddots"];
pub const G_EPIPES: &'static [&str] = &["|\\ |"];
pub const G_QUAD: &'static [&str] = &["|quad|"];
pub const G_ANGLE: &'static [&str] = &["/_", "angle"];
pub const G_FROWN: &'static [&str] = &["frown"];
pub const G_TRIANGLE: &'static [&str] = &["/_\\", "triangle"];
pub const G_DIAMOND: &'static [&str] = &["diamond"];
pub const G_SQUARE: &'static [&str] = &["square"];
pub const G_LFLOOR: &'static [&str] = &["|__", "lfloor"];
pub const G_RFLOOR: &'static [&str] = &["__|", "rfloor"];
pub const G_LCEILING: &'static [&str] = &["|~", "lceiling"];
pub const G_RCEILING: &'static [&str] = &["~|", "rceiling"];
pub const G_COMPLEX: &'static[&str] = &["CC"];
pub const G_NATURAL: &'static[&str] = &["NN"];
pub const G_RATIONAL: &'static[&str] = &["QQ"];
pub const G_REAL: &'static[&str] = &["RR"];
pub const G_INTEGER: &'static[&str] = &["ZZ"];
pub const G_COMPLEX: &'static [&str] = &["CC"];
pub const G_NATURAL: &'static [&str] = &["NN"];
pub const G_RATIONAL: &'static [&str] = &["QQ"];
pub const G_REAL: &'static [&str] = &["RR"];
pub const G_INTEGER: &'static [&str] = &["ZZ"];
pub const A_TEXT: &str = "\"";
pub const T_TEX: &str = "text";
pub const G_A_TEXT: &'static [&str] = &["\""];
pub const G_T_TEX: &'static [&str] = &["text"];

@ -1,5 +1,7 @@
use crate::tokens::constants::misc::*;
use crate::tokens::constants::operations::*;
use crate::tokens::Operation;
use crate::tokens::{Misc, Operation};
use std::cell::RefCell;
use std::collections::HashMap;
pub fn get_operation_mappings() -> Vec<HashMap<&'static [&'static str], Operation>> {
@ -38,3 +40,51 @@ pub fn get_operation_mappings() -> Vec<HashMap<&'static [&'static str], Operatio
},
]
}
pub fn get_misc_mappings() -> Vec<HashMap<&'static [&'static str], Misc>> {
vec![
hashmap! {
G_TRIANGLE => Misc::Triangle,
},
hashmap! {
G_ANGLE => Misc::Angle,
},
hashmap! {
G_A_FRAC => Misc::AsciiFrac,
G_T_FRAC => Misc::LatexFrac,
G_POW => Misc::Pow,
G_SQRT => Misc::Sqrt,
G_ROOT => Misc::Root,
G_INT => Misc::Int,
G_OINT => Misc::OInt,
G_DEL => Misc::Del,
G_GRAD => Misc::Grad,
G_PM => Misc::PlusMinus,
G_EMPTYSET => Misc::EmptySet,
G_INFTY => Misc::Infty,
G_ALEPH => Misc::Aleph,
G_THEREFORE => Misc::Therefore,
G_BECAUSE => Misc::Because,
G_ELDOTS => Misc::PLDots,
G_ECDOTS => Misc::PCDots,
G_VDOTS => Misc::VDots,
G_DDOTS => Misc::DDots,
G_EPIPES => Misc::EPipes,
G_QUAD => Misc::EQuad,
G_FROWN => Misc::Frown,
G_DIAMOND => Misc::Diamond,
G_SQUARE => Misc::Square,
G_LFLOOR => Misc::LFloor,
G_RFLOOR => Misc::RFloor,
G_LCEILING => Misc::LCeiling,
G_RCEILING => Misc::RCeiling,
G_COMPLEX => Misc::Complex,
G_NATURAL => Misc::Natural,
G_RATIONAL => Misc::Rational,
G_REAL => Misc::Real,
G_INTEGER => Misc::Integer,
G_A_TEXT => Misc::AsciiText,
G_T_TEX => Misc::LatexText,
},
]
}

@ -46,7 +46,8 @@ pub enum Operation {
#[derive(Debug, Clone)]
pub enum Misc {
Frac,
AsciiFrac,
LatexFrac,
Pow,
Sqrt,
Root,
@ -73,13 +74,15 @@ pub enum Misc {
Square,
LFloor,
RFloor,
LCeiling,
RCeiling,
Complex,
Natural,
Rational,
Real,
Integer,
Text,
AsciiText,
LatexText,
}
#[derive(Debug, Clone)]
@ -218,4 +221,4 @@ pub enum FontCommand {
TText,
Fr,
SansSerif,
}
}

Loading…
Cancel
Save