mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-01 11:49:54 -05:00
Add noms/primitives.go and relatedness
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"github.com/clipperhouse/typewriter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
templates = append(templates, &typewriter.Template{
|
||||
Name: "noms",
|
||||
Text: `
|
||||
func (self {{.Name}}) Equals(other Value) bool {
|
||||
if other, ok := other.({{.Name}}); ok {
|
||||
return self == other
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
`,
|
||||
TypeConstraint: typewriter.Constraint{Comparable: true},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
. "github.com/attic-labs/noms/dbg"
|
||||
"github.com/clipperhouse/typewriter"
|
||||
)
|
||||
|
||||
var (
|
||||
templates = typewriter.TemplateSlice{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
Chk.NoError(typewriter.Register(&nomWriter{}))
|
||||
}
|
||||
|
||||
type nomWriter struct{}
|
||||
|
||||
func (nw *nomWriter) Name() string {
|
||||
return "noms"
|
||||
}
|
||||
|
||||
func (nw *nomWriter) Imports(t typewriter.Type) []typewriter.ImportSpec {
|
||||
return []typewriter.ImportSpec{}
|
||||
}
|
||||
|
||||
func (nw *nomWriter) 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
|
||||
}
|
||||
if err := tmpl.Execute(w, typ); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user