sql_dialect_fmt_lexer/
token.rs1use sql_dialect_fmt_syntax::SyntaxKind;
4use sql_dialect_fmt_text::LineColumn;
5
6#[derive(Clone, Copy, PartialEq, Eq, Debug)]
8pub struct Token<'a> {
9 pub kind: SyntaxKind,
10 pub text: &'a str,
11}
12
13#[derive(Clone, PartialEq, Eq, Debug)]
15pub struct LexError {
16 pub message: String,
17 pub offset: usize,
19 pub len: usize,
22 pub line_column: Option<LineColumn>,
24}
25
26impl LexError {
27 pub fn range(&self) -> std::ops::Range<usize> {
29 self.offset..self.offset + self.len
30 }
31}
32
33impl std::fmt::Display for LexError {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 match self.line_column {
36 Some(pos) => write!(
37 f,
38 "{} at line {}, column {} (byte {})",
39 self.message, pos.line, pos.column, self.offset
40 ),
41 None => write!(f, "{} at byte {}", self.message, self.offset),
42 }
43 }
44}
45
46impl std::error::Error for LexError {}
47
48#[derive(Clone, Debug, Default)]
50pub struct Lexed<'a> {
51 pub tokens: Vec<Token<'a>>,
52 pub errors: Vec<LexError>,
53}