Add FilterBar query language parser (pest grammar)
Introduces a standalone src/filter_parser.rs module (no dependency on
engine/index types) that parses the FilterBar query language into a
FilterExpr AST using a pest grammar (src/filter_parser.pest). Supports
regex("...") searches, metric_name[param] <op> value comparisons,
reserved sequence/timestamp metrics, and and/or combinators with
correct precedence (and binds tighter than or) and parenthesized
sub-expressions. Evaluation against real log data is left to a later
integration ticket.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XFUNZwCvz3kcod3352ZR2o
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
1fb564d06b
commit
202b1dcf9f
@@ -0,0 +1,42 @@
|
||||
// Grammar for the FilterBar query language.
|
||||
//
|
||||
// Supports:
|
||||
// - regex("...") raw-text regex search over log lines
|
||||
// - metric_name[param] <op> value metric comparisons
|
||||
// - sequence <op> value reserved metric name (no [param])
|
||||
// - timestamp <op> value reserved metric name (no [param])
|
||||
// - `and` / `or` boolean combinators, with `and` binding tighter than `or`
|
||||
// - parenthesized sub-expressions
|
||||
|
||||
WHITESPACE = _{ " " | "\t" | "\n" | "\r" }
|
||||
|
||||
file = { SOI ~ or_expr ~ EOI }
|
||||
|
||||
or_expr = { and_expr ~ (or_kw ~ and_expr)* }
|
||||
and_expr = { term ~ (and_kw ~ term)* }
|
||||
|
||||
term = _{ regex_expr | comparison | "(" ~ or_expr ~ ")" }
|
||||
|
||||
// These must be atomic (`@`): a non-atomic rule would let pest's implicit
|
||||
// whitespace insertion slip in between the keyword and its own boundary
|
||||
// check below, which breaks the lookahead (it would see the first
|
||||
// non-whitespace character *after* skipping the separating space, instead
|
||||
// of the character immediately following the keyword).
|
||||
and_kw = @{ "and" ~ !(ASCII_ALPHANUMERIC | "_") }
|
||||
or_kw = @{ "or" ~ !(ASCII_ALPHANUMERIC | "_") }
|
||||
|
||||
regex_expr = { "regex" ~ "(" ~ string_literal ~ ")" }
|
||||
|
||||
string_literal = ${ "\"" ~ inner_str ~ "\"" }
|
||||
inner_str = @{ (escaped_char | !("\"" | "\\") ~ ANY)* }
|
||||
escaped_char = @{ "\\" ~ ANY }
|
||||
|
||||
comparison = { metric ~ ("[" ~ param ~ "]")? ~ op ~ value }
|
||||
|
||||
metric = @{ ident }
|
||||
param = @{ ident }
|
||||
ident = @{ (ASCII_ALPHANUMERIC | "_")+ }
|
||||
|
||||
op = { "<=" | ">=" | "==" | "!=" | "<" | ">" }
|
||||
|
||||
value = @{ (!(WHITESPACE | ")") ~ ANY)+ }
|
||||
Reference in New Issue
Block a user