pub enum Token {
Show 18 variants
Keyword {
keyword: Keyword,
original: String,
},
Identifier(String),
DelimitedIdentifier(String),
Number(String),
String(String),
BlobLiteral(Vec<u8>),
Symbol(char),
Operator(MultiCharOperator),
SessionVariable(String),
UserVariable(String),
Placeholder,
NumberedPlaceholder(usize),
NamedPlaceholder(String),
Semicolon,
Comma,
LParen,
RParen,
Eof,
}Expand description
SQL Token produced by the lexer.
Variants§
Keyword
SQL keyword (SELECT, FROM, etc.) Stores both the keyword variant and original text for error messages. The original text preserves user’s input case (e.g., “SeLeCt”).
Identifier(String)
Identifier (table name, column name, etc.)
DelimitedIdentifier(String)
Delimited identifier (“columnName” - case-sensitive, can use reserved words)
Number(String)
Numeric literal (42, 3.14, etc.)
String(String)
String literal (‘hello’)
BlobLiteral(Vec<u8>)
Blob literal (x’48454C4C4F’ or X’1234’)
Symbol(char)
Single character symbols (+, -, *, /, =, <, >, etc.)
Operator(MultiCharOperator)
Multi-character operators (<=, >=, !=, <>, ||)
SessionVariable(String)
Session variable (@@variable, @@session.variable, @@global.variable)
UserVariable(String)
User variable (@variable)
Placeholder
Parameter placeholder (?) for prepared statements The index is assigned during parsing (0-indexed, in order of appearance)
NumberedPlaceholder(usize)
Numbered parameter placeholder ($1, $2, etc.) for prepared statements PostgreSQL-style: 1-indexed as written in SQL ($1 = first parameter)
NamedPlaceholder(String)
Named parameter placeholder (:name) for prepared statements Used by many ORMs and applications for readability
Semicolon
Semicolon (statement terminator)
Comma
Comma (separator)
LParen
Left parenthesis
RParen
Right parenthesis
Eof
End of input
Implementations§
Source§impl Token
impl Token
Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
Convert token back to valid SQL string. This is the inverse of lexing - it produces SQL that can be re-parsed.
Sourcepub fn syntax_error(&self) -> String
pub fn syntax_error(&self) -> String
Generate a SQLite-compatible syntax error message for this token.
SQLite uses the format: near "TOKEN": syntax error
where TOKEN is the actual text that caused the error.
Special cases:
- EOF (end of input) returns “incomplete input” (SQLite convention for truncated statements)
- Keywords preserve original case from user input (e.g., “SeLeCt”)