Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MontFerret/ferret
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Sep 9, 2021
2 parents de12889 + 8f2957e commit a000302
Show file tree
Hide file tree
Showing 27 changed files with 823 additions and 239 deletions.
16 changes: 16 additions & 0 deletions pkg/compiler/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/expressions/clauses"
"github.com/MontFerret/ferret/pkg/runtime/expressions/literals"
"github.com/MontFerret/ferret/pkg/runtime/expressions/operators"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/pkg/errors"
"regexp"
Expand Down Expand Up @@ -877,6 +878,8 @@ func (v *visitor) doVisitMemberExpression(ctx *fql.MemberExpressionContext, scop

children := ctx.AllMemberExpressionPath()
path := make([]*expressions.MemberPathSegment, 0, len(children))
preCompiledPath := make([]core.Value, 0, len(children))
skipOptimization := false

for _, memberPath := range children {
var exp core.Expression
Expand All @@ -903,13 +906,26 @@ func (v *visitor) doVisitMemberExpression(ctx *fql.MemberExpressionContext, scop
return nil, err
}

if !skipOptimization {
switch t := exp.(type) {
case literals.StringLiteral:
preCompiledPath = append(preCompiledPath, values.NewString(string(t)))
case literals.IntLiteral:
preCompiledPath = append(preCompiledPath, values.NewInt(int(t)))
default:
skipOptimization = true
preCompiledPath = nil
}
}

path = append(path, segment)
}

return expressions.NewMemberExpression(
v.getSourceMap(ctx),
source,
path,
preCompiledPath,
)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/drivers/cdp/dom/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ func (doc *HTMLDocument) Iterate(ctx context.Context) (core.Iterator, error) {
return doc.element.Iterate(ctx)
}

func (doc *HTMLDocument) GetIn(ctx context.Context, path []core.Value) (core.Value, error) {
return common.GetInDocument(ctx, doc, path)
func (doc *HTMLDocument) GetIn(ctx context.Context, path []core.Value) (core.Value, core.PathError) {
return common.GetInDocument(ctx, path, doc)
}

func (doc *HTMLDocument) SetIn(ctx context.Context, path []core.Value, value core.Value) error {
return common.SetInDocument(ctx, doc, path, value)
func (doc *HTMLDocument) SetIn(ctx context.Context, path []core.Value, value core.Value) core.PathError {
return common.SetInDocument(ctx, path, doc, value)
}

func (doc *HTMLDocument) Close() error {
Expand Down
8 changes: 4 additions & 4 deletions pkg/drivers/cdp/dom/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ func (el *HTMLElement) Iterate(_ context.Context) (core.Iterator, error) {
return common.NewIterator(el)
}

func (el *HTMLElement) GetIn(ctx context.Context, path []core.Value) (core.Value, error) {
return common.GetInElement(ctx, el, path)
func (el *HTMLElement) GetIn(ctx context.Context, path []core.Value) (core.Value, core.PathError) {
return common.GetInElement(ctx, path, el)
}

func (el *HTMLElement) SetIn(ctx context.Context, path []core.Value, value core.Value) error {
return common.SetInElement(ctx, el, path, value)
func (el *HTMLElement) SetIn(ctx context.Context, path []core.Value, value core.Value) core.PathError {
return common.SetInElement(ctx, path, el, value)
}

func (el *HTMLElement) GetValue(ctx context.Context) (core.Value, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/drivers/cdp/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ func (p *HTMLPage) Copy() core.Value {
return values.None
}

func (p *HTMLPage) GetIn(ctx context.Context, path []core.Value) (core.Value, error) {
return common.GetInPage(ctx, p, path)
func (p *HTMLPage) GetIn(ctx context.Context, path []core.Value) (core.Value, core.PathError) {
return common.GetInPage(ctx, path, p)
}

func (p *HTMLPage) SetIn(ctx context.Context, path []core.Value, value core.Value) error {
return common.SetInPage(ctx, p, path, value)
func (p *HTMLPage) SetIn(ctx context.Context, path []core.Value, value core.Value) core.PathError {
return common.SetInPage(ctx, path, p, value)
}

func (p *HTMLPage) Iterate(ctx context.Context) (core.Iterator, error) {
Expand Down
Loading

0 comments on commit a000302

Please sign in to comment.