listGenMixin.go 4.35 KB
Newer Older
Eric Myhre's avatar
Eric Myhre committed
1 2 3 4 5
package mixins

import (
	"io"

6
	ld "gitlab.dms3.io/ld/go-ld-prime"
Eric Myhre's avatar
Eric Myhre committed
7 8 9 10 11 12 13 14
)

type ListTraits struct {
	PkgName    string
	TypeName   string // see doc in kindTraitsGenerator
	TypeSymbol string // see doc in kindTraitsGenerator
}

15 16
func (ListTraits) Kind() ld.Kind {
	return ld.Kind_List
Eric Myhre's avatar
Eric Myhre committed
17
}
18
func (g ListTraits) EmitNodeMethodKind(w io.Writer) {
Eric Myhre's avatar
Eric Myhre committed
19
	doTemplate(`
20 21
		func ({{ .TypeSymbol }}) Kind() ld.Kind {
			return ld.Kind_List
Eric Myhre's avatar
Eric Myhre committed
22 23 24
		}
	`, w, g)
}
25
func (g ListTraits) EmitNodeMethodLookupByString(w io.Writer) {
26
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodLookupByString(w)
Eric Myhre's avatar
Eric Myhre committed
27
}
28
func (g ListTraits) EmitNodeMethodLookupBySegment(w io.Writer) {
Eric Myhre's avatar
Eric Myhre committed
29
	doTemplate(`
30
		func (n {{ .TypeSymbol }}) LookupBySegment(seg ld.PathSegment) (ld.Node, error) {
Eric Myhre's avatar
Eric Myhre committed
31 32
			i, err := seg.Index()
			if err != nil {
33
				return nil, ld.ErrInvalidSegmentForList{TypeName: "{{ .PkgName }}.{{ .TypeName }}", TroubleSegment: seg, Reason: err}
Eric Myhre's avatar
Eric Myhre committed
34
			}
35
			return n.LookupByIndex(i)
Eric Myhre's avatar
Eric Myhre committed
36 37 38 39
		}
	`, w, g)
}
func (g ListTraits) EmitNodeMethodMapIterator(w io.Writer) {
40
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodMapIterator(w)
Eric Myhre's avatar
Eric Myhre committed
41
}
42
func (g ListTraits) EmitNodeMethodIsAbsent(w io.Writer) {
43
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodIsAbsent(w)
Eric Myhre's avatar
Eric Myhre committed
44 45
}
func (g ListTraits) EmitNodeMethodIsNull(w io.Writer) {
46
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodIsNull(w)
Eric Myhre's avatar
Eric Myhre committed
47 48
}
func (g ListTraits) EmitNodeMethodAsBool(w io.Writer) {
49
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodAsBool(w)
Eric Myhre's avatar
Eric Myhre committed
50 51
}
func (g ListTraits) EmitNodeMethodAsInt(w io.Writer) {
52
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodAsInt(w)
Eric Myhre's avatar
Eric Myhre committed
53 54
}
func (g ListTraits) EmitNodeMethodAsFloat(w io.Writer) {
55
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodAsFloat(w)
Eric Myhre's avatar
Eric Myhre committed
56 57
}
func (g ListTraits) EmitNodeMethodAsString(w io.Writer) {
58
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodAsString(w)
Eric Myhre's avatar
Eric Myhre committed
59 60
}
func (g ListTraits) EmitNodeMethodAsBytes(w io.Writer) {
61
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodAsBytes(w)
Eric Myhre's avatar
Eric Myhre committed
62 63
}
func (g ListTraits) EmitNodeMethodAsLink(w io.Writer) {
64
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_List}.emitNodeMethodAsLink(w)
Eric Myhre's avatar
Eric Myhre committed
65 66 67 68 69 70 71 72
}

type ListAssemblerTraits struct {
	PkgName       string
	TypeName      string // see doc in kindAssemblerTraitsGenerator
	AppliedPrefix string // see doc in kindAssemblerTraitsGenerator
}

73 74
func (ListAssemblerTraits) Kind() ld.Kind {
	return ld.Kind_List
75
}
Eric Myhre's avatar
Eric Myhre committed
76
func (g ListAssemblerTraits) EmitNodeAssemblerMethodBeginMap(w io.Writer) {
77
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodBeginMap(w)
Eric Myhre's avatar
Eric Myhre committed
78 79
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignNull(w io.Writer) {
80
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignNull(w)
Eric Myhre's avatar
Eric Myhre committed
81 82
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignBool(w io.Writer) {
83
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignBool(w)
Eric Myhre's avatar
Eric Myhre committed
84 85
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignInt(w io.Writer) {
86
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignInt(w)
Eric Myhre's avatar
Eric Myhre committed
87 88
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignFloat(w io.Writer) {
89
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignFloat(w)
Eric Myhre's avatar
Eric Myhre committed
90 91
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignString(w io.Writer) {
92
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignString(w)
Eric Myhre's avatar
Eric Myhre committed
93 94
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignBytes(w io.Writer) {
95
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignBytes(w)
Eric Myhre's avatar
Eric Myhre committed
96 97
}
func (g ListAssemblerTraits) EmitNodeAssemblerMethodAssignLink(w io.Writer) {
98
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodAssignLink(w)
Eric Myhre's avatar
Eric Myhre committed
99
}
100
func (g ListAssemblerTraits) EmitNodeAssemblerMethodPrototype(w io.Writer) {
101
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_List}.emitNodeAssemblerMethodPrototype(w)
Eric Myhre's avatar
Eric Myhre committed
102
}