Documentation
¶
Overview ¶
Package expr implements a parser and evaluator for FlexMatch property expressions used inside rule measurements and reference values, e.g. "avg(flatten(teams[*].players.attributes[skill]))" or "teams[red].players.attributes[skill]".
Values are modelled as a recursive tree (scalars or lists of Values) so that nested results such as List<List<number>> — produced by multi-team scopes like teams[*] — can be aggregated per sublist, matching FlexMatch semantics ("operations on a nested list operate on each sublist individually").
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvalContext ¶
type EvalContext struct {
Players []core.Player
TeamPlayers map[string][]core.Player
TeamOrder []string
}
EvalContext supplies the player population an expression operates over.
Players is the full pool (used when no team scope is given). TeamPlayers maps a team name to its members for teams[<name>] accesses. TeamOrder lists team names in a deterministic order, used to expand teams[*].
type FuncCall ¶
FuncCall is a one-argument function such as avg / min / max / sum / count / median / stddev / flatten / set_intersection.
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is a parsed property expression AST node.
func Parse ¶
Parse parses a FlexMatch property expression. Recognised forms:
NUMBER (e.g. 42, 3.14)
"STRING" / 'STRING'
players.attributes[<attr>]
players.attributes[<attr>][<key>] (string_number_map index)
players[playerId] (player IDs)
players (the players, for count(...))
teams[<name>].players... (single team)
teams[<a>,<b>].players... (multiple teams, grouped)
teams[*].players... (all teams, grouped)
<func>(<expr>) where <func> in {flatten, avg, min,
max, sum, count, median, stddev,
set_intersection}
type PlayerAccess ¶
type PlayerAccess struct {
Teams []string // explicit team names (empty = all players)
AllTeams bool // teams[*]
Attr string // attribute name; "" means the whole player (ID)
MapKey string // optional, for string_number_map
HasIndex bool
}
PlayerAccess refers to player data within a team scope.
Team scoping:
Teams == nil, AllTeams == false -> all players in the match, ungrouped
AllTeams == true ("*") -> every team, grouped (List<List<...>>)
len(Teams) == 1 -> one team, ungrouped (List<...>)
len(Teams) > 1 -> those teams, grouped (List<List<...>>)
Attr selects what to read from each player:
Attr == "" -> the player itself (its ID); used by count(...players)
and teams[red].players[playerId].
Attr == name -> players.attributes[name]. For string_number_map attrs an
optional [MapKey] index selects a single numeric value.
type StringLit ¶
type StringLit struct{ V string }
StringLit is a string literal (quoted with single or double quotes).
type Value ¶
Value is the result of evaluating an expression node. A Value is either a scalar (KindNumber/KindString), an absent value (KindNone), or a list of Values (KindList) which may itself contain lists for nested scopes.
func Eval ¶
func Eval(n Node, ctx *EvalContext) (Value, error)
Eval evaluates a parsed expression node against ctx.
func NumberList ¶
NumberList wraps a []float64 as a list of Number values.
func StringList ¶
StringList wraps a []string as a list of String values.
func (Value) FlattenNumbers ¶
FlattenNumbers deeply flattens any nesting of numeric values into a single []float64. It returns false if the value contains a non-numeric scalar.
func (Value) FlattenStrings ¶
FlattenStrings deeply flattens any nesting of string values into a single []string. It returns false if the value contains a non-string scalar.