Files
dolt/codegen/valuewriter.go
T
2015-06-12 15:22:27 -07:00

60 lines
998 B
Go

package gen
import (
"io"
. "github.com/attic-labs/noms/dbg"
"github.com/clipperhouse/typewriter"
)
var (
templates = typewriter.TemplateSlice{}
)
func init() {
Chk.NoError(typewriter.Register(&valueWriter{}))
}
type valueWriter struct{}
func (nw *valueWriter) Name() string {
return "value"
}
func (nw *valueWriter) Imports(t typewriter.Type) []typewriter.ImportSpec {
return []typewriter.ImportSpec{
typewriter.ImportSpec{
Name: ".",
Path: "github.com/attic-labs/noms/dbg",
},
typewriter.ImportSpec{
Path: "github.com/attic-labs/noms/ref",
},
}
}
func (nw *valueWriter) Write(w io.Writer, typ typewriter.Type) error {
tag, found := typ.FindTag(nw)
if !found {
return nil
}
tmpl, err := templates.ByTag(typ, tag)
if err != nil {
return err
}
w.Write([]byte(`
// DO NOT EDIT
//
// This file was generated by a tool.
// See http://clipperhouse.github.io/gen for details.
`))
if err := tmpl.Execute(w, typ); err != nil {
return err
}
return nil
}