Skip to main content

Analysis

Struct Analysis 

Source
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>

Source

pub fn new(arena: &'a mut Arena, options: &'a AnalysisOptions) -> Self

Creates a new analysis instance with the given options.

Source

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.

Source

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.

Source

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());
Source

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 behavior
  • expr - The expression to analyze
  • expect - 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());

Auto Trait Implementations§

§

impl<'a> Freeze for Analysis<'a>

§

impl<'a> RefUnwindSafe for Analysis<'a>

§

impl<'a> Send for Analysis<'a>

§

impl<'a> Sync for Analysis<'a>

§

impl<'a> Unpin for Analysis<'a>

§

impl<'a> !UnwindSafe for Analysis<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.