mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-29 01:44:23 +02:00
5620be211c
* Renamed DOCUMENT to PAGE * Added PageLoadParams * Added PageLoadParams * Renamed LoadPageParams -> PageLoadParams * Added support for context.Done() (#201) * Bug/#189 operators precedence (#202) * Fixed math operators precedence * Fixed logical operators precedence * Fixed array operator * Added support for parentheses to enforce a different operator evaluation order * Feature/#200 drivers (#209) * Added new interfaces * Renamed dynamic to cdp driver * Renamed drivers * Added ELEMENT_EXISTS function (#210) * Renamed back PAGE to DOCUMENT (#211) * Added Getter and Setter interfaces
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package expressions
|
|
|
|
import (
|
|
"context"
|
|
"github.com/MontFerret/ferret/pkg/runtime/collections"
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
)
|
|
|
|
type BlockExpression struct {
|
|
values collections.Iterable
|
|
statements []core.Expression
|
|
}
|
|
|
|
func NewBlockExpression(values collections.Iterable) (*BlockExpression, error) {
|
|
if values == nil {
|
|
return nil, core.Error(core.ErrMissedArgument, "values")
|
|
}
|
|
|
|
return &BlockExpression{
|
|
values: values,
|
|
statements: make([]core.Expression, 0, 5),
|
|
}, nil
|
|
}
|
|
|
|
func (exp *BlockExpression) Add(stmt core.Expression) {
|
|
exp.statements = append(exp.statements, stmt)
|
|
}
|
|
|
|
func (exp *BlockExpression) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) {
|
|
select {
|
|
case <-ctx.Done():
|
|
return values.None, core.ErrTerminated
|
|
default:
|
|
for _, stmt := range exp.statements {
|
|
_, err := stmt.Exec(ctx, scope)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
}
|
|
|
|
return values.None, nil
|
|
}
|
|
}
|
|
|
|
func (exp *BlockExpression) Iterate(ctx context.Context, scope *core.Scope) (collections.Iterator, error) {
|
|
select {
|
|
case <-ctx.Done():
|
|
return nil, core.ErrTerminated
|
|
default:
|
|
iter, err := exp.values.Iterate(ctx, scope)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return collections.NewTapIterator(iter, exp)
|
|
}
|
|
}
|