1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-06 08:39:09 +02:00

Improved path lookup

This commit is contained in:
Tim Voronov
2019-09-07 01:47:58 -04:00
parent 9c0e81a2f4
commit 0a2fd478cd
3 changed files with 100 additions and 11 deletions

View File

@@ -35,22 +35,24 @@ func (e *MemberExpression) Exec(ctx context.Context, scope *core.Scope) (core.Va
)
}
strPath := make([]core.Value, len(e.path))
out := val
path := make([]core.Value, 1, 1)
for idx, exp := range e.path {
for _, exp := range e.path {
segment, err := exp.Exec(ctx, scope)
if err != nil {
return values.None, err
}
strPath[idx] = segment
}
path[0] = segment
c, err := values.GetIn(ctx, out, path)
out, err := values.GetIn(ctx, val, strPath)
if err != nil {
return values.None, core.SourceError(e.src, err)
}
if err != nil {
return values.None, core.SourceError(e.src, err)
out = c
}
return out, nil