Documentation ¶
Overview ¶
Package syntax defines a scanner and parser for the CometBFT event filter query language. A query selects events by their types and attribute values.
Grammar ¶
The grammar of the query language is defined by the following EBNF:
query = conditions EOF conditions = condition {"AND" condition} condition = tag comparison comparison = equal / order / contains / "EXISTS" equal = "=" (date / number / time / value) order = cmp (date / number / time) contains = "CONTAINS" value cmp = "<" / "<=" / ">" / ">="
The lexical terms are defined here using RE2 regular expression notation:
// The name of an event attribute (type.value) tag = #'\w+(\.\w+)*' // A datestamp (YYYY-MM-DD) date = #'DATE \d{4}-\d{2}-\d{2}' // A number with optional fractional parts (0, 10, 3.25) number = #'\d+(\.\d+)?' // An RFC3339 timestamp (2021-11-23T22:04:19-09:00) time = #'TIME \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}([-+]\d{2}:\d{2}|Z)' // A quoted literal string value ('a b c') value = #'\'[^\']*\''
Index ¶
Constants ¶
const ( TInvalid = iota // invalid or unknown token TTag // field tag: x.y TString // string value: 'foo bar' TNumber // number: 0, 15.5, 100 TTime // timestamp: TIME yyyy-mm-ddThh:mm:ss([-+]hh:mm|Z) TDate // datestamp: DATE yyyy-mm-dd TAnd // operator: AND TContains // operator: CONTAINS TExists // operator: EXISTS TEq // operator: = TLt // operator: < TLeq // operator: <= TGt // operator: > TGeq // operator: >= )
const ( // TimeFormat is the format string used for timestamp values. TimeFormat = time.RFC3339 // DateFormat is the format string used for datestamp values. DateFormat = "2006-01-02" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Arg ¶
type Arg struct { Type Token // contains filtered or unexported fields }
An Arg is the argument of a comparison operator.
func (*Arg) Number ¶
Number returns the value of the argument text as a number, or nil if the text does not encode a valid number value.
type Condition ¶
A Condition is a single conditional expression, consisting of a tag, a comparison operator, and an optional argument. The type of the argument depends on the operator.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is a query expression parser. The grammar for query expressions is defined in the syntax package documentation.
type Query ¶
type Query []Condition
Query is the root of the parse tree for a query. A query is the conjunction of one or more conditions.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner reads lexical tokens of the query language from an input stream. Each call to Next advances the scanner to the next token, or reports an error.
func NewScanner ¶
NewScanner constructs a new scanner that reads from r.
func (*Scanner) Next ¶
Next advances s to the next token in the input, or reports an error. At the end of input, Next returns io.EOF.