pub struct Token {
pub token_type: TokenType,
pub literal: SmartString,
pub position: Position,
pub quoted: bool,
}Expand description
Token represents a lexical token
Uses SmartString for literal to avoid heap allocation for tokens up to 24 bytes (covers most SQL tokens: keywords, operators, short identifiers, numbers). For error tokens, the literal field contains the error message.
Fields§
§token_type: TokenTypeThe type of the token
literal: SmartStringThe literal string value (SmartString inlines strings up to 24 bytes) For error tokens, this contains the error message instead.
position: PositionThe position in the source
quoted: boolWhether this token was double-quoted (identifier with string fallback)
Implementations§
Source§impl Token
impl Token
Sourcepub fn new(
token_type: TokenType,
literal: impl AsRef<str>,
position: Position,
) -> Self
pub fn new( token_type: TokenType, literal: impl AsRef<str>, position: Position, ) -> Self
Create a new token
Sourcepub fn new_quoted(
token_type: TokenType,
literal: impl AsRef<str>,
position: Position,
) -> Self
pub fn new_quoted( token_type: TokenType, literal: impl AsRef<str>, position: Position, ) -> Self
Create a new double-quoted token (identifier with string fallback)
Sourcepub fn error(
message: impl AsRef<str>,
_literal: impl AsRef<str>,
position: Position,
) -> Self
pub fn error( message: impl AsRef<str>, _literal: impl AsRef<str>, position: Position, ) -> Self
Create an error token (error message is stored in literal field)
Sourcepub fn is_keyword(&self, keyword: &str) -> bool
pub fn is_keyword(&self, keyword: &str) -> bool
Check if this is a keyword with the given value (case-insensitive)
Sourcepub fn is_operator(&self, op: &str) -> bool
pub fn is_operator(&self, op: &str) -> bool
Check if this is an operator with the given value
Sourcepub fn is_punctuator(&self, punct: &str) -> bool
pub fn is_punctuator(&self, punct: &str) -> bool
Check if this is a punctuator with the given value