1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/runtime/expressions/return.go
2018-10-28 01:45:26 -04:00

39 lines
721 B
Go

package expressions
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
type (
ReturnExpression struct {
src core.SourceMap
predicate core.Expression
}
)
func NewReturnExpression(
src core.SourceMap,
predicate core.Expression,
) (*ReturnExpression, error) {
if predicate == nil {
return nil, core.Error(core.ErrMissedArgument, "expression")
}
return &ReturnExpression{
src,
predicate,
}, nil
}
func (e *ReturnExpression) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) {
val, err := e.predicate.Exec(ctx, scope)
if err != nil {
return values.None, core.SourceError(e.src, err)
}
return val, nil
}