Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

Session is the main entry point for parsing and analyzing EventQL queries.

It holds the necessary context, such as the expression arena and analysis options, to perform lexical analysis, parsing, and static analysis of EQL query strings.

Implementations§

Source§

impl Session

Source

pub fn builder() -> SessionBuilder

Creates a new SessionBuilder for configuring and building a Session.

This is the recommended way to create a Session instance, allowing for customization of functions, event types, and custom types.

§Returns

A new SessionBuilder instance.

Source

pub fn tokenize<'a>(&self, input: &'a str) -> Result<Vec<Token<'a>>>

Tokenize an EventQL query string.

This function performs lexical analysis on the input string, converting it into a sequence of tokens. Each token includes position information (line and column numbers) for error reporting.

§Recognized Tokens
  • Identifiers: Alphanumeric names starting with a letter (e.g., events, e)
  • Keywords: Case-insensitive SQL-like keywords detected by the parser
  • Numbers: Floating-point literals (e.g., 42, 3.14)
  • Strings: Double-quoted string literals (e.g., "hello")
  • Operators: Arithmetic (+, -, *, /), comparison (==, !=, <, <=, >, >=), logical (AND, OR, XOR, NOT)
  • Symbols: Structural characters ((, ), [, ], {, }, ., ,, :)
Source

pub fn parse(&mut self, input: &str) -> Result<Query<Raw>>

Parse an EventQL query string into an abstract syntax tree.

This is the main entry point for parsing EventQL queries. It performs both lexical analysis (tokenization) and syntactic analysis (parsing) in a single call.

§Examples
use eventql_parser::Session;

// Parse a simple query
let mut session = Session::builder().use_stdlib().build();
let query = session.parse("FROM e IN events WHERE e.id == \"1\" PROJECT INTO e").unwrap();
assert!(query.predicate.is_some());
Source

pub fn run_static_analysis(&mut self, query: Query<Raw>) -> Result<Query<Typed>>

Performs static analysis on an EventQL query.

This function takes a raw (untyped) query and performs type checking and variable scoping analysis. It validates that:

  • All variables are properly declared
  • Types match expected types in expressions and operations
  • Field accesses are valid for their record types
  • Function calls have the correct argument types
  • Aggregate functions are only used in PROJECT INTO clauses
  • Aggregate functions are not mixed with source-bound fields in projections
  • Aggregate function arguments are source-bound fields (not constants or function results)
  • Record literals are non-empty in projection contexts
§Arguments
  • options - Configuration containing type information and default scope
  • query - The raw query to analyze
§Returns

Returns a typed query on success, or an AnalysisError if type checking fails.

Source

pub fn resolve_type(&self, name: &str) -> Option<Type>

Converts a type name string to its corresponding Type variant.

This function performs case-insensitive matching for built-in type names and checks against custom types defined in the analysis options.

§Returns
  • Some(Type) - If the name matches a built-in type or custom type
  • None - If the name doesn’t match any known type
§Built-in Type Mappings

The following type names are recognized (case-insensitive):

note: Registered custom types are also recognized (case-insensitive).

Source

pub fn display_type(&self, tpe: Type) -> String

Provides human-readable string formatting for types.

Function types display optional parameters with a ? suffix. For example, a function with signature (boolean, number?) -> string accepts 1 or 2 arguments. Aggregate functions use => instead of -> in their signature.

Source

pub fn analysis(&mut self) -> Analysis<'_>

Creates an Analysis instance for fine-grained control over static analysis.

Use this when you need to analyze individual expressions or manage scopes manually, rather than using run_static_analysis for whole queries.

Source

pub fn arena(&self) -> &Arena

Returns a reference to the underlying Arena.

Source

pub fn arena_mut(&mut self) -> &mut Arena

Returns a mutable reference to the underlying Arena.

Source

pub fn global_scope(&self) -> &Scope

Returns the global Scope

Auto Trait Implementations§

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.