use crate::highlighter;
use crate::syntax::{Highlight, color};
use logos::Logos;
use ratatui::style::Color;
#[derive(Logos, Debug)]
#[logos(skip r"[ \t\n]+")]
enum TexToken {
#[regex("\\\\.|\\\\[[:alpha:]]*")]
Command,
#[token("{")]
#[token("}")]
Punctuation,
#[token("$")]
Math,
#[regex("%.*", allow_greedy = true)]
Comment,
}
impl TryFrom<TexToken> for Highlight {
type Error = ();
fn try_from(t: TexToken) -> Result<Highlight, ()> {
match t {
TexToken::Command => Ok(Color::Green.into()),
TexToken::Punctuation => Ok(Color::Magenta.into()),
TexToken::Math => Ok(Color::Red.into()),
TexToken::Comment => Ok(color::COMMENT),
}
}
}
#[derive(Debug)]
pub struct Tex;
impl std::fmt::Display for Tex {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
"TeX".fmt(f)
}
}
highlighter!(Tex, TexToken);