48 lines
1.6 KiB
Plaintext
48 lines
1.6 KiB
Plaintext
# This Pest grammar defines the syntax for filter chains used in the Keep application.
|
|
# Filters can be chained with commas and may have named or unnamed options with JSON-like values.
|
|
|
|
WHITESPACE = _{ " " | "\t" | "\n" | "\r" }
|
|
|
|
# Top-level rule for parsing multiple filters separated by commas.
|
|
filters = { filter ~ ("," ~ filters)? }
|
|
|
|
# A single filter consisting of a name optionally followed by parenthesized options.
|
|
filter = { filter_name ~ ("(" ~ options ~ ")")? }
|
|
|
|
# The name of a filter, starting with an ASCII letter followed by alphanumeric characters or underscores.
|
|
filter_name = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
|
|
|
|
# A list of comma-separated options within parentheses.
|
|
options = { option ~ ("," ~ options)? }
|
|
|
|
# A single option, optionally with a name followed by an equals sign and a value.
|
|
option = { (option_name ~ "=")? ~ option_value }
|
|
|
|
# The name of an option, starting with an ASCII letter followed by alphanumeric characters or underscores.
|
|
option_name = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
|
|
|
|
# The value of an option, which can be a JSON number, string, or boolean.
|
|
option_value = {
|
|
JSON_NUMBER |
|
|
JSON_STRING |
|
|
JSON_BOOLEAN
|
|
}
|
|
|
|
# JSON number format supporting integers, decimals, and scientific notation.
|
|
JSON_NUMBER = @{
|
|
("-")? ~
|
|
("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) ~
|
|
("." ~ ASCII_DIGIT*)? ~
|
|
(("e" | "E") ~ ("+" | "-")? ~ ASCII_DIGIT+)?
|
|
}
|
|
|
|
# JSON string format with escaped characters.
|
|
JSON_STRING = ${
|
|
"\"" ~
|
|
(("\\" ~ ANY) | (!("\"" | "\\") ~ ANY))* ~
|
|
"\""
|
|
}
|
|
|
|
# JSON boolean values: true or false.
|
|
JSON_BOOLEAN = ${ "true" | "false" }
|