#![doc = include_str!("readme.md")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HighlightKind {
Keyword,
String,
Number,
Comment,
Identifier,
}
pub trait Highlighter {
fn highlight(&self, text: &str) -> Vec<(usize, usize, HighlightKind)>;
}
pub struct AplHighlighter {
pub use_parser: bool,
}
impl Default for AplHighlighter {
fn default() -> Self {
Self { use_parser: false }
}
}
impl AplHighlighter {
pub fn new() -> Self {
Self::default()
}
fn highlight_symbols(&self, text: &str) -> Vec<(usize, usize, HighlightKind)> {
let mut highlights = Vec::new();
let symbols = ['←', '→', '⋄', '⎕', '⍞', '⍴', '⍳', '⍬', '⍣', '⍤', '⍛', '⍢', '⌸', '⌺', '⌼', '⍠', '⌻', '⍃', '⍄', '⍈', '⍐', '⍗', '⍇', '⍈', '⍌', '⍍', '⍏', '⍖'];
for (i, ch) in text.char_indices() {
if symbols.contains(&ch) {
highlights.push((i, i + ch.len_utf8(), HighlightKind::Keyword));
}
}
highlights
}
}
impl Highlighter for AplHighlighter {
fn highlight(&self, text: &str) -> Vec<(usize, usize, HighlightKind)> {
self.highlight_symbols(text)
}
}