Remove token color theming
This commit is contained in:
parent
24414dcdd1
commit
3172d7d460
|
@ -6,7 +6,6 @@ authors = ["Marceline Cramer <mars@tebibyte.media>"]
|
|||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
console = "0.15.0"
|
||||
logos = "0.12.0"
|
||||
pest = "2"
|
||||
pest_derive = "2"
|
||||
|
|
|
@ -204,62 +204,14 @@ impl<'a> Iterator for Lexer<'a> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use console::Style;
|
||||
|
||||
pub struct ColorTheme {
|
||||
normal: Style,
|
||||
keyword: Style,
|
||||
literal: Style,
|
||||
comment: Style,
|
||||
error: Style,
|
||||
}
|
||||
|
||||
impl ColorTheme {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
normal: Style::default(),
|
||||
keyword: Style::new().blue(),
|
||||
literal: Style::new().cyan(),
|
||||
comment: Style::new().white(),
|
||||
error: Style::new().black().on_red().bold(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn token_style(&self, token: &Token) -> &Style {
|
||||
use Token::*;
|
||||
match token {
|
||||
Struct | Function | For | If | Else | In | Let | Mut => &self.keyword,
|
||||
BinaryInteger | OctalInteger | DecimalInteger => &self.literal,
|
||||
SingleLineComment => &self.comment,
|
||||
Error => &self.error,
|
||||
_ => &self.normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lex_file() {
|
||||
let source = include_str!("../test/clock.fae");
|
||||
let theme = ColorTheme::new();
|
||||
let mut lex = Lexer::new(source);
|
||||
|
||||
while let Some(token) = lex.next() {
|
||||
let style = theme.token_style(&token);
|
||||
let styled = style.apply_to(format!("{:?}: {}", token, lex.slice()));
|
||||
println!("{}", styled);
|
||||
println!("{:?}: {}", token, lex.slice());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO use spans to color-code instead of raw tokens, to show original whitespace
|
||||
/*#[test]
|
||||
fn color_file() {
|
||||
let source = include_str!("test/example.fae");
|
||||
let theme = ColorTheme::new();
|
||||
let mut lex = Token::lexer(source);
|
||||
|
||||
while let Some(token) = lex.next() {
|
||||
let style = theme.token_style(&token);
|
||||
print!("{}", style.apply_to(lex.slice()));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue