src/sydra/query/ast.zig
Purpose
Defines the sydraQL abstract syntax tree (AST) produced by the parser and consumed by later stages.
Every syntactic node carries a Span (a half-open byte range into the original query text) so later stages can attach diagnostics.
Definition index (public)
pub const Statement = union(enum) { ... }
Top-level statement variants:
invalid: Invalidselect: *const Selectinsert: *const Insertdelete: *const Deleteexplain: *const Explain
Notes:
- The parser allocates statement payload structs (
Select,Insert, …) and stores pointers in theStatementunion. - In the current implementation, these allocations typically live in an arena owned by the execution cursor (see
src/sydra/query/exec.zig).
pub const Invalid = struct { ... }
span: Span
pub const Select = struct { ... }
Represents a SELECT statement:
projections: []const Projectionselector: ?Selector— present whenFROMwas providedpredicate: ?*const Expr— present whenWHEREwas providedgroupings: []const GroupExprfill: ?FillClauseordering: []const OrderExprlimit: ?LimitClausespan: Span
pub const Insert = struct { ... }
Represents an INSERT statement:
series: Identifiercolumns: []const Identifier— may be empty if no column list is providedvalues: []const *const Expr— expression list insideVALUES (...)span: Span
pub const Delete = struct { ... }
Represents a DELETE statement:
selector: Selectorpredicate: ?*const Exprspan: Span
pub const Explain = struct { ... }
Represents EXPLAIN <statement>:
target: *const Statementspan: Span
pub const Selector = struct { ... }
Selects a series to read from:
series: SeriesReftag_filter: ?*const Expr— currently alwaysnullin the parser implementationspan: Span
pub const SeriesRef = union(enum) { ... }
name: Identifier— series name pathby_id: ById— special selectorby_id(<u64>)
pub const ById = struct { ... }
value: u64span: Span
pub const Identifier = struct { ... }
value: []const u8— slice of the original source (may include dots)quoted: bool— true when any segment came from a quoted identifierspan: Span
pub const LimitClause = struct { ... }
limit: usizeoffset: ?usizespan: Span
pub const LiteralValue = union(enum) { ... }
integer: i64float: f64string: []const u8boolean: boolnull
pub const Literal = struct { ... }
value: LiteralValuespan: Span
pub const BinaryOp = enum { ... }
Binary operators:
add, subtract, multiply, divide, modulo,
equal, not_equal,
less, less_equal, greater, greater_equal,
regex_match, regex_not_match,
logical_and, logical_or
pub const UnaryOp = enum { ... }
negate, logical_not, positive
pub const Expr = union(enum) { ... }
Expression variants:
identifier: Identifierliteral: Literalcall: Callbinary: Binaryunary: Unary
pub const Projection = struct { ... }
A projection item in a SELECT list:
expr: *const Expralias: ?Identifierspan: Span
pub const GroupExpr = struct { ... }
expr: *const Exprspan: Span
pub const FillStrategy = union(enum) { ... }
previouslinearnull_valueconstant: *const Expr
pub const FillClause = struct { ... }
strategy: FillStrategyspan: Span
pub const OrderDirection = enum { ... }
ascdesc
pub const OrderExpr = struct { ... }
expr: *const Exprdirection: OrderDirectionspan: Span
pub const Call = struct { ... }
callee: Identifierargs: []const *const Exprspan: Span
pub const Binary = struct { ... }
op: BinaryOpleft: *const Exprright: *const Exprspan: Span
pub const Unary = struct { ... }
op: UnaryOpoperand: *const Exprspan: Span
pub fn placeholderStatement(span: Span) Statement
Creates a synthetic .invalid statement (used for placeholders or error recovery).
Notes on memory ownership
The parser allocates Expr and statement payload structs using its allocator.
In the HTTP surface, exec.execute constructs an arena allocator for parsing/planning artifacts and attaches it to the returned ExecutionCursor, so:
- AST pointers remain valid while the cursor is in use.
cursor.deinit()releases the arena allocations.
Code excerpt
pub const Statement = union(enum) {
invalid: Invalid,
select: *const Select,
insert: *const Insert,
delete: *const Delete,
explain: *const Explain,
};
pub const Select = struct {
projections: []const Projection,
selector: ?Selector,
predicate: ?*const Expr,
groupings: []const GroupExpr,
fill: ?FillClause,
ordering: []const OrderExpr,
limit: ?LimitClause,
span: common.Span,
};
pub const Expr = union(enum) {
identifier: Identifier,
literal: Literal,
call: Call,
binary: Binary,
unary: Unary,
};