-
Notifications
You must be signed in to change notification settings - Fork 4
/
unit.go
62 lines (52 loc) · 1.05 KB
/
unit.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
package ast
import (
"github.com/dipdup-net/go-lib/tools/base"
"github.com/dipdup-net/go-lib/tools/consts"
)
//
// UNIT
//
// Unit -
type Unit struct {
Default
}
// NewUnit -
func NewUnit(depth int) *Unit {
return &Unit{
Default: NewDefault(consts.UNIT, 0, depth),
}
}
// ToBaseNode -
func (u *Unit) ToBaseNode(optimized bool) (*base.Node, error) {
return &base.Node{
Prim: consts.Unit,
}, nil
}
// ToParameters -
func (u *Unit) ToParameters() ([]byte, error) {
return []byte(`{"prim":"Unit"}`), nil
}
// Compare -
func (u *Unit) Compare(second Comparable) (int, error) {
if _, ok := second.(*Unit); !ok {
return 0, consts.ErrTypeIsNotComparable
}
return 0, nil
}
// Distinguish -
func (u *Unit) Distinguish(x Distinguishable) (*MiguelNode, error) {
s, ok := x.(*Unit)
if !ok {
return nil, nil
}
return s.Default.Distinguish(&s.Default)
}
// GetJSONModel -
func (u *Unit) GetJSONModel(model JSONModel) {}
// FindByName -
func (u *Unit) FindByName(name string, isEntrypoint bool) Node {
if u.GetName() == name {
return u
}
return nil
}