1use crate::Position;
2use std::fmt;
3
4#[derive(Clone, Debug, PartialEq)]
5pub enum Keyword {
6 As,
7 Schema,
8 Table,
9}
10
11impl fmt::Display for Keyword {
12 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13 match self {
14 Keyword::As => write!(f, "as"),
15 Keyword::Schema => write!(f, "schema"),
16 Keyword::Table => write!(f, "table"),
17 }
18 }
19}
20
21#[derive(Clone, Debug, PartialEq)]
22pub enum Symbol {
23 AtSign,
24 Comma,
25 ParenLeft,
26 ParenRight,
27 Period,
28 Underscore,
29}
30
31impl fmt::Display for Symbol {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 match self {
34 Symbol::AtSign => write!(f, "@"),
35 Symbol::Comma => write!(f, ","),
36 Symbol::ParenLeft => write!(f, "("),
37 Symbol::ParenRight => write!(f, ")"),
38 Symbol::Period => write!(f, "."),
39 Symbol::Underscore => write!(f, "_"),
40 }
41 }
42}
43
44#[derive(Clone, Debug, PartialEq)]
45pub enum TokenKind {
46 Bool(bool),
47 Identifier(String),
48 Keyword(Keyword),
49 LineSep,
50 Number(String),
51 QuotedIdentifier(String),
52 Symbol(Symbol),
53 Text(String),
54}
55
56impl fmt::Display for TokenKind {
57 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58 match self {
59 TokenKind::Bool(b) => write!(f, "boolean `{}`", b),
60 TokenKind::Identifier(i) => write!(f, "identifier `{}`", i),
61 TokenKind::Keyword(k) => write!(f, "keyword `{}`", k),
62 TokenKind::LineSep => write!(f, "newline"),
63 TokenKind::Number(n) => write!(f, "number `{}`", n),
64 TokenKind::QuotedIdentifier(i) => write!(f, "quoted identifier `\"{}\"`", i),
65 TokenKind::Symbol(s) => write!(f, "symbol `{}`", s),
66 TokenKind::Text(s) => write!(f, "string '{}'", s),
67 }
68 }
69}
70
71#[derive(Clone, Debug, PartialEq)]
72pub struct Token {
73 pub kind: TokenKind,
74 pub position: Position,
75}