forked from mangalorg/gopher-luadoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
47 lines (37 loc) · 859 Bytes
/
type.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
package luadoc
import (
"fmt"
"strings"
"github.com/samber/lo"
)
const (
String = "string"
Number = "number"
Boolean = "boolean"
Table = "table"
Any = "any"
)
func List(of string) string {
return of + "[]"
}
func Map(keys string, values string) string {
return Table + "<" + keys + ", " + values + ">"
}
func TableLiteral(keysAndValues ...string) string {
if len(keysAndValues)%2 != 0 {
panic("keysAndValues must be even")
}
var pairs []string
for i := 0; i < len(keysAndValues); i += 2 {
key := keysAndValues[i]
value := keysAndValues[i+1]
pairs = append(pairs, fmt.Sprintf("%s: %s", key, value))
}
return "{" + strings.Join(pairs, ", ") + "}"
}
func Enum(members ...string) string {
quoted := lo.Map(members, func(s string, _ int) string {
return fmt.Sprintf(`'%s'`, s)
})
return strings.Join(quoted, " | ")
}