refactor: Refactor filter parsing to use comma separation and JSON values
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -1,41 +1,30 @@
|
||||
WHITESPACE = _{ " " | "\t" | "\n" | "\r" }
|
||||
|
||||
//! This Pest grammar defines the syntax for filter chains used in the Keep application.
|
||||
filters = { filter ~ ("," ~ filters)? }
|
||||
filter = { filter_name ~ ("(" ~ options ~ ")")? }
|
||||
filter_name = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
|
||||
// Main entry point for parsing multiple filters separated by pipes
|
||||
filters = { SOI ~ filter ~ (pipe ~ filter)* ~ EOI }
|
||||
options = { option ~ ("," ~ options)? }
|
||||
option = { (option_name ~ "=")? ~ option_value }
|
||||
option_name = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
|
||||
// A single filter with optional options
|
||||
filter = { filter_name ~ options? }
|
||||
option_value = {
|
||||
JSON_NUMBER |
|
||||
JSON_STRING |
|
||||
JSON_BOOLEAN
|
||||
}
|
||||
|
||||
// Filter name (alphanumeric with underscores)
|
||||
filter_name = @{ [a-zA-Z_][a-zA-Z0-9_]* }
|
||||
JSON_NUMBER = @{
|
||||
("-")? ~
|
||||
("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) ~
|
||||
("." ~ ASCII_DIGIT*)? ~
|
||||
(("e" | "E") ~ ("+" | "-")? ~ ASCII_DIGIT+)?
|
||||
}
|
||||
|
||||
// Options block with parentheses
|
||||
options = { "(" ~ WO ~ option* ~ WO ~ ")" }
|
||||
JSON_STRING = ${
|
||||
"\"" ~
|
||||
(("\\" ~ ANY) | (!("\"" | "\\") ~ ANY))* ~
|
||||
"\""
|
||||
}
|
||||
|
||||
// Single option: either named (name=value) or unnamed (just value)
|
||||
option = { WO ~ (option_name ~ WO ~ "=" ~ WO ~ option_value | option_value) }
|
||||
|
||||
// Option name (alphanumeric with underscores)
|
||||
option_name = @{ [a-zA-Z_][a-zA-Z0-9_]* }
|
||||
|
||||
// Option value: number, boolean, or quoted string
|
||||
option_value = { number | boolean | string }
|
||||
|
||||
// Simple number (integer or float)
|
||||
number = @{ ("-")? ~ [0-9]+ ~ ('.' ~ [0-9]+)? }
|
||||
|
||||
// Boolean true or false
|
||||
boolean = { "true" | "false" }
|
||||
|
||||
// Quoted string (double or single quotes)
|
||||
string = { (dquote ~ (!dquote ~ [^"])* ~ dquote) | (squote ~ (!squote ~ [^'])* ~ squote) }
|
||||
dquote = { '"' }
|
||||
squote = { '\'' }
|
||||
|
||||
// Pipe separator
|
||||
pipe = { "|" }
|
||||
|
||||
// Optional whitespace
|
||||
WO = { (WHITESPACE)* }
|
||||
JSON_BOOLEAN = ${ "true" | "false" }
|
||||
|
||||
Reference in New Issue
Block a user