-
Notifications
You must be signed in to change notification settings - Fork 6
/
docstring.go
112 lines (98 loc) · 2.23 KB
/
docstring.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
package ast
import (
"fmt"
"strings"
"github.com/dipdup-net/go-lib/tools/consts"
)
// docs constants
const (
DocsFull = ""
)
var simpleTypes = []string{
consts.INT,
consts.STRING,
consts.BYTES,
consts.BOOL,
consts.NAT,
consts.MUTEZ,
consts.TIMESTAMP,
consts.ADDRESS,
consts.KEYHASH,
consts.KEY,
consts.SIGNATURE,
consts.CHAINID,
consts.UNIT,
consts.OPERATION,
consts.BAKERHASH,
consts.BLS12381FR,
consts.BLS12381G1,
consts.BLS12381G2,
consts.NEVER,
consts.SAPLINGSTATE,
consts.SAPLINGTRANSACTION,
}
// EntrypointType -
type EntrypointType struct {
Name string `json:"name"`
Type []Typedef `json:"typedef"`
}
// Typedef -
type Typedef struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
TypeDef []Typedef `json:"typedef,omitempty"`
Args []TypedefArg `json:"args,omitempty"`
}
// TypedefArg -
type TypedefArg struct {
Key string `json:"key,omitempty"`
Value string `json:"value"`
}
func buildArrayDocs(nodes []Node) ([]Typedef, error) {
typedef := make([]Typedef, 0)
for i := range nodes {
docs, _, err := nodes[i].Docs("")
if err != nil {
return nil, err
}
typedef = append(typedef, docs...)
}
return typedef, nil
}
func isSimpleDocType(prim string) bool {
for _, t := range simpleTypes {
if prim == t {
return true
}
}
return false
}
func makeVarDocString(name string) string {
return fmt.Sprintf("$%s", strings.TrimPrefix(name, "@"))
}
func getNameDocString(node Type, inferredName string) string {
name := node.GetName()
if strings.HasPrefix(name, "@") && inferredName != "" {
name = inferredName
}
return name
}
func isFlatDocType(typ Typedef) bool {
if isSyntheticDocName(typ) {
return false
}
return strings.HasPrefix(typ.Type, consts.LIST) ||
strings.HasPrefix(typ.Type, consts.SET) ||
strings.HasPrefix(typ.Type, consts.BIGMAP) ||
strings.HasPrefix(typ.Type, consts.CONTRACT) ||
strings.HasPrefix(typ.Type, consts.MAP) ||
strings.HasPrefix(typ.Type, consts.OPTION)
}
func isSyntheticDocName(typ Typedef) bool {
return strings.HasSuffix(typ.Name, "_param") ||
strings.HasSuffix(typ.Name, "_item") ||
strings.HasSuffix(typ.Name, "_key") ||
strings.HasSuffix(typ.Name, "_value") ||
typ.Name == "input" ||
typ.Name == "return"
}