diff --git a/ableos/src/experiments/absi.rs b/ableos/src/experiments/absi.rs index b709b0dd..d4aecfb7 100644 --- a/ableos/src/experiments/absi.rs +++ b/ableos/src/experiments/absi.rs @@ -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) -> Option { + let slice = lex.slice(); + Some(String::from(slice)) +} diff --git a/ableos/src/print.rs b/ableos/src/print.rs index b1bb0f4c..65b05527 100644 --- a/ableos/src/print.rs +++ b/ableos/src/print.rs @@ -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")] diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index 5a7bcff6..e4645a98 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -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(); }