2022-01-18 06:15:51 -06:00
|
|
|
// TODO improve tokenizer/parser
|
2021-12-24 13:00:20 -06:00
|
|
|
pub fn colorify(eval: &str) {
|
|
|
|
let y = eval.split("$");
|
|
|
|
for z in y {
|
|
|
|
match z {
|
|
|
|
"BLACK" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Black, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"RED" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Red, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"GREEN" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Green, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"BLUE" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Blue, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"CYAN" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Cyan, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"MAGENTA" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Magenta, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"BROWN" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Brown, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"LIGHTGRAY" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::LightGray, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"DARKGRAY" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::DarkGray, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"LIGHTBLUE" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::LightBlue, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"LIGHTGREEN" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::LightGreen, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"LIGHTCYAN" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::LightCyan, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"LIGHTRED" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::LightRed, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"PINK" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Pink, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"YELLOW" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Yellow, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"WHITE" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::White, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
"RESET" => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::White, Color::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
elk => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// kprint!("{}", elk);
|
2021-12-24 13:00:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-18 10:04:10 -06:00
|
|
|
|
2022-02-21 07:17:16 -06:00
|
|
|
use logos::Logos;
|
|
|
|
|
|
|
|
#[derive(Logos, Debug, PartialEq)]
|
|
|
|
pub enum Token {
|
|
|
|
// Hex(u32),
|
|
|
|
#[regex(r"\$RED\$")]
|
|
|
|
Red,
|
2022-02-18 10:04:10 -06:00
|
|
|
|
2022-02-21 07:17:16 -06:00
|
|
|
#[regex(r"\$RESET\$")]
|
|
|
|
Reset,
|
2022-02-18 10:04:10 -06:00
|
|
|
|
2022-02-21 07:17:16 -06:00
|
|
|
#[regex("[a-zA-Z!@#$%^&*\">()\n ]+", parse_text, priority = 2)]
|
|
|
|
Text(String),
|
|
|
|
|
|
|
|
#[error]
|
|
|
|
#[regex(r"[ \t\n\f]+", logos::skip)]
|
|
|
|
Error,
|
|
|
|
}
|
|
|
|
pub fn colorify_2(eval: &str) {
|
2022-03-11 13:51:47 -06:00
|
|
|
let lexer = Token::lexer(eval);
|
2022-02-21 07:17:16 -06:00
|
|
|
for token in lexer {
|
|
|
|
use Token::*;
|
|
|
|
match token {
|
|
|
|
Red => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::Red, Color::Black);
|
2022-02-21 07:17:16 -06:00
|
|
|
}
|
|
|
|
Reset => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// set_vga_color(Color::White, Color::Black);
|
2022-02-21 07:17:16 -06:00
|
|
|
}
|
|
|
|
Text(text) => {
|
2022-03-11 14:18:07 -06:00
|
|
|
// kprint!("{}", text);
|
2022-02-21 07:17:16 -06:00
|
|
|
}
|
|
|
|
err => {
|
2022-03-11 13:51:47 -06:00
|
|
|
error!("Error parsing {:?}", err);
|
2022-02-21 07:17:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use logos::Lexer;
|
2022-02-18 10:04:10 -06:00
|
|
|
|
2022-03-11 14:18:07 -06:00
|
|
|
// use crate::kprint;
|
2022-02-21 07:17:16 -06:00
|
|
|
fn parse_text(lex: &mut Lexer<Token>) -> Option<String> {
|
|
|
|
let slice = lex.slice();
|
|
|
|
Some(String::from(slice))
|
|
|
|
}
|