Skip to main content

TypedParser

Struct TypedParser 

Source
pub struct TypedParser<G: TypedGrammar> { /* private fields */ }
Expand description

Parser API parameterized by grammar type G.

Primarily for library/framework code over generated grammars.

  • Use this when grammar type is known at compile time.
  • Use top-level Parser for typical SQLite SQL app code.

Implementations§

Source§

impl<G: TypedGrammar> TypedParser<G>

Source

pub fn new(grammar: G) -> Self

Create a parser for grammar G with default ParserConfig.

Source

pub fn with_config(grammar: G, config: &ParserConfig) -> Self

Create a parser for grammar G with custom ParserConfig.

§Panics

Panics if parser allocation fails (out of memory).

Source

pub fn parse(&self, source: &str) -> TypedParseSession<G>

Parse a SQL script and return a typed statement session.

§Examples
use syntaqlite_syntax::typed::{grammar, TypedParser};
use syntaqlite_syntax::ParseOutcome;

let parser = TypedParser::new(grammar());
let mut session = parser.parse("SELECT 1;");
let stmt = match session.next() {
    ParseOutcome::Ok(stmt) => stmt,
    ParseOutcome::Done => panic!("expected statement"),
    ParseOutcome::Err(err) => panic!("unexpected parse error: {err}"),
};
assert!(stmt.root().is_some());
§Panics

Panics if another session from this parser is still active. Drop the previous session before starting a new one.

Source

pub fn register_macro(&mut self, name: &str, params: &[&str], body: &str)

Start incremental parsing for grammar G.

Use this when tokens arrive over time (editor completion, interactive parsing, macro-expansion pipelines).

§Examples
use syntaqlite_syntax::typed::{grammar, TypedParser};
use syntaqlite_syntax::TokenType;

let parser = TypedParser::new(grammar());
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 _ = session.finish();
§Panics

Panics if another session from this parser is still active. Drop the previous session before starting a new one. Register a template macro with the parser.

The macro name will be expanded when name!(args) is encountered during batch parsing (parse()). The body uses $param placeholders that are substituted with the corresponding arguments.

§Panics

Panics if another session from this parser is still active.

Source

pub fn deregister_macro(&mut self, name: &str) -> bool

Deregister a macro by name.

Returns true if the macro was found and removed.

§Panics

Panics if another session from this parser is still active.

Source

pub fn incremental_parse(&self, source: &str) -> TypedIncrementalParseSession<G>

Start incremental parsing for grammar G.

Use this when tokens arrive over time (editor completion, interactive parsing, macro-expansion pipelines).

§Panics

Panics if another session from this parser is still active. Drop the previous session before starting a new one.

Auto Trait Implementations§

§

impl<G> Freeze for TypedParser<G>

§

impl<G> !RefUnwindSafe for TypedParser<G>

§

impl<G> !Send for TypedParser<G>

§

impl<G> !Sync for TypedParser<G>

§

impl<G> Unpin for TypedParser<G>
where G: Unpin,

§

impl<G> UnsafeUnpin for TypedParser<G>

§

impl<G> !UnwindSafe for TypedParser<G>

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.