string colorizer

pls-build-on-my-machine
Able 2022-02-21 07:17:16 -06:00
parent b8b1b3603c
commit 2633580d1c
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
3 changed files with 49 additions and 5 deletions

View File

@ -65,3 +65,47 @@ pub fn colorify(eval: &str) {
}
}
}
use alloc::string::String;
use logos::Logos;
#[derive(Logos, Debug, PartialEq)]
pub enum Token {
// Hex(u32),
#[regex(r"\$RED\$")]
Red,
#[regex(r"\$RESET\$")]
Reset,
#[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) {
let mut lexer = Token::lexer(eval);
for token in lexer {
use Token::*;
match token {
Red => {
set_vga_color(Color::Red, Color::Black);
}
Reset => {
set_vga_color(Color::White, Color::Black);
}
Text(text) => {
kprint!("{}", text);
}
err => {
error!("Error parsing");
}
}
}
}
use logos::Lexer;
fn parse_text(lex: &mut Lexer<Token>) -> Option<String> {
let slice = lex.slice();
Some(String::from(slice))
}

View File

@ -19,9 +19,9 @@ impl core::fmt::Write for Stdout {
}
#[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::experiments::absi::colorify;
colorify(s);
// kprint!("{}", s);
use crate::{experiments::absi::colorify_2, kprint};
// colorify_2(s);
kprint!("{}", s);
Ok(())
}
#[cfg(target_arch = "riscv64")]

View File

@ -1,4 +1,4 @@
use crate::rhai_shell::rhai_shell;
use crate::{absi::colorify, rhai_shell::rhai_shell};
use {
crate::{
@ -37,7 +37,7 @@ pub fn scratchpad() {
}
*/
// interp();
// crate::experiments::absi::colorify();
rhai_shell();
}