1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-12-05 22:26:09 +02:00

Bug/#142 clauses and statements (#148)

This commit is contained in:
Tim Voronov
2018-10-28 01:45:26 -04:00
committed by GitHub
parent e6fd33ac1d
commit 3472630e6f
72 changed files with 2828 additions and 2185 deletions

View File

@@ -8,9 +8,10 @@ import (
)
type DataSource struct {
src core.SourceMap
variables collections.Variables
exp core.Expression
src core.SourceMap
valVariable string
keyVariable string
exp core.Expression
}
func NewDataSource(
@@ -25,15 +26,12 @@ func NewDataSource(
return &DataSource{
src,
collections.Variables{valVariable, keyVariable},
valVariable,
keyVariable,
exp,
}, nil
}
func (ds *DataSource) Variables() collections.Variables {
return ds.variables
}
func (ds *DataSource) Iterate(ctx context.Context, scope *core.Scope) (collections.Iterator, error) {
data, err := ds.exp.Exec(ctx, scope)
@@ -41,23 +39,20 @@ func (ds *DataSource) Iterate(ctx context.Context, scope *core.Scope) (collectio
return nil, core.SourceError(ds.src, err)
}
valVar := ds.variables[0]
keyVar := ds.variables[1]
switch data.Type() {
case core.ArrayType:
return collections.NewIndexedIterator(valVar, keyVar, data.(collections.IndexedCollection)), nil
return collections.NewIndexedIterator(ds.valVariable, ds.keyVariable, data.(collections.IndexedCollection))
case core.ObjectType:
return collections.NewKeyedIterator(valVar, keyVar, data.(collections.KeyedCollection)), nil
return collections.NewKeyedIterator(ds.valVariable, ds.keyVariable, data.(collections.KeyedCollection))
case core.HTMLElementType, core.HTMLDocumentType:
return collections.NewHTMLNodeIterator(valVar, keyVar, data.(values.HTMLNode)), nil
return collections.NewHTMLNodeIterator(ds.valVariable, ds.keyVariable, data.(values.HTMLNode))
default:
// fallback to user defined types
switch data.(type) {
case collections.KeyedCollection:
return collections.NewIndexedIterator(valVar, keyVar, data.(collections.IndexedCollection)), nil
return collections.NewIndexedIterator(ds.valVariable, ds.keyVariable, data.(collections.IndexedCollection))
case collections.IndexedCollection:
return collections.NewKeyedIterator(valVar, keyVar, data.(collections.KeyedCollection)), nil
return collections.NewKeyedIterator(ds.valVariable, ds.keyVariable, data.(collections.KeyedCollection))
default:
return nil, core.TypeError(
data.Type(),