Skip to content

Commit

Permalink
add doc comments
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed Dec 18, 2024
1 parent d3f5d08 commit 646d56a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/ottl/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,21 @@ func (c *ConditionSequence[K]) Eval(ctx context.Context, tCtx K) (bool, error) {
return c.logicOp == And && atLeastOneMatch, nil
}

// ValueExpression represents an expression that resolves to a value. The returned value can be of any type,
// and the expression can be either a literal value, a path value within the context, or the result of a converter and/or
// a mathematical expression.
// This Allows other components using this library to extract data from the context of the incoming signal using OTTL.
type ValueExpression[K any] struct {
getter Getter[K]
}

// Eval evaluates the given expression and returns the value the expression resolves to.
func (e *ValueExpression[K]) Eval(ctx context.Context, tCtx K) (any, error) {
return e.getter.Get(ctx, tCtx)
}

// ParseValueExpression parses an expression string into a ValueExpression. The ValueExpression's Eval
// method can then be used to extract the value from the context of the incoming signal.
func (p *Parser[K]) ParseValueExpression(raw string) (*ValueExpression[K], error) {
parsed, err := parseValueExpression(raw)
if err != nil {
Expand Down

0 comments on commit 646d56a

Please sign in to comment.