Skip to content

Commit

Permalink
reorganize the package ast source files (#5370)
Browse files Browse the repository at this point in the history
This commit merges the ast/zed package into compiler/ast and simplifies
the ast layout.  It was good to keep them separate till now but
now that the dust has settled on the super-structured data model,
it all belongs together and hangs together nicely.

This change is needed to break an import sycle in a subsequent PR that
will simplify the ast.Node implementations, which is in turn needed,
by the SuperSQL additions.

We also moved the dag data structure from compiler/ast/dag to
compiler/dag as the dag describes the physical runtime query
execution structure and has nothing to do with syntax of the
query language.

Note that there is no new logic introduced here.  This is strictly
source code file movement and name changes.
  • Loading branch information
mccanne authored Oct 26, 2024
1 parent 56880f0 commit d25e41f
Show file tree
Hide file tree
Showing 39 changed files with 3,026 additions and 3,140 deletions.
42 changes: 19 additions & 23 deletions compiler/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// queries.
package ast

import (
astzed "github.com/brimdata/super/compiler/ast/zed"
)

// This module is derived from the GO AST design pattern in
// https://golang.org/pkg/go/ast/
//
Expand Down Expand Up @@ -44,10 +40,10 @@ func (i *ID) Pos() int { return i.NamePos }
func (i *ID) End() int { return i.NamePos + len(i.Name) }

type Term struct {
Kind string `json:"kind" unpack:""`
Text string `json:"text"`
TextPos int `json:"text_pos"`
Value astzed.Any `json:"value"`
Kind string `json:"kind" unpack:""`
Text string `json:"text"`
TextPos int `json:"text_pos"`
Value Any `json:"value"`
}

func (t *Term) Pos() int { return t.TextPos }
Expand Down Expand Up @@ -213,15 +209,15 @@ type RecordElem interface {
recordAST()
}

type Field struct {
type FieldExpr struct {
Kind string `json:"kind" unpack:""`
Name string `json:"name"`
NamePos int `json:"name_pos"`
Value Expr `json:"value"`
}

func (f *Field) Pos() int { return f.NamePos }
func (f *Field) End() int { return f.Value.End() }
func (f *FieldExpr) Pos() int { return f.NamePos }
func (f *FieldExpr) End() int { return f.Value.End() }

type Spread struct {
Kind string `json:"kind" unpack:""`
Expand All @@ -232,9 +228,9 @@ type Spread struct {
func (s *Spread) Pos() int { return s.StartPos }
func (s *Spread) End() int { return s.Expr.End() }

func (*Field) recordAST() {}
func (*ID) recordAST() {}
func (*Spread) recordAST() {}
func (*FieldExpr) recordAST() {}
func (*ID) recordAST() {}
func (*Spread) recordAST() {}

type ArrayExpr struct {
Kind string `json:"kind" unpack:""`
Expand Down Expand Up @@ -393,10 +389,10 @@ func (o *OpDecl) Pos() int { return o.KeywordPos }
func (o *OpDecl) End() int { return o.Rparen }

type TypeDecl struct {
Kind string `json:"kind" unpack:""`
KeywordPos int `json:"keyword_pos"`
Name *ID `json:"name"`
Type astzed.Type `json:"type"`
Kind string `json:"kind" unpack:""`
KeywordPos int `json:"keyword_pos"`
Name *ID `json:"name"`
Type Type `json:"type"`
}

func (t *TypeDecl) Pos() int { return t.KeywordPos }
Expand Down Expand Up @@ -475,11 +471,11 @@ type (
Args []Expr `json:"args"`
}
Explode struct {
Kind string `json:"kind" unpack:""`
KeywordPos int `json:"keyword_pos"`
Args []Expr `json:"args"`
Type astzed.Type `json:"type"`
As Expr `json:"as"`
Kind string `json:"kind" unpack:""`
KeywordPos int `json:"keyword_pos"`
Args []Expr `json:"args"`
Type Type `json:"type"`
As Expr `json:"as"`
}
Head struct {
Kind string `json:"kind" unpack:""`
Expand Down
7 changes: 1 addition & 6 deletions compiler/ast/zed/type.go → compiler/ast/type.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package zed
package ast

type Type interface {
Node
typeNode()
}

type Node interface {
Pos() int
End() int
}

type (
TypePrimitive struct {
Kind string `json:"kind" unpack:""`
Expand Down
47 changes: 23 additions & 24 deletions compiler/ast/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"encoding/json"
"fmt"

astzed "github.com/brimdata/super/compiler/ast/zed"
"github.com/brimdata/super/pkg/unpack"
)

var unpacker = unpack.New(
astzed.Array{},
Array{},
ArrayExpr{},
Assert{},
Assignment{},
Expand All @@ -18,17 +17,17 @@ var unpacker = unpack.New(
BinaryExpr{},
Call{},
Cast{},
astzed.CastValue{},
CastValue{},
Conditional{},
ConstDecl{},
Cut{},
Debug{},
astzed.DefValue{},
DefValue{},
Drop{},
Explode{},
astzed.Enum{},
astzed.Error{},
Field{},
Enum{},
Error{},
FieldExpr{},
File{},
From{},
FString{},
Expand All @@ -41,32 +40,32 @@ var unpacker = unpack.New(
Head{},
HTTP{},
ID{},
astzed.ImpliedValue{},
ImpliedValue{},
IndexExpr{},
Join{},
Load{},
Merge{},
Output{},
Over{},
astzed.Map{},
Map{},
MapExpr{},
Shape{},
OverExpr{},
Parallel{},
Pass{},
Pool{},
astzed.Primitive{},
Primitive{},
Put{},
QuotedString{},
astzed.Record{},
Record{},
Agg{},
Regexp{},
Glob{},
RecordExpr{},
Rename{},
Scope{},
Search{},
astzed.Set{},
Set{},
SetExpr{},
Spread{},
SliceExpr{},
Expand All @@ -77,19 +76,19 @@ var unpacker = unpack.New(
Tail{},
Term{},
Top{},
astzed.TypeArray{},
astzed.TypeDef{},
TypeArray{},
TypeDef{},
TypeDecl{},
astzed.TypeEnum{},
astzed.TypeError{},
astzed.TypeMap{},
astzed.TypeName{},
astzed.TypeNull{},
astzed.TypePrimitive{},
astzed.TypeRecord{},
astzed.TypeSet{},
astzed.TypeUnion{},
astzed.TypeValue{},
TypeEnum{},
TypeError{},
TypeMap{},
TypeName{},
TypeNull{},
TypePrimitive{},
TypeRecord{},
TypeSet{},
TypeUnion{},
TypeValue{},
UnaryExpr{},
Uniq{},
VectorValue{},
Expand Down
2 changes: 1 addition & 1 deletion compiler/ast/zed/value.go → compiler/ast/value.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zed
package ast

type Value interface {
valueNode()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion compiler/data/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"

"github.com/brimdata/super"
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/optimizer/demand"
"github.com/brimdata/super/lake"
"github.com/brimdata/super/lakeparse"
Expand Down
2 changes: 1 addition & 1 deletion compiler/describe/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/data"
"github.com/brimdata/super/compiler/optimizer"
"github.com/brimdata/super/compiler/parser"
Expand Down
2 changes: 1 addition & 1 deletion compiler/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"

"github.com/brimdata/super/compiler/ast"
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/data"
"github.com/brimdata/super/compiler/kernel"
"github.com/brimdata/super/compiler/optimizer"
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/bufferfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kernel

import (
"github.com/brimdata/super"
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/runtime/sam/expr"
"github.com/brimdata/super/zson"
"golang.org/x/text/unicode/norm"
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/brimdata/super"
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/pkg/field"
"github.com/brimdata/super/runtime/sam/expr"
"github.com/brimdata/super/runtime/sam/expr/function"
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/filter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kernel

import (
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/runtime/sam/expr"
"github.com/brimdata/super/zbuf"
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/groupby.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/order"
"github.com/brimdata/super/pkg/field"
"github.com/brimdata/super/runtime/sam/expr"
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"

"github.com/brimdata/super"
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/data"
"github.com/brimdata/super/compiler/optimizer"
"github.com/brimdata/super/compiler/optimizer/demand"
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/vexpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/pkg/field"
vamexpr "github.com/brimdata/super/runtime/vam/expr"
vamfunc "github.com/brimdata/super/runtime/vam/expr/function"
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/vop.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/optimizer"
"github.com/brimdata/super/pkg/field"
samexpr "github.com/brimdata/super/runtime/sam/expr"
Expand Down
2 changes: 1 addition & 1 deletion compiler/lake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
goruntime "runtime"

"github.com/brimdata/super/compiler/ast"
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/data"
"github.com/brimdata/super/compiler/kernel"
"github.com/brimdata/super/compiler/optimizer"
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/demand.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package optimizer

import (
"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/optimizer/demand"
)

Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"strings"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/order"
"github.com/brimdata/super/pkg/field"
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/compiler/data"
"github.com/brimdata/super/lake"
"github.com/brimdata/super/order"
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/parallelize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/order"
)

Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/vam.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package optimizer
import (
"context"

"github.com/brimdata/super/compiler/ast/dag"
"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/pkg/field"
)

Expand Down
Loading

0 comments on commit d25e41f

Please sign in to comment.