From 8a5b6ed2a9f51ea33c7633f2434636223d8201df Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 3 Aug 2020 15:45:08 +0200 Subject: [PATCH] Add font command mapping --- src/tokenizer/mod.rs | 23 ++++++++++++++++++++--- src/tokens/mappings.rs | 20 +++++++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/tokenizer/mod.rs b/src/tokenizer/mod.rs index 0de40bd..b8a6560 100644 --- a/src/tokenizer/mod.rs +++ b/src/tokenizer/mod.rs @@ -1,9 +1,12 @@ use crate::tokens::constants::TokenPattern; use crate::tokens::mappings::{ - get_accent_mappings, get_arrow_mapping, get_greek_mappings, get_grouping_mappings, - get_logical_mappings, get_misc_mappings, get_operation_mappings, get_relation_mapping, + get_accent_mappings, get_arrow_mapping, get_font_mappings, get_greek_mappings, + get_grouping_mappings, get_logical_mappings, get_misc_mappings, get_operation_mappings, + get_relation_mapping, +}; +use crate::tokens::{ + Accent, Arrow, FontCommand, Greek, 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; @@ -136,4 +139,18 @@ impl Tokenizer { } None } + + fn parse_font_command(&mut self) -> Option { + lazy_static! { + static ref FONTC_MAPPING: Vec> = get_font_mappings(); + } + for mapping in FONTC_MAPPING.iter() { + for key in mapping.keys() { + if self.ctm.check_str_sequence(*key) { + return Some(mapping[key].clone()); + } + } + } + None + } } diff --git a/src/tokens/mappings.rs b/src/tokens/mappings.rs index 1209a0a..22ba58f 100644 --- a/src/tokens/mappings.rs +++ b/src/tokens/mappings.rs @@ -1,5 +1,6 @@ use crate::tokens::constants::accents::*; use crate::tokens::constants::arrows::*; +use crate::tokens::constants::font_commands::*; use crate::tokens::constants::greek::*; use crate::tokens::constants::grouping::*; use crate::tokens::constants::logical::*; @@ -8,7 +9,9 @@ use crate::tokens::constants::operations::*; use crate::tokens::constants::relations::*; use crate::tokens::constants::TokenPattern; -use crate::tokens::{Accent, Arrow, Greek, Grouping, Logical, Misc, Operation, Relation}; +use crate::tokens::{ + Accent, Arrow, FontCommand, Greek, Grouping, Logical, Misc, Operation, Relation, +}; use std::cell::RefCell; use std::collections::HashMap; @@ -251,3 +254,18 @@ pub fn get_greek_mappings() -> Vec> { G_BIGOMEGA => Greek::BigOmega, }] } + +pub fn get_font_mappings() -> Vec> { + vec![ + hashmap! { + F_BBB => FontCommand::BigOutline + }, + hashmap! { + F_BB => FontCommand::Big, + F_CC => FontCommand::Cursive, + F_TT => FontCommand::TText, + F_FR => FontCommand::Fr, + F_SF => FontCommand::SansSerif, + }, + ] +}