Skip to content

Commit

Permalink
explode: move "as" check to semantic pass
Browse files Browse the repository at this point in the history
Move the "as" check on explode proc from kernel compilation phase to
semantic phase where this belongs.
  • Loading branch information
mattnibs committed Sep 18, 2023
1 parent aaf9752 commit e46bea3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion compiler/ast/dag/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type (
Kind string `json:"kind" unpack:""`
Args []Expr `json:"args"`
Type string `json:"type"`
As Expr `json:"as"`
As string `json:"as"`
}
Filter struct {
Kind string `json:"kind" unpack:""`
Expand Down
9 changes: 1 addition & 8 deletions compiler/kernel/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,7 @@ func (b *Builder) compileLeaf(o dag.Op, parent zbuf.Puller) (zbuf.Puller, error)
if err != nil {
return nil, err
}
as, err := compileLval(v.As)
if err != nil {
return nil, err
}
if len(as) != 1 {
return nil, errors.New("explode field must be a top-level field")
}
return explode.New(b.octx.Zctx, parent, args, typ, as.Leaf())
return explode.New(b.octx.Zctx, parent, args, typ, v.As)
case *dag.Over:
return b.compileOver(parent, v)
case *dag.Yield:
Expand Down
14 changes: 8 additions & 6 deletions compiler/semantic/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,19 @@ func (a *analyzer) semOp(o ast.Op, seq dag.Seq) (dag.Seq, error) {
if err != nil {
return nil, err
}
var as dag.Expr
var as string
if o.As == nil {
as = &dag.This{
Kind: "This",
Path: field.Path{"value"},
}
as = "value"
} else {
as, err = a.semExpr(o.As)
e, err := a.semExpr(o.As)
if err != nil {
return nil, err
}
if this, ok := e.(*dag.This); !ok {
return nil, errors.New("explode: as clause must be a field reference")
} else if len(this.Path) != 1 {
return nil, errors.New("explode: field must be a top-level field")
}
}
return append(seq, &dag.Explode{
Kind: "Explode",
Expand Down

0 comments on commit e46bea3

Please sign in to comment.