mod tokenizer;
pub use tokenizer::Tokenizer;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TokenType {
Number,
String,
Identifier,
BitString,
HexString,
Parameter,
Select,
From,
Where,
And,
Or,
Not,
As,
Join,
Inner,
Left,
Right,
Full,
Outer,
Cross,
On,
Insert,
Into,
Values,
Update,
Set,
Delete,
Create,
Table,
Drop,
Alter,
Index,
If,
Exists,
In,
Is,
Null,
Like,
ILike,
Between,
Case,
When,
Then,
Else,
End,
Order,
By,
Asc,
Desc,
Group,
Having,
Limit,
Offset,
Union,
All,
Distinct,
True,
False,
Intersect,
Except,
With,
Recursive,
Any,
Some,
Cast,
Over,
Partition,
Window,
Rows,
Range,
Unbounded,
Preceding,
Following,
CurrentRow,
Filter,
Int,
Integer,
BigInt,
SmallInt,
TinyInt,
Float,
Double,
Decimal,
Numeric,
Real,
Varchar,
Char,
Text,
Boolean,
Bool,
Date,
Timestamp,
TimestampTz,
Time,
Interval,
Blob,
Bytea,
Json,
Jsonb,
Uuid,
Array,
Map,
Struct,
Primary,
Key,
Foreign,
References,
Unique,
Check,
Default,
Constraint,
AutoIncrement,
NotNull,
Cascade,
Restrict,
NoAction,
SetNull,
SetDefault,
Returning,
Conflict,
Do,
Nothing,
Replace,
Ignore,
Merge,
Matched,
Using,
Truncate,
Schema,
Database,
View,
Materialized,
Temporary,
Temp,
Begin,
Commit,
Rollback,
Savepoint,
Transaction,
Explain,
Analyze,
Describe,
Show,
Use,
Grant,
Revoke,
Lateral,
Unnest,
Pivot,
Unpivot,
Tablesample,
Fetch,
First,
Next,
Only,
Percent,
WithTies,
Nulls,
Respect,
Top,
Collate,
Comment,
Isnull,
Notnull,
Escape,
Qualify,
Cube,
Rollup,
Grouping,
Sets,
Xor,
Extract,
Epoch,
Year,
Month,
Day,
Hour,
Minute,
Second,
Plus,
Minus,
Star,
Slash,
Percent2, Eq,
Neq, Lt,
Gt,
LtEq,
GtEq,
Concat, BitwiseAnd, BitwiseOr, BitwiseXor, BitwiseNot, ShiftLeft, ShiftRight, DoubleColon, Arrow, DoubleArrow, HashArrow, HashDoubleArrow, AtSign, Scope,
LParen,
RParen,
LBracket, RBracket, LBrace, RBrace, Comma,
Semicolon,
Dot,
Colon,
DoubleColon2,
Whitespace,
LineComment,
BlockComment,
Eof,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Token {
pub token_type: TokenType,
pub value: String,
pub line: usize,
pub col: usize,
pub position: usize,
#[serde(default)]
pub quote_char: char,
}
impl Token {
#[must_use]
pub fn new(token_type: TokenType, value: impl Into<String>, position: usize) -> Self {
Self {
token_type,
value: value.into(),
line: 0,
col: 0,
position,
quote_char: '\0',
}
}
#[must_use]
pub fn with_location(
token_type: TokenType,
value: impl Into<String>,
position: usize,
line: usize,
col: usize,
) -> Self {
Self {
token_type,
value: value.into(),
line,
col,
position,
quote_char: '\0',
}
}
#[must_use]
pub fn with_quote(
token_type: TokenType,
value: impl Into<String>,
position: usize,
line: usize,
col: usize,
quote_char: char,
) -> Self {
Self {
token_type,
value: value.into(),
line,
col,
position,
quote_char,
}
}
}