use crate::highlighter;
use crate::syntax::{Highlight, color};
use logos::Logos;
use ratatui::style::Color;
#[derive(Logos, Debug)]
#[logos(skip r"[ \t\n]+")]
enum FishToken {
#[regex("#.*", allow_greedy = true)]
Comment,
#[token("alias")]
#[token("bind")]
#[token("builtin")]
#[token("cd")]
#[token("command")]
#[token("echo")]
#[token("eval")]
#[token("exec")]
#[token("exit")]
#[token("false")]
#[token("fg")]
#[token("function")]
#[token("help")]
#[token("history")]
#[token("jobs")]
#[token("kill")]
#[token("set")]
#[token("true")]
#[token("umask")]
#[token("wait")]
Keyword,
#[token("and")]
#[token("or")]
#[token("not")]
#[token("begin")]
#[token("end")]
#[token("if")]
#[token("else")]
#[token("while")]
#[token("for")]
#[token("switch")]
#[token("case")]
#[token("break")]
#[token("continue")]
#[token("return")]
#[token("in")]
Loop,
#[regex("\\$[[:alnum:]_]+")]
Variable,
#[regex("\\S+", priority = 3)]
Misc,
}
impl TryFrom<FishToken> for Highlight {
type Error = ();
fn try_from(t: FishToken) -> Result<Highlight, ()> {
match t {
FishToken::Comment => Ok(color::COMMENT),
FishToken::Keyword => Ok(color::KEYWORD),
FishToken::Loop => Ok(color::FLOW),
FishToken::Variable => Ok(Color::Cyan.into()),
FishToken::Misc => Err(()),
}
}
}
#[derive(Debug)]
pub struct Fish;
impl std::fmt::Display for Fish {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
"Fish".fmt(f)
}
}
highlighter!(Fish, FishToken);