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

import (
	"io"

tavit ohanian's avatar
tavit ohanian committed
6
	dms3ld "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
}

tavit ohanian's avatar
tavit ohanian committed
15 16
func (ListTraits) Kind() dms3ld.Kind {
	return dms3ld.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(`
tavit ohanian's avatar
tavit ohanian committed
20 21
		func ({{ .TypeSymbol }}) Kind() dms3ld.Kind {
			return dms3ld.Kind_List
Eric Myhre's avatar
Eric Myhre committed
22 23 24
		}
	`, w, g)
}
25
func (g ListTraits) EmitNodeMethodLookupByString(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
26
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.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(`
tavit ohanian's avatar
tavit ohanian committed
30
		func (n {{ .TypeSymbol }}) LookupBySegment(seg dms3ld.PathSegment) (dms3ld.Node, error) {
Eric Myhre's avatar
Eric Myhre committed
31 32
			i, err := seg.Index()
			if err != nil {
tavit ohanian's avatar
tavit ohanian committed
33
				return nil, dms3ld.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) {
tavit ohanian's avatar
tavit ohanian committed
40
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodMapIterator(w)
Eric Myhre's avatar
Eric Myhre committed
41
}
42
func (g ListTraits) EmitNodeMethodIsAbsent(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
43
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodIsAbsent(w)
Eric Myhre's avatar
Eric Myhre committed
44 45
}
func (g ListTraits) EmitNodeMethodIsNull(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
46
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodIsNull(w)
Eric Myhre's avatar
Eric Myhre committed
47 48
}
func (g ListTraits) EmitNodeMethodAsBool(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
49
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodAsBool(w)
Eric Myhre's avatar
Eric Myhre committed
50 51
}
func (g ListTraits) EmitNodeMethodAsInt(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
52
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodAsInt(w)
Eric Myhre's avatar
Eric Myhre committed
53 54
}
func (g ListTraits) EmitNodeMethodAsFloat(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
55
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodAsFloat(w)
Eric Myhre's avatar
Eric Myhre committed
56 57
}
func (g ListTraits) EmitNodeMethodAsString(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
58
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodAsString(w)
Eric Myhre's avatar
Eric Myhre committed
59 60
}
func (g ListTraits) EmitNodeMethodAsBytes(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
61
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.Kind_List}.emitNodeMethodAsBytes(w)
Eric Myhre's avatar
Eric Myhre committed
62 63
}
func (g ListTraits) EmitNodeMethodAsLink(w io.Writer) {
tavit ohanian's avatar
tavit ohanian committed
64
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, dms3ld.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
}

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