pub struct IncrementalParseSession(/* private fields */);Expand description
Incremental parsing API for the built-in SQLite grammar.
Produced by super::Parser::incremental_parse.
Feed tokens one at a time via feed_token and signal
end of input with finish.
Ideal for editor-like flows that parse as the user types.
Implementations§
Source§impl IncrementalParseSession
impl IncrementalParseSession
Sourcepub fn feed_token(
&mut self,
token_type: TokenType,
span: Range<usize>,
) -> Option<Result<ParsedStatement<'_>, ParseError<'_>>>
pub fn feed_token( &mut self, token_type: TokenType, span: Range<usize>, ) -> Option<Result<ParsedStatement<'_>, ParseError<'_>>>
Feed one source token into the parser.
Returns:
-
None— keep going, statement not yet complete. -
Some(Ok(result))— statement parsed cleanly. -
Some(Err(e))— parse error;e.recovery_root()may contain a partial recovery tree. -
spanis a byte range into the source text bound by this session.
§Examples
use syntaqlite_syntax::{Parser, TokenType};
let parser = Parser::new();
let mut session = parser.incremental_parse("SELECT 1");
assert!(session.feed_token(TokenType::Select, 0..6).is_none());
assert!(session.feed_token(TokenType::Integer, 7..8).is_none());Sourcepub fn finish(&mut self) -> Option<Result<ParsedStatement<'_>, ParseError<'_>>>
pub fn finish(&mut self) -> Option<Result<ParsedStatement<'_>, ParseError<'_>>>
Finalize parsing for the current input.
Returns:
None— nothing was pending.Some(Ok(result))— final statement parsed cleanly.Some(Err(e))— parse error;e.recovery_root()may contain a partial recovery tree.
No further methods may be called after finish().
§Examples
use syntaqlite_syntax::{Parser, TokenType};
let parser = Parser::new();
let mut session = parser.incremental_parse("SELECT 1");
let _ = session.feed_token(TokenType::Select, 0..6);
let _ = session.feed_token(TokenType::Integer, 7..8);
let stmt = session.finish().and_then(Result::ok).unwrap();
let _ = stmt.root();Sourcepub fn expected_tokens(&self) -> impl Iterator<Item = TokenType>
pub fn expected_tokens(&self) -> impl Iterator<Item = TokenType>
Return token types that are currently valid lookaheads.
Sourcepub fn completion_context(&self) -> CompletionContext
pub fn completion_context(&self) -> CompletionContext
Return the semantic completion context for the current parser state.
Sourcepub fn node_count(&self) -> u32
pub fn node_count(&self) -> u32
Return how many arena nodes have been built so far.
Sourcepub fn begin_macro(&mut self, span: Range<usize>)
pub fn begin_macro(&mut self, span: Range<usize>)
Mark subsequent fed tokens as originating from a macro expansion.
Trait Implementations§
Source§impl From<TypedIncrementalParseSession<Grammar>> for IncrementalParseSession
Available on crate feature sqlite only.
impl From<TypedIncrementalParseSession<Grammar>> for IncrementalParseSession
sqlite only.