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_parserimplementation 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):
||(OR)&&(AND) / implicit AND (whitespace)()(grouping)
Structs§
- Expr
Matcher - 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.