Expand description
Query language: tokenizer, AST, and recursive descent parser.
Implements the grammar from the project doc’s “Notes → Query language grammar” section, extended in v0.2.0 to support OR and in v0.3.0 to support explicit parenthesised grouping.
This module owns only the parse step: &str → QueryNode. Translating
a QueryNode into SQL and binding parameters is the executor’s job.
Resolving relative time ranges like last 2h against wall-clock time
is also the executor’s job; the AST just carries the raw spec.
§Grammar (v0.3.0)
query := or_expr
or_expr := and_expr (OR and_expr)*
and_expr := clause (AND clause)*
clause := field OP value
| field CONTAINS string
| TIME_RANGE
| "(" or_expr ")"
field := [a-zA-Z_][a-zA-Z0-9_.]*
OP := "=" | "!=" | ">" | "<"
value := string | number | bool
string := '"' .* '"' | bare_word
TIME_RANGE := "last" duration | "since" datetime
duration := number ("m" | "h" | "d")AND binds tighter than OR. With parentheses users can override precedence:
(level=error OR level=warn) AND service=payments.
Without parens: level=error AND service=payments OR level=warn parses as
(level=error AND service=payments) OR level=warn.
Structs§
- AndGroup
- A conjunction of one or more clauses, joined by AND.
- Duration
- A relative duration parsed from
last <N><unit>. - Query
Parse Error - Parse error with a byte offset into the original input.
Enums§
- Clause
- A single clause — the atomic unit a query is built from.
- Compare
Op - Comparison operator for
field OP valueclauses. - Duration
Unit - Query
Node - The top-level query: a disjunction of one or more AND-groups.
- Query
Value - A literal value appearing on the right-hand side of a comparison.
Functions§
- parse
- Parse a query string into a
QueryNode.