tokenizer
ModuleSQL tokenizers: SQL text to Tokens, per dialect.
A Tokenizer splits SQL into keywords, identifiers, literals,
operators, punctuation, placeholders, comments and whitespace, each with
its byte position. Tokenizer::filter drops whitespace and comments,
which is what the Parser reads. Token values
borrow the SQL text where they can, so tokenizing allocates only the
token list.
Rust
use utopia_query::tokenizer::{TokenType, Tokenizer};
let tokens = Tokenizer::filter(Tokenizer::new().tokenize("SELECT * FROM users")?);
let kinds: Vec<TokenType> = tokens.iter().map(|t| t.kind).collect();
assert_eq!(kinds, [TokenType::Keyword, TokenType::Star, TokenType::Keyword, TokenType::Identifier, TokenType::Eof]);
assert_eq!(tokens[3].text(), "users");Contents
use utopia_query::tokenizer::Token;Rust
pub struct Token<'a>One token: its type, its text and its byte position in the SQL.
use utopia_query::tokenizer::Tokenizer;Rust
pub struct TokenizerSplits SQL into Tokens, the way one dialect writes it.
Dialects differ in the identifier quote (a backtick, or a double quote
for PostgreSQL and SQLite), in MySQL's # line comments and in
PostgreSQL's multi-character operators (@>, <@, <=>, <->, <#>,
?|, ?&).
Also implements
Default.use utopia_query::tokenizer::TokenType;Rust
pub enum TokenTypeWhat a Token is.