Skip to main content

Grammar

Trait Grammar 

Source
pub trait Grammar: Send + Sync {
Show 60 methods // Required methods fn statement_keywords(&self) -> &[&str]; fn dispatch_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>; // Provided methods fn parse_table_hint(&self, _ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn dispatch_ansi_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_file(&self, ctx: &mut ParseContext<'_>) -> Segment { ... } fn parse_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_select_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_select_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_select_target(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_from_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_table_reference( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_table_reference_core( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_where_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_group_by_clause( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_having_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_order_by_clause( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_order_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_limit_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_offset_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_with_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_cte_definition( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_set_operation(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_join_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_insert_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_values_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_update_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_set_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_delete_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_create_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_create_table_body( &self, ctx: &mut ParseContext<'_>, children: Vec<Segment>, ) -> Option<Segment> { ... } fn parse_drop_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_alter_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_or_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_and_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_not_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_comparison_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_addition_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_multiplication_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_unary_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_primary_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_paren_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_paren_subquery( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_case_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_when_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_exists_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_cast_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_data_type(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_identifier(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_qualified_name( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_name_or_function( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_over_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn parse_partition_by_clause( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_window_order_by( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_window_frame_clause( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn parse_simple_statement( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment> { ... } fn peek_statement_start(&self, ctx: &ParseContext<'_>) -> bool { ... } fn consume_until_statement_end( &self, ctx: &mut ParseContext<'_>, children: &mut Vec<Segment>, ) { ... } fn parse_paren_block(&self, ctx: &mut ParseContext<'_>) -> Option<Segment> { ... } fn consume_until_end( &self, ctx: &mut ParseContext<'_>, children: &mut Vec<Segment>, ) { ... }
}
Expand description

Trait for dialect-specific SQL grammar.

Dialects implement dispatch_statement and statement_keywords. All shared ANSI parsing logic lives in default methods.

Required Methods§

Source

fn statement_keywords(&self) -> &[&str]

Return the set of keywords that can start a statement in this dialect.

Source

fn dispatch_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Dispatch a single statement based on the current token. Called from parse_statement after consuming leading trivia.

Provided Methods§

Source

fn parse_table_hint(&self, _ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse an optional table hint after a table reference. Default returns None (ANSI has no table hints). TSQL overrides this to handle WITH(NOLOCK) etc.

Source

fn dispatch_ansi_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

ANSI-only statement dispatch. Dialect impls can call this as fallback.

Source

fn parse_file(&self, ctx: &mut ParseContext<'_>) -> Segment

Parse a complete SQL file: zero or more statements.

Source

fn parse_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse a single statement (terminated by ; or EOF).

Source

fn parse_select_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_select_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_select_target(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_from_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_table_reference(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_table_reference_core( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Core table reference parsing (name/subquery + optional alias), without table hints. Called by parse_table_reference.

Source

fn parse_where_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_group_by_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_having_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_order_by_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_order_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_limit_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_offset_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_with_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_cte_definition(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_set_operation(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_join_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_insert_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_values_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_update_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_set_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_delete_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_create_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_create_table_body( &self, ctx: &mut ParseContext<'_>, children: Vec<Segment>, ) -> Option<Segment>

Source

fn parse_drop_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_alter_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse an expression. This uses a simple precedence climbing approach.

Source

fn parse_or_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_and_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_not_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_comparison_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Source

fn parse_addition_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Source

fn parse_multiplication_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Source

fn parse_unary_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_primary_expression( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Source

fn parse_paren_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_paren_subquery(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_case_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_when_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_exists_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_cast_expression(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_data_type(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_identifier(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_qualified_name(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse a possibly qualified name: a, a.b, a.b.c

Source

fn parse_name_or_function(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Source

fn parse_over_clause(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse OVER clause: OVER (PARTITION BY ... ORDER BY ... ROWS/RANGE ...) or OVER window_name

Source

fn parse_partition_by_clause( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Parse PARTITION BY expr, expr, …

Source

fn parse_window_order_by(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse ORDER BY inside a window spec (reuses expression parsing).

Source

fn parse_window_frame_clause( &self, ctx: &mut ParseContext<'_>, ) -> Option<Segment>

Parse window frame: ROWS/RANGE/GROUPS frame_spec

Source

fn parse_simple_statement(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse a simple statement (USE, TRUNCATE, etc.) by consuming until end.

Source

fn peek_statement_start(&self, ctx: &ParseContext<'_>) -> bool

Check if current token looks like the start of a new statement.

Source

fn consume_until_statement_end( &self, ctx: &mut ParseContext<'_>, children: &mut Vec<Segment>, )

Consume tokens until semicolon, EOF, or start of new statement. Consume tokens until semicolon, EOF, or start of a new statement. Tracks paren depth so that keywords inside subqueries (e.g. SELECT within (SELECT ...)) do not cause premature termination.

Source

fn parse_paren_block(&self, ctx: &mut ParseContext<'_>) -> Option<Segment>

Parse parenthesized content as a simple block.

Source

fn consume_until_end( &self, ctx: &mut ParseContext<'_>, children: &mut Vec<Segment>, )

Consume tokens until the end of a statement.

The ANSI default tracks paren and CASE/END depth, stopping at semicolons or EOF. TSQL overrides this to additionally track BEGIN/END blocks and the GO batch separator.

Implementors§