pub struct ParserToken<'a>(/* private fields */);Expand description
One parser-observed token from a parsed statement.
Returned by [ParsedStatement::tokens]. This is useful when building
token-aware tooling such as:
- Semantic syntax highlighting.
- Identifier/function/type classification.
- Statement-level token diagnostics.
Requires collect_tokens: true in ParserConfig.
§Examples
use syntaqlite_syntax::{Parser, ParserConfig, TokenType};
let parser = Parser::with_config(&ParserConfig::default().with_collect_tokens(true));
let mut session = parser.parse("SELECT max(x) FROM t;");
let stmt = session.next().transpose().unwrap().unwrap();
let tokens: Vec<_> = stmt.tokens().collect();
assert!(!tokens.is_empty());
assert!(tokens.iter().any(|t| t.token_type() == TokenType::Select));
// Flags expose parser-inferred role information (identifier/function/type).
let _has_semantic_role = tokens.iter().any(|t| {
let f = t.flags();
f.used_as_identifier() || f.used_as_function() || f.used_as_type()
});Implementations§
Source§impl<'a> ParserToken<'a>
impl<'a> ParserToken<'a>
Sourcepub fn text(&self) -> &'a str
pub fn text(&self) -> &'a str
Exact source text for this token.
Preserves original casing and quoting from input SQL.
Sourcepub fn token_type(&self) -> TokenType
pub fn token_type(&self) -> TokenType
Token kind from the SQLite SQL grammar.
This is the lexical class (keyword, identifier, operator, etc.).
Sourcepub fn flags(&self) -> ParserTokenFlags
pub fn flags(&self) -> ParserTokenFlags
Semantic usage flags inferred by the parser.
Use this to distinguish contextual role, for example:
- Keyword text used as an identifier.
- Function-call names.
- Type names.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ParserToken<'a>
impl<'a> RefUnwindSafe for ParserToken<'a>
impl<'a> Send for ParserToken<'a>
impl<'a> Sync for ParserToken<'a>
impl<'a> Unpin for ParserToken<'a>
impl<'a> UnsafeUnpin for ParserToken<'a>
impl<'a> UnwindSafe for ParserToken<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more