mapGenMixin.go 4.15 KB
Newer Older
1 2 3 4 5
package mixins

import (
	"io"

6
	ld "gitlab.dms3.io/ld/go-ld-prime"
7 8 9 10 11 12 13 14
)

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

15 16
func (MapTraits) Kind() ld.Kind {
	return ld.Kind_Map
Eric Myhre's avatar
Eric Myhre committed
17
}
18
func (g MapTraits) EmitNodeMethodKind(w io.Writer) {
19
	doTemplate(`
20 21
		func ({{ .TypeSymbol }}) Kind() ld.Kind {
			return ld.Kind_Map
22 23 24
		}
	`, w, g)
}
25
func (g MapTraits) EmitNodeMethodLookupByIndex(w io.Writer) {
26
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodLookupByIndex(w)
27
}
28
func (g MapTraits) EmitNodeMethodLookupBySegment(w io.Writer) {
29
	doTemplate(`
30
		func (n {{ .TypeSymbol }}) LookupBySegment(seg ld.PathSegment) (ld.Node, error) {
31
			return n.LookupByString(seg.String())
32 33 34 35
		}
	`, w, g)
}
func (g MapTraits) EmitNodeMethodListIterator(w io.Writer) {
36
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodListIterator(w)
37
}
38
func (g MapTraits) EmitNodeMethodIsAbsent(w io.Writer) {
39
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodIsAbsent(w)
40 41
}
func (g MapTraits) EmitNodeMethodIsNull(w io.Writer) {
42
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodIsNull(w)
43 44
}
func (g MapTraits) EmitNodeMethodAsBool(w io.Writer) {
45
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodAsBool(w)
46 47
}
func (g MapTraits) EmitNodeMethodAsInt(w io.Writer) {
48
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodAsInt(w)
49 50
}
func (g MapTraits) EmitNodeMethodAsFloat(w io.Writer) {
51
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodAsFloat(w)
52 53
}
func (g MapTraits) EmitNodeMethodAsString(w io.Writer) {
54
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodAsString(w)
55 56
}
func (g MapTraits) EmitNodeMethodAsBytes(w io.Writer) {
57
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodAsBytes(w)
58 59
}
func (g MapTraits) EmitNodeMethodAsLink(w io.Writer) {
60
	kindTraitsGenerator{g.PkgName, g.TypeName, g.TypeSymbol, ld.Kind_Map}.emitNodeMethodAsLink(w)
61
}
62 63 64 65 66 67 68

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

69 70
func (MapAssemblerTraits) Kind() ld.Kind {
	return ld.Kind_Map
71
}
72
func (g MapAssemblerTraits) EmitNodeAssemblerMethodBeginList(w io.Writer) {
73
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodBeginList(w)
74 75
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignNull(w io.Writer) {
76
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignNull(w)
77 78
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignBool(w io.Writer) {
79
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignBool(w)
80 81
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignInt(w io.Writer) {
82
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignInt(w)
83 84
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignFloat(w io.Writer) {
85
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignFloat(w)
86 87
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignString(w io.Writer) {
88
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignString(w)
89 90
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignBytes(w io.Writer) {
91
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignBytes(w)
92 93
}
func (g MapAssemblerTraits) EmitNodeAssemblerMethodAssignLink(w io.Writer) {
94
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodAssignLink(w)
95
}
96
func (g MapAssemblerTraits) EmitNodeAssemblerMethodPrototype(w io.Writer) {
97
	kindAssemblerTraitsGenerator{g.PkgName, g.TypeName, g.AppliedPrefix, ld.Kind_Map}.emitNodeAssemblerMethodPrototype(w)
98
}