Commit 680f1386 authored by Eric Myhre's avatar Eric Myhre

The string of kinds should really be lowercase.

Yes, even though in practice in most of codegen we'll just turn around
and title-case it again for symbol export reasons.

The keywords everywhere throughout the schema language are lower-case,
and kinds are such a keyword.  They should therefore be consistently
handled and shown as lowercase.

This has bugged me for a while but it's time to fix it before any more
code starts passing by the area (and it's about to).
parent f6cbe842
......@@ -25,25 +25,25 @@ const (
func (k ReprKind) String() string {
switch k {
case ReprKind_Invalid:
return "Invalid"
return "INVALID"
case ReprKind_Map:
return "Map"
return "map"
case ReprKind_List:
return "List"
return "list"
case ReprKind_Null:
return "Null"
return "null"
case ReprKind_Bool:
return "Bool"
return "bool"
case ReprKind_Int:
return "Int"
return "int"
case ReprKind_Float:
return "Float"
return "float"
case ReprKind_String:
return "String"
return "string"
case ReprKind_Bytes:
return "Bytes"
return "bytes"
case ReprKind_Link:
return "Link"
return "link"
default:
panic("invalid enumeration value!")
}
......
......@@ -37,7 +37,7 @@ func (g kindTraitsGenerator) emitNodeMethodLookupString(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) LookupString(string) (ipld.Node, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.LookupString("")
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.LookupString("")
}
`, w, g)
}
......@@ -48,7 +48,7 @@ func (g kindTraitsGenerator) emitNodeMethodLookup(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) Lookup(ipld.Node) (ipld.Node, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.Lookup(nil)
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.Lookup(nil)
}
`, w, g)
}
......@@ -59,7 +59,7 @@ func (g kindTraitsGenerator) emitNodeMethodLookupIndex(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) LookupIndex(idx int) (ipld.Node, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.LookupIndex(0)
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.LookupIndex(0)
}
`, w, g)
}
......@@ -70,7 +70,7 @@ func (g kindTraitsGenerator) emitNodeMethodLookupSegment(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) LookupSegment(seg ipld.PathSegment) (ipld.Node, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.LookupSegment(seg)
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.LookupSegment(seg)
}
`, w, g)
}
......@@ -130,7 +130,7 @@ func (g kindTraitsGenerator) emitNodeMethodAsBool(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) AsBool() (bool, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsBool()
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsBool()
}
`, w, g)
}
......@@ -141,7 +141,7 @@ func (g kindTraitsGenerator) emitNodeMethodAsInt(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) AsInt() (int, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsInt()
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsInt()
}
`, w, g)
}
......@@ -152,7 +152,7 @@ func (g kindTraitsGenerator) emitNodeMethodAsFloat(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) AsFloat() (float64, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsFloat()
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsFloat()
}
`, w, g)
}
......@@ -163,7 +163,7 @@ func (g kindTraitsGenerator) emitNodeMethodAsString(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) AsString() (string, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsString()
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsString()
}
`, w, g)
}
......@@ -174,7 +174,7 @@ func (g kindTraitsGenerator) emitNodeMethodAsBytes(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) AsBytes() ([]byte, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsBytes()
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsBytes()
}
`, w, g)
}
......@@ -185,7 +185,7 @@ func (g kindTraitsGenerator) emitNodeMethodAsLink(w io.Writer) {
}
doTemplate(`
func ({{ .TypeSymbol }}) AsLink() (ipld.Link, error) {
return mixins.{{ .Kind }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsLink()
return mixins.{{ .Kind.String | title }}{"{{ .PkgName }}.{{ .TypeName }}"}.AsLink()
}
`, w, g)
}
......@@ -213,7 +213,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodBeginMap(w io.Write
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.BeginMap(0)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.BeginMap(0)
}
`, w, g)
}
......@@ -224,7 +224,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodBeginList(w io.Writ
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.BeginList(0)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.BeginList(0)
}
`, w, g)
}
......@@ -235,7 +235,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignNull(w io.Wri
}
doTemplate(`
func (na *{{ .AppliedPrefix }}Assembler) AssignNull() error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignNull()
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignNull()
}
`, w, g)
}
......@@ -246,7 +246,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignBool(w io.Wri
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) AssignBool(bool) error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignBool(false)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignBool(false)
}
`, w, g)
}
......@@ -257,7 +257,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignInt(w io.Writ
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) AssignInt(int) error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignInt(0)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignInt(0)
}
`, w, g)
}
......@@ -268,7 +268,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignFloat(w io.Wr
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) AssignFloat(float64) error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignFloat(0)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignFloat(0)
}
`, w, g)
}
......@@ -279,7 +279,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignString(w io.W
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) AssignString(string) error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignString("")
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignString("")
}
`, w, g)
}
......@@ -290,7 +290,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignBytes(w io.Wr
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) AssignBytes([]byte) error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignBytes(nil)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignBytes(nil)
}
`, w, g)
}
......@@ -301,7 +301,7 @@ func (g kindAssemblerTraitsGenerator) emitNodeAssemblerMethodAssignLink(w io.Wri
}
doTemplate(`
func ({{ .AppliedPrefix }}Assembler) AssignLink(ipld.Link) error {
return mixins.{{ .Kind }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignLink(nil)
return mixins.{{ .Kind.String | title }}Assembler{"{{ .PkgName }}.{{ .TypeName }}"}.AssignLink(nil)
}
`, w, g)
}
......
......@@ -2,6 +2,7 @@ package mixins
import (
"io"
"strings"
"text/template"
wish "github.com/warpfork/go-wish"
......@@ -9,6 +10,9 @@ import (
func doTemplate(tmplstr string, w io.Writer, data interface{}) {
tmpl := template.Must(template.New("").
Funcs(template.FuncMap{
"title": func(s string) string { return strings.Title(s) },
}).
Parse(wish.Dedent(tmplstr)))
if err := tmpl.Execute(w, data); err != nil {
panic(err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment