-
Notifications
You must be signed in to change notification settings - Fork 1
/
expression.go
128 lines (98 loc) · 2.15 KB
/
expression.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package expression
import (
"encoding/json"
tz "github.com/ecadlabs/gotez/v2"
"github.com/ecadlabs/gotez/v2/encoding"
)
type Expression interface {
Expression()
}
type Int struct {
Int tz.BigInt `json:"int"`
}
func (Int) Expression() {}
type String struct {
String string `tz:"dyn" json:"string"`
}
func (String) Expression() {}
type Seq struct {
Value []Expression `tz:"dyn"`
}
func (s Seq) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Value)
}
func (Seq) Expression() {}
type Prim00 Prim
func (Prim00) Expression() {}
func (p Prim00) MarshalJSON() ([]byte, error) {
return json.Marshal(&PrimXX{
Prim: Prim(p),
})
}
type Prim0X struct {
Prim Prim `json:"prim"`
Annots string `tz:"dyn" json:"annots"`
}
func (*Prim0X) Expression() {}
type Prim10 struct {
Prim Prim
Arg Expression
}
func (*Prim10) Expression() {}
func (p *Prim10) MarshalJSON() ([]byte, error) {
return json.Marshal(&PrimXX{
Prim: p.Prim,
Args: []Expression{p.Arg},
})
}
type Prim1X struct {
Prim Prim
Arg Expression
Annots string `tz:"dyn"`
}
func (*Prim1X) Expression() {}
func (p *Prim1X) MarshalJSON() ([]byte, error) {
return json.Marshal(&PrimXX{
Prim: p.Prim,
Args: []Expression{p.Arg},
Annots: p.Annots,
})
}
type Prim20 struct {
Prim Prim `json:"prim"`
Args [2]Expression `json:"args"`
}
func (*Prim20) Expression() {}
type Prim2X struct {
Prim Prim `json:"prim"`
Args [2]Expression `json:"args"`
Annots string `tz:"dyn" json:"annots,omitempty"`
}
func (*Prim2X) Expression() {}
type PrimXX struct {
Prim Prim `json:"prim"`
Args []Expression `tz:"dyn" json:"args,omitempty"`
Annots string `tz:"dyn" json:"annots,omitempty"`
}
func (*PrimXX) Expression() {}
type Bytes struct {
Bytes tz.Bytes `tz:"dyn" json:"bytes"`
}
func (Bytes) Expression() {}
func init() {
encoding.RegisterEnum(&encoding.Enum[Expression]{
Variants: encoding.Variants[Expression]{
0: Int{},
1: String{},
2: Seq{},
3: Prim00(0),
4: (*Prim0X)(nil),
5: (*Prim10)(nil),
6: (*Prim1X)(nil),
7: (*Prim20)(nil),
8: (*Prim2X)(nil),
9: (*PrimXX)(nil),
10: Bytes{},
},
})
}