synoptic 1.2.0

A simple, low-level, syntax highlighting library with unicode support
Documentation
use unicode_width::UnicodeWidthChar;

/// For storing tokens to put into a string
/// It has a start token, to mark the start of a token
/// It has a text token, for the text inbetween and inside tokens
/// It also has an end token, to mark the end of a token
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Token {
    Start(String),
    Text(String),
    End(String),
}

/// An alternative way to store tokens, makes it easy to trim them
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TokOpt {
    Some(String, String),
    None(String),
}

impl TokOpt {
    /// Determines if this token is empty
    #[must_use]
    pub fn is_empty(&self) -> bool {
        let (TokOpt::Some(text, _) | TokOpt::None(text)) = self;
        text.len() == 0
    }

    /// Takes a single character off the front of a token
    pub fn nibble(&mut self) -> Option<char> {
        let (TokOpt::Some(ref mut text, _) | TokOpt::None(ref mut text)) = self;
        let ch = *text.chars().collect::<Vec<_>>().get(0)?;
        text.remove(0);
        if UnicodeWidthChar::width(ch)? > 1 {
            text.insert(0, ' ');
        }
        Some(ch)
    }
}

/// For storing all the data in a token to prevent overwriting
/// This contains the contents, type, start and end of the token
/// This is used to compare tokens to each other to prevent tokens inside tokens
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct FullToken {
    pub text: String,
    pub kind: String,
    pub start: usize,
    pub end: usize,
    pub multi: bool,
}

impl FullToken {
    /// Returns the length of the token
    #[must_use]
    pub fn len(&self) -> usize {
        self.text.len()
    }

    /// Determines if the token is empty
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

/// For representing a bounded token definition
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Bounded {
    pub kind: String,
    pub start: String,
    pub end: String,
    pub escaping: bool,
}