Files
dolt/nomdl/codegen/union.tmpl
Erik Arvidsson e10e6224b0 Codegen for NomDL
This adds a new codegen that reads .noms files and generates Go
API for these types

Issue #304
2015-09-17 14:01:49 -04:00

29 lines
680 B
Cheetah

// {{.Name}}
type {{.Name}} struct {
l types.List
}
func {{.Name}}FromVal(val types.Value) {{.Name}} {
// TODO: Validate here
return {{.Name}}{val.(types.List)}
}
func (self {{.Name}}) NomsValue() types.Value {
return self.l
}
{{$name := .Name}}
{{range $index, $field := .Choices}}
func (self {{$name}}) {{.Name}}() ({{userType .T}}, bool) {
if int32(self.l.Get(types.Int32(0)).(types.Int32) != {{$index}} {
return {{userZero .T}}, false
}
return {{valueToUser "self.l.Get(types.Int32(1))" .T}}, true
}
func (self {{$name}}) Set{{.Name}}(val {{userType .T}}) {{$name}} {
return {{$name}}{types.NewList(types.Int32({{$index}}), {{userToValue "val" .T}})}
}
{{end}}