Skip to main content

IncrementalParseSession

Struct IncrementalParseSession 

Source
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

Source

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.

  • span is 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());
Source

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();
Source

pub fn expected_tokens(&self) -> impl Iterator<Item = TokenType>

Return token types that are currently valid lookaheads.

Source

pub fn completion_context(&self) -> CompletionContext

Return the semantic completion context for the current parser state.

Source

pub fn node_count(&self) -> u32

Return how many arena nodes have been built so far.

Source

pub fn begin_macro(&mut self, span: Range<usize>)

Mark subsequent fed tokens as originating from a macro expansion.

Source

pub fn end_macro(&mut self)

End the innermost macro expansion region.

Trait Implementations§

Source§

impl From<TypedIncrementalParseSession<Grammar>> for IncrementalParseSession

Available on crate feature sqlite only.
Source§

fn from(inner: TypedIncrementalParseSession<Grammar>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.