string colorizer

This commit is contained in:
Able 2022-02-21 07:17:16 -06:00
parent 7fc1606a18
commit f6143d3895
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();
}