use sql_dialect_fmt_syntax::SyntaxKind;
use sql_dialect_fmt_text::LineColumn;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Token<'a> {
pub kind: SyntaxKind,
pub text: &'a str,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct LexError {
pub message: String,
pub offset: usize,
pub len: usize,
pub line_column: Option<LineColumn>,
}
impl LexError {
pub fn range(&self) -> std::ops::Range<usize> {
self.offset..self.offset + self.len
}
}
impl std::fmt::Display for LexError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.line_column {
Some(pos) => write!(
f,
"{} at line {}, column {} (byte {})",
self.message, pos.line, pos.column, self.offset
),
None => write!(f, "{} at byte {}", self.message, self.offset),
}
}
}
impl std::error::Error for LexError {}
#[derive(Clone, Debug, Default)]
pub struct Lexed<'a> {
pub tokens: Vec<Token<'a>>,
pub errors: Vec<LexError>,
}