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
Parserfor typicalSQLiteSQL app code.
Implementations§
Source§impl<G: TypedGrammar> TypedParser<G>
impl<G: TypedGrammar> TypedParser<G>
Sourcepub fn new(grammar: G) -> Self
pub fn new(grammar: G) -> Self
Create a parser for grammar G with default ParserConfig.
Sourcepub fn with_config(grammar: G, config: &ParserConfig) -> Self
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).
Sourcepub fn parse(&self, source: &str) -> TypedParseSession<G>
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.
Sourcepub fn register_macro(&mut self, name: &str, params: &[&str], body: &str)
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.
Sourcepub fn deregister_macro(&mut self, name: &str) -> bool
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.
Sourcepub fn incremental_parse(&self, source: &str) -> TypedIncrementalParseSession<G>
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.