Skip to main content

ParseSession

Struct ParseSession 

Source
pub struct ParseSession(/* private fields */);
Expand description

Cursor over statements parsed from one SQL source string.

Useful for SQL scripts containing multiple statements.

  • Returns one statement at a time via next.
  • Reports errors per statement instead of failing the whole script immediately.
  • Can continue after recoverable errors.

Implementations§

Source§

impl ParseSession

Source

pub fn next(&mut self) -> ParseOutcome<ParsedStatement<'_>, ParseError<'_>>

Parse and return the next statement as a tri-state outcome.

Mirrors C parser return codes directly:

Source

pub fn source(&self) -> &str

Original SQL source bound to this session.

Source

pub fn arena_result(&self) -> AnyParsedStatement<'_>

Return a grammar-agnostic view over the current parse arena state.

Useful for generic introspection after consuming the session.

§Examples
let parser = syntaqlite_syntax::Parser::new();
let mut session = parser.parse("SELECT 1;");
let stmt = match session.next().transpose() {
    Ok(Some(stmt)) => stmt,
    Ok(None) => panic!("expected statement"),
    Err(err) => panic!("unexpected parse error: {err}"),
};
let _ = stmt.root();

let any = session.arena_result();
assert!(!any.root_id().is_null());