pub struct Analysis<'a> { /* private fields */ }Expand description
A type checker and static analyzer for EventQL expressions.
This struct maintains the analysis state including scopes and type information. It can be used to perform type checking on individual expressions or entire queries.
Implementations§
Source§impl<'a> Analysis<'a>
impl<'a> Analysis<'a>
Sourcepub fn new(arena: &'a mut Arena, options: &'a AnalysisOptions) -> Self
pub fn new(arena: &'a mut Arena, options: &'a AnalysisOptions) -> Self
Creates a new analysis instance with the given options.
Sourcepub fn scope(&self) -> &Scope
pub fn scope(&self) -> &Scope
Returns a reference to the current scope.
The scope contains variable bindings and their types for the current
analysis context. Note that this only includes local variable bindings
and does not include global definitions such as built-in functions
(e.g., COUNT, NOW) or event type information, which are stored
in the AnalysisOptions.
Sourcepub fn scope_mut(&mut self) -> &mut Scope
pub fn scope_mut(&mut self) -> &mut Scope
Returns a mutable reference to the current scope.
This allows you to modify the scope by adding or removing variable bindings.
This is useful when you need to set up custom type environments before
analyzing expressions. Note that this only provides access to local variable
bindings; global definitions like built-in functions are managed through
AnalysisOptions and cannot be modified via the scope.
Sourcepub fn analyze_query(
&mut self,
query: Query<Raw>,
) -> AnalysisResult<Query<Typed>>
pub fn analyze_query( &mut self, query: Query<Raw>, ) -> AnalysisResult<Query<Typed>>
Performs static analysis on a parsed query.
This method analyzes an entire EventQL query, performing type checking on all clauses including sources, predicates, group by, order by, and projections. It returns a typed version of the query with type information attached.
§Arguments
query- A parsed query in its raw (untyped) form
§Returns
Returns a typed query with all type information resolved, or an error if type checking fails for any part of the query.
§Example
use eventql_parser::Session;
let mut session = Session::builder().build();
let query = session.parse("FROM e IN events WHERE [1,2,3] CONTAINS e.data.price PROJECT INTO e").unwrap();
let typed_query = session.run_static_analysis(query);
assert!(typed_query.is_ok());Sourcepub fn analyze_expr(
&mut self,
ctx: &mut AnalysisContext,
expr: ExprRef,
expect: Type,
) -> AnalysisResult<Type>
pub fn analyze_expr( &mut self, ctx: &mut AnalysisContext, expr: ExprRef, expect: Type, ) -> AnalysisResult<Type>
Analyzes an expression and checks it against an expected type.
This method performs type checking on an expression, verifying that all operations are type-safe and that the expression’s type is compatible with the expected type.
§Arguments
ctx- The analysis context controlling analysis behaviorexpr- The expression to analyzeexpect- The expected type of the expression
§Returns
Returns the actual type of the expression after checking compatibility with the expected type, or an error if type checking fails.
§Example
use eventql_parser::Session;
let mut session = Session::builder().build();
let query = session.parse("FROM e IN events PROJECT INTO { price: 1 + 2 }").unwrap();
let result = session.run_static_analysis(query);
assert!(result.is_ok());