Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions book/src/super-sql/functions/errors/error.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ values {this,err:is_error(this),kind:kind(this)}
error("exception")
"exception"
# expected output
{this:error("exception"),err:true,kind:"error"}
{this:"exception",err:false,kind:"primitive"}
{that:error("exception"),err:true,kind:"error"}
{that:"exception",err:false,kind:"primitive"}
```

---
Expand Down
56 changes: 28 additions & 28 deletions book/src/super-sql/functions/generics/len.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ null
|["x","y","z"]|
"hello"
# expected output
{this:[1,2,3],kind:"array",type:<[int64]>,len:3}
{this:0x0102ffee,kind:"primitive",type:<bytes>,len:4}
{this:192.168.4.1,kind:"primitive",type:<ip>,len:4}
{this:2001:db8:85a3::8a2e:370:7334,kind:"primitive",type:<ip>,len:16}
{this:|{"APPL":145.03,"GOOG":87.07}|,kind:"map",type:<|{string:float64}|>,len:2}
{this:192.168.4.0/24,kind:"primitive",type:<net>,len:8}
{this:2001:db8:abcd::/64,kind:"primitive",type:<net>,len:32}
{this:null,kind:"primitive",type:<null>,len:0}
{this:{a:1,b:2},kind:"record",type:<{a:int64,b:int64}>,len:2}
{this:|["x","y","z"]|,kind:"set",type:<|[string]|>,len:3}
{this:"hello",kind:"primitive",type:<string>,len:5}
{that:[1,2,3],kind:"array",type:<[int64]>,len:3}
{that:0x0102ffee,kind:"primitive",type:<bytes>,len:4}
{that:192.168.4.1,kind:"primitive",type:<ip>,len:4}
{that:2001:db8:85a3::8a2e:370:7334,kind:"primitive",type:<ip>,len:16}
{that:|{"APPL":145.03,"GOOG":87.07}|,kind:"map",type:<|{string:float64}|>,len:2}
{that:192.168.4.0/24,kind:"primitive",type:<net>,len:8}
{that:2001:db8:abcd::/64,kind:"primitive",type:<net>,len:32}
{that:null,kind:"primitive",type:<null>,len:0}
{that:{a:1,b:2},kind:"record",type:<{a:int64,b:int64}>,len:2}
{that:|["x","y","z"]|,kind:"set",type:<|[string]|>,len:3}
{that:"hello",kind:"primitive",type:<string>,len:5}
```

_The length of various values of type `type`_
Expand All @@ -96,18 +96,18 @@ values {this,kind:kind(this),type:typeof(this),len:len(this)}
<|[{a:int64,b:string,c:bool}]|>
<(int64|float64|string)>
# expected output
{this:<[string]>,kind:"array",type:<type>,len:1}
{this:<[{a:int64,b:string,c:bool}]>,kind:"array",type:<type>,len:3}
{this:<enum(HEADS,TAILS)>,kind:"enum",type:<type>,len:2}
{this:<error(string)>,kind:"error",type:<type>,len:1}
{this:<error({ts:time,msg:string})>,kind:"error",type:<type>,len:2}
{this:<|{string:float64}|>,kind:"map",type:<type>,len:1}
{this:<|{string:{x:int64,y:float64}}|>,kind:"map",type:<type>,len:2}
{this:<int8>,kind:"primitive",type:<type>,len:1}
{this:<{a:int64,b:string,c:bool}>,kind:"record",type:<type>,len:3}
{this:<|[string]|>,kind:"set",type:<type>,len:1}
{this:<|[{a:int64,b:string,c:bool}]|>,kind:"set",type:<type>,len:3}
{this:<int64|float64|string>,kind:"union",type:<type>,len:3}
{that:<[string]>,kind:"array",type:<type>,len:1}
{that:<[{a:int64,b:string,c:bool}]>,kind:"array",type:<type>,len:3}
{that:<enum(HEADS,TAILS)>,kind:"enum",type:<type>,len:2}
{that:<error(string)>,kind:"error",type:<type>,len:1}
{that:<error({ts:time,msg:string})>,kind:"error",type:<type>,len:2}
{that:<|{string:float64}|>,kind:"map",type:<type>,len:1}
{that:<|{string:{x:int64,y:float64}}|>,kind:"map",type:<type>,len:2}
{that:<int8>,kind:"primitive",type:<type>,len:1}
{that:<{a:int64,b:string,c:bool}>,kind:"record",type:<type>,len:3}
{that:<|[string]|>,kind:"set",type:<type>,len:1}
{that:<|[{a:int64,b:string,c:bool}]|>,kind:"set",type:<type>,len:3}
{that:<int64|float64|string>,kind:"union",type:<type>,len:3}
```

_Unsupported values produce [errors](../../types/error.md)_
Expand All @@ -122,9 +122,9 @@ error("hello")
1
2024-07-30T20:05:15.118252Z
# expected output
{this:true,kind:"primitive",type:<bool>,len:error({message:"len: bad type",on:true})}
{this:10m30s,kind:"primitive",type:<duration>,len:error({message:"len: bad type",on:10m30s})}
{this:error("hello"),kind:"error",type:<error(string)>,len:error({message:"len()",on:error("hello")})}
{this:1,kind:"primitive",type:<int64>,len:error({message:"len: bad type",on:1})}
{this:2024-07-30T20:05:15.118252Z,kind:"primitive",type:<time>,len:error({message:"len: bad type",on:2024-07-30T20:05:15.118252Z})}
{that:true,kind:"primitive",type:<bool>,len:error({message:"len: bad type",on:true})}
{that:10m30s,kind:"primitive",type:<duration>,len:error({message:"len: bad type",on:10m30s})}
{that:error("hello"),kind:"error",type:<error(string)>,len:error({message:"len()",on:error("hello")})}
{that:1,kind:"primitive",type:<int64>,len:error({message:"len: bad type",on:1})}
{that:2024-07-30T20:05:15.118252Z,kind:"primitive",type:<time>,len:error({message:"len: bad type",on:2024-07-30T20:05:15.118252Z})}
```
82 changes: 44 additions & 38 deletions compiler/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,64 +239,70 @@ type TableAlias struct {
}

type RecordExpr struct {
Kind string `json:"kind" unpack:""`
Elems []Expr `json:"elems"`
Loc `json:"loc"`
}

type FieldExpr struct {
Kind string `json:"kind" unpack:""`
Name *Text `json:"name"`
Value Expr `json:"value"`
Kind string `json:"kind" unpack:""`
Elems []RecordElem `json:"elems"`
Loc `json:"loc"`
}

type Spread struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Loc `json:"loc"`
}

func (*FieldExpr) exprNode() {}
func (*Spread) exprNode() {}

type ArrayExpr struct {
Kind string `json:"kind" unpack:""`
Elems []VectorElem `json:"elems"`
Kind string `json:"kind" unpack:""`
Elems []ArrayElem `json:"elems"`
Loc `json:"loc"`
}

type SetExpr struct {
Kind string `json:"kind" unpack:""`
Elems []VectorElem `json:"elems"`
Kind string `json:"kind" unpack:""`
Elems []ArrayElem `json:"elems"`
Loc `json:"loc"`
}

type VectorElem interface {
vectorElemNode()
}

func (*Spread) vectorElemNode() {}
func (*VectorValue) vectorElemNode() {}

type VectorValue struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Loc `json:"loc"`
}

type MapExpr struct {
Kind string `json:"kind" unpack:""`
Entries []EntryExpr `json:"entries"`
Kind string `json:"kind" unpack:""`
Entries []MapEntry `json:"entries"`
Loc `json:"loc"`
}

type EntryExpr struct {
// Support structures embedded in Expr nodes

type MapEntry struct {
Key Expr `json:"key"`
Value Expr `json:"value"`
Loc `json:"loc"`
}

type ArrayElem interface {
arrayElemNode()
}

type RecordElem interface {
recordElemNode()
}

type (
FieldElem struct {
Kind string `json:"kind" unpack:""`
Name *Text `json:"name"`
Value Expr `json:"value"`
Loc `json:"loc"`
}
SpreadElem struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Loc `json:"loc"`
}
ExprElem struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Loc `json:"loc"`
}
)

func (*ExprElem) arrayElemNode() {}
func (*ExprElem) recordElemNode() {}
func (*FieldElem) recordElemNode() {}
func (*SpreadElem) arrayElemNode() {}
func (*SpreadElem) recordElemNode() {}

type Exists struct {
Kind string `json:"kind" unpack:""`
Body Seq `json:"body"`
Expand Down
6 changes: 3 additions & 3 deletions compiler/ast/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ var unpacker = unpack.New(
DoubleQuote{},
Drop{},
Explode{},
ExprElem{},
Enum{},
Error{},
ExprEntity{},
FieldExpr{},
FieldElem{},
From{},
FromElem{},
FString{},
Expand Down Expand Up @@ -74,7 +75,7 @@ var unpacker = unpack.New(
Search{},
Set{},
SetExpr{},
Spread{},
SpreadElem{},
SliceExpr{},
Sort{},
Text{},
Expand All @@ -97,7 +98,6 @@ var unpacker = unpack.New(
TypeValue{},
UnaryExpr{},
Uniq{},
VectorValue{},
Values{},
Where{},
Shapes{},
Expand Down
Loading