Documentation
¶
Index ¶
Constants ¶
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 // PfGreaterLess the parameter can be compared with < or > only PfGreaterLess = 1 << 5 // The ParamDialect ValueF() is a constant value and should not be re-calculated every time when called // it also means that ValueF will return a value for the *new(T) PfConstValue = 1 << 6 )
const ( StringParamID = "__string__" NumberParamID = "__number__" ArrayParamID = "__array__" )
Variables ¶
var ( LogsCondDialect = Dialect[*solaris.Log]{ StringParamID: { Flags: PfRValue | PfComparable | PfConstValue, ValueF: func(p *Param, _ *solaris.Log) (any, error) { return p.Const.Value(), nil }, Type: VTString, }, ArrayParamID: { Flags: PfRValue | PfConstValue, ValueF: func(p *Param, _ *solaris.Log) (any, error) { var strArr []string for _, elem := range p.Array { strArr = append(strArr, elem.Value()) } return strArr, nil }, Type: VTStrings, }, "logID": { Flags: PfLValue | PfComparable | PfInLike, ValueF: func(p *Param, log *solaris.Log) (any, error) { return log.ID, nil }, Type: VTString, }, "tag": { Flags: PfLValue | PfComparable | PfRValue | PfInLike, CheckF: func(p *Param) 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) } return nil }, ValueF: func(p *Param, log *solaris.Log) (any, error) { if len(log.Tags) == 0 { return "", nil } return log.Tags[p.Function.Params[0].Name(true)], nil }, Type: VTString, }, } RecordsCondDialect = Dialect[*solaris.Record]{ StringParamID: { Flags: PfRValue | PfComparable | PfConstValue, ValueF: func(p *Param, _ *solaris.Record) (any, error) { return p.Const.Value(), nil }, Type: VTString, }, "ctime": { Flags: PfLValue | PfComparable, ValueF: func(p *Param, r *solaris.Record) (any, error) { if r.CreatedAt != nil { return r.CreatedAt.AsTime(), nil } return time.Time{}, nil }, Type: VTTime, }, } )
var ( OpsAll = []string{"<", ">", "<=", ">=", "=", "!="} OpsGtLt = []string{"<", ">"} )
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 Dialect ¶ added in v0.9.0
type Dialect[T any] map[string]ParamDialect[T]
type ExprF ¶ added in v0.9.0
ExprF represents the Expression function to evaluate the expression for the type T
func BuildExprF ¶ added in v0.9.0
func BuildExprF[T any](expr *Expression, dialect Dialect[T]) (ExprF[T], error)
BuildExprF allows to build the ExprF[T] function by the expression and the dialect provided. The result function may be used for testing a value of T either it matches the expression or not.
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 ParamDialect[T any] struct { // Flags contains flags associated with the parameter, please see Pf constants above Flags int // CheckF is used for calculating the parameter value while building an evaluator function // If not specified, then the parameter is always correct CheckF func(p *Param) error // ValueF is the function which allows to get the parameter value. The function MUST NOT be called // if the CheckF returns an error ValueF valueF[T] // Define the type for the ValueF result Type ValueType }
ParamDialect is used for describing grama objects in the dialect
type ParamIntervalBuilder ¶ added in v0.15.0
type ParamIntervalBuilder[T, K any] struct { // contains filtered or unexported fields }
ParamIntervalBuilder allows to build value intervals from the AST expression for a given parameter and comparison operations specified.
func NewParamIntervalBuilder ¶ added in v0.15.0
func NewParamIntervalBuilder[T, K any](basis intervals.Basis[T], dialect Dialect[K], param string, ops []string) ParamIntervalBuilder[T, K]
NewParamIntervalBuilder returns new ParamIntervalBuilder.
func (*ParamIntervalBuilder[T, K]) Build ¶ added in v0.15.0
func (ib *ParamIntervalBuilder[T, K]) Build(expr *Expression) ([]intervals.Interval[T], error)
Build returns a list of intervals built from the AST expression.
type ValueType ¶ added in v0.9.0
type ValueType int
ValueType defines the type returned by a parameter value function (see below)
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