pub struct Ast {Show 18 fields
pub statements: Vec<Statement>,
pub queries: Vec<Query>,
pub selects: Vec<Select>,
pub exprs: Vec<Expr>,
pub sources: Vec<Source>,
pub strings: Vec<String>,
pub parts: Vec<StrRef>,
pub expr_lists: Vec<ExprRef>,
pub source_lists: Vec<SourceRef>,
pub targets: Vec<Target>,
pub order_items: Vec<OrderItem>,
pub case_arms: Vec<CaseArm>,
pub create_tables: Vec<CreateTable>,
pub drop_tables: Vec<DropTable>,
pub inserts: Vec<Insert>,
pub column_defs: Vec<ColumnDef>,
pub name_lists: Vec<Slice>,
pub rows: Vec<Slice>,
}Expand description
A parsed statement or script, with every arena it points into.
Cheap to clone, cheap to send, and self contained: no index in here refers to anything outside
it, and nothing in here borrows the query text. The text is copied into strings on the way in,
which costs one allocation per distinct identifier and buys an Ast that outlives the string it
came from.
Fields§
§statements: Vec<Statement>The statements in the script, in order.
queries: Vec<Query>The query arena.
selects: Vec<Select>The select arena.
exprs: Vec<Expr>The expression arena.
sources: Vec<Source>The from-item arena.
strings: Vec<String>Interned text. Identifiers keep the case they were written in, because DuckDB does not fold it at any point, including for quoted identifiers.
parts: Vec<StrRef>Backing store for every Slice of names.
expr_lists: Vec<ExprRef>Backing store for every Slice of expressions.
source_lists: Vec<SourceRef>Backing store for every Slice of from items.
targets: Vec<Target>Backing store for every Slice of target list entries.
order_items: Vec<OrderItem>Backing store for every Slice of order by entries.
case_arms: Vec<CaseArm>Backing store for every Slice of case arms.
create_tables: Vec<CreateTable>The CREATE TABLE arena.
drop_tables: Vec<DropTable>The DROP TABLE arena.
inserts: Vec<Insert>The INSERT arena.
column_defs: Vec<ColumnDef>Backing store for every Slice of column definitions.
name_lists: Vec<Slice>Backing store for every Slice of names, which is a name list rather than a name.
rows: Vec<Slice>Backing store for the rows of a VALUES, each of which is a run of expressions.
Implementations§
Source§impl Ast
impl Ast
Sourcepub fn string(&self, index: StrRef) -> &str
pub fn string(&self, index: StrRef) -> &str
The text behind a StrRef, or the empty string for NONE.
Sourcepub fn parameters(&self) -> Vec<&str>
pub fn parameters(&self) -> Vec<&str>
Every parameter identifier the statement uses, once each, in the order they were written.
The arena is built as the walk goes, so its order is the written order, and a parameter used twice is one identifier here because it is one value to provide.
Sourcepub fn name(&self, slice: Slice) -> impl Iterator<Item = &str>
pub fn name(&self, slice: Slice) -> impl Iterator<Item = &str>
The parts of a name, outermost first.
Sourcepub fn name_text(&self, slice: Slice) -> String
pub fn name_text(&self, slice: Slice) -> String
A name written back out with dots between the parts, for error messages and tests.
Sourcepub fn source_list(&self, slice: Slice) -> &[SourceRef] ⓘ
pub fn source_list(&self, slice: Slice) -> &[SourceRef] ⓘ
The from items of a list.
Sourcepub fn target_list(&self, slice: Slice) -> &[Target]
pub fn target_list(&self, slice: Slice) -> &[Target]
The entries of a target list.
Sourcepub fn order_list(&self, slice: Slice) -> &[OrderItem]
pub fn order_list(&self, slice: Slice) -> &[OrderItem]
The entries of an order by list.
Sourcepub fn create_table(&self, index: CreateTableRef) -> CreateTable
pub fn create_table(&self, index: CreateTableRef) -> CreateTable
One CREATE TABLE.
Sourcepub fn drop_table(&self, index: DropTableRef) -> DropTable
pub fn drop_table(&self, index: DropTableRef) -> DropTable
One DROP TABLE.
Sourcepub fn column_defs(&self, slice: Slice) -> &[ColumnDef]
pub fn column_defs(&self, slice: Slice) -> &[ColumnDef]
The column definitions of a CREATE TABLE.
Sourcepub fn name_list(&self, slice: Slice) -> &[Slice]
pub fn name_list(&self, slice: Slice) -> &[Slice]
The names of a name list, each of which is itself a run of parts.
Sourcepub fn rows(&self, slice: Slice) -> &[Slice]
pub fn rows(&self, slice: Slice) -> &[Slice]
The rows of a VALUES, each of which is itself a run of expressions.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
How many nodes the whole tree is, across every arena.
The number to watch when the transformer changes. A parse tree of five thousand nodes that becomes an AST of thirty is the twenty precedence levels being thrown away, which is the whole reason this module exists.