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
impl Session
Sourcepub fn builder() -> SessionBuilder
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.
Sourcepub fn tokenize<'a>(&self, input: &'a str) -> Result<Vec<Token<'a>>>
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 (
(,),[,],{,},.,,,:)
Sourcepub fn parse(&mut self, input: &str) -> Result<Query<Raw>>
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());Sourcepub fn run_static_analysis(&mut self, query: Query<Raw>) -> Result<Query<Typed>>
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 scopequery- The raw query to analyze
§Returns
Returns a typed query on success, or an AnalysisError if type checking fails.
Sourcepub fn resolve_type(&self, name: &str) -> Option<Type>
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 typeNone- If the name doesn’t match any known type
§Built-in Type Mappings
The following type names are recognized (case-insensitive):
"string"→Type::String"int"or"float64"→Type::Number"boolean"→Type::Bool"date"→Type::Date"time"→Type::Time"datetime"→Type::DateTime
note: Registered custom types are also recognized (case-insensitive).
Sourcepub fn display_type(&self, tpe: Type) -> String
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.
Sourcepub fn analysis(&mut self) -> Analysis<'_>
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.
Sourcepub fn global_scope(&self) -> &Scope
pub fn global_scope(&self) -> &Scope
Returns the global Scope