2018-09-18 22:42:38 +02:00
|
|
|
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 {
|
2018-10-28 07:45:26 +02:00
|
|
|
return nil, core.Error(core.ErrMissedArgument, "expression")
|
2018-09-18 22:42:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|