Skip to content

Conversation

@YoEight
Copy link
Owner

@YoEight YoEight commented Dec 31, 2025

Summary

This PR adds static analysis and type checking capabilities to the EventQL parser. Queries can now be validated for type correctness and variable scoping before execution, catching errors at parse-time rather than runtime.

Key Features

Static Analysis Engine

  • Type Checking: Validates that expressions use correct types (numbers, strings, booleans, records, arrays)
  • Variable Scoping: Ensures all variables are properly declared and in scope
  • Field Access Validation: Verifies that record field accesses are valid for their types
  • Function Call Validation: Checks that function calls have correct argument types

Type System

  • Introduced Typed marker type to distinguish analyzed queries from raw queries at compile-time
  • Query<Raw>: Parsed but untyped queries
  • Query<Typed>: Type-checked queries with validated scopes and type information
  • Provides compile-time guarantees about query type safety

Built-in Functions

The default scope includes type signatures for:

  • Math functions: ABS, CEIL, FLOOR, ROUND, COS, EXP, POW, SQRT, RAND, PI
  • String functions: LOWER, UPPER, TRIM, LTRIM, RTRIM, LEN, INSTR, SUBSTRING, REPLACE, STARTSWITH, ENDSWITH
  • Date/time functions: NOW, YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEKDAY
  • Aggregate functions: COUNT, SUM, AVG, MIN, MAX, MEDIAN, STDDEV, VARIANCE, UNIQUE
  • Control flow: IF

Implementation Details

  • Scope Management: Implements hierarchical scoping with enter/exit scope tracking
  • Type Inference: Supports gradual typing with Type::Unspecified for dynamic data fields
  • Bidirectional Type Checking: Uses expected types to guide inference in ambiguous cases
  • Dynamic Field Handling: Special handling for the data field to support flexible JSON payloads

@YoEight YoEight marked this pull request as draft December 31, 2025 22:03
@YoEight YoEight marked this pull request as ready for review January 2, 2026 01:03
@YoEight YoEight merged commit 9f20265 into master Jan 2, 2026
4 checks passed
@YoEight YoEight deleted the static-analysis branch January 2, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants