use unicode_width::UnicodeWidthChar;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Token {
Start(String),
Text(String),
End(String),
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TokOpt {
Some(String, String),
None(String),
}
impl TokOpt {
#[must_use]
pub fn is_empty(&self) -> bool {
let (TokOpt::Some(text, _) | TokOpt::None(text)) = self;
text.len() == 0
}
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)
}
}
#[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 {
#[must_use]
pub fn len(&self) -> usize {
self.text.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Bounded {
pub kind: String,
pub start: String,
pub end: String,
pub escaping: bool,
}