Skip to main content

Module sqe

Module sqe 

Source
Expand description

Experimental high-performance expression parser.

This module provides a faster alternative to expr_parser and will replace it in a future release. See the module documentation for details. Experimental SQE (Substreams Query Expression) - High-performance boolean expression parser and matcher.

Warning: This module is experimental and will replace the current crate::expr_parser implementation in a future release. The API may change before stabilization.

SQE provides a fast, zero-allocation way to match sets of keys against boolean expressions. It is significantly faster than the current Pest-based implementation:

  • Parsing: 5-9x faster across all expression types
  • Matching: 3-14x faster with zero allocations
  • Repeated matching: 9-14x faster - the main use case sees the biggest wins

§Features

  • Zero-copy parsing: The AST stores byte ranges into the original input, not owned strings.
  • Zero-allocation matching: Once parsed, expressions can be matched without any allocations.
  • Simple grammar: Supports AND (&&), OR (||), implicit AND (whitespace), and grouping ().
  • Quoted keys: Keys with spaces can be quoted with single or double quotes.

§Example

use substreams::sqe::ExprMatcher;

// Parse an expression once
let matcher = ExprMatcher::parse("(a || b) && c").unwrap();

// Match against different key sets (zero allocations)
assert!(matcher.matches_keys(&["a", "c"]));
assert!(matcher.matches_keys(&["b", "c"]));
assert!(!matcher.matches_keys(&["a"]));

§Grammar

expression := or EOF
or         := and (OR and)*
and        := value ((WHITESPACE value) | (AND value))*
value      := KEY | QUOTED_KEY | '(' or ')'

Operator precedence (lowest to highest):

  1. || (OR)
  2. && (AND) / implicit AND (whitespace)
  3. () (grouping)

Structs§

ExprMatcher
An experimental expression matcher that can be used to match keys from a given expression.

Functions§

expr_matcher
Creates a new expression matcher from the given input.