Documentation
¶
Index ¶
Constants ¶
View Source
const ( // PfLValue the parameter can be a lvalue in the condition PfLValue = 1 << 0 // PfRValue the parameter can be a rvalue in the condition PfRValue = 1 << 1 // PfNop the parameter cannot have any operation PfNop = 1 << 2 // PfComparable the parameter can be compared: <, >, !=, =, >=, <= PfComparable = 1 << 3 // PfInLike the IN or LIKE operations are allowed for the param PfInLike = 1 << 4 )
View Source
const ( StringParamID = "__string__" NumberParamID = "__number__" ArrayParamID = "__array__" )
Variables ¶
View Source
var ( LogsCondDialect = map[string]ParamDialect[*solaris.Log, any]{ NumberParamID: { Flags: PfRValue | PfComparable, Value: func(p *Param, log *solaris.Log) (any, error) { return p.Const.Value(), nil }, }, StringParamID: { Flags: PfRValue | PfComparable, Value: func(p *Param, log *solaris.Log) (any, error) { return p.Const.Value(), nil }, }, ArrayParamID: { Flags: PfRValue, Value: func(p *Param, log *solaris.Log) (any, error) { var strArr []string for _, elem := range p.Array { strArr = append(strArr, elem.Value()) } return strArr, nil }, }, "id": { Flags: PfLValue | PfComparable | PfInLike, Value: func(p *Param, log *solaris.Log) (any, error) { return log.ID, nil }, }, "tag": { Flags: PfLValue | PfComparable | PfRValue | PfInLike, Value: func(p *Param, log *solaris.Log) (any, error) { if p.Function == nil { return "", fmt.Errorf("tag must be a function: %w", errors.ErrInvalid) } if len(p.Function.Params) != 1 { return "", fmt.Errorf("tag() function expects only one parameter - the name of the tag: %w", errors.ErrInvalid) } if p.Function.Params[0].ID() != StringParamID { return "", fmt.Errorf("tag() function expects the tag name (string) as the parameter: %w", errors.ErrInvalid) } if len(log.Tags) == 0 { return "", nil } return log.Tags[p.Function.Params[0].Name()], nil }, }, } )
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition struct { FirstParam Param ` @@` Op string ` {@("<"|">"|">="|"<="|"!="|"="|"IN"|"LIKE")` SecondParam *Param ` @@}` }
Condition is a unary or binary logical operation which has first mandatory param and optional operation and second param
type Expression ¶
type Expression struct {
Or []*OrCondition `@@ { "OR" @@ }`
}
Expression is an AST element which describes a series of OR conditions
func Parse ¶
func Parse(expr string) (*Expression, error)
Parse parses the expr and in case of success returns AST
type OrCondition ¶
type OrCondition struct {
And []*XCondition `@@ { "AND" @@ }`
}
OrCondition is an AST element which describes a series of AND conditions
type Param ¶
type Param struct { Const *Const ` @@` Function *Function ` | @@` Identifier string ` | @Ident` Array []*Const `|"[" (@@ {"," @@})?"]"` }
Param describes a parameter either a constant (string or number), function, identifier or an array of constants
type ParamDialect ¶
type XCondition ¶
type XCondition struct { Not bool ` [@"NOT"] ` Cond *Condition `( @@` Expr *Expression `| "(" @@ ")")` }
XCondition is an AST element which groups either a Condition object or an Expression object
Click to show internal directories.
Click to hide internal directories.