From 0971f60c30296a2a5aa085474179dfe0a78fcfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 19 Jul 2023 19:34:39 +0200 Subject: [PATCH] v0.0.185 add Meta() to enums --- bfcodegen/enum-generate.go | 25 +++++++++++-------------- goextVersion.go | 4 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/bfcodegen/enum-generate.go b/bfcodegen/enum-generate.go index 19a2e64..ef51c4d 100644 --- a/bfcodegen/enum-generate.go +++ b/bfcodegen/enum-generate.go @@ -293,15 +293,7 @@ func fmtOutput(cs string, enums []EnumDef, pkgname string) string { str += "" + "\n" str += "func (e " + enumdef.EnumTypeName + ") ValuesMeta() []EnumMetaValue {" + "\n" - str += " return []EnumMetaValue{" + "\n" - for _, v := range enumdef.Values { - if hasDescr { - str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: langext.Ptr(\"%s\")},", v.VarName, v.VarName, strings.TrimSpace(*v.Description)) + "\n" - } else { - str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: nil},", v.VarName, v.VarName) + "\n" - } - } - str += " }" + "\n" + str += " return " + enumdef.EnumTypeName + "ValuesMeta()" str += "}" + "\n" str += "" + "\n" @@ -330,6 +322,15 @@ func fmtOutput(cs string, enums []EnumDef, pkgname string) string { str += "}" + "\n" str += "" + "\n" + str += "func (e " + enumdef.EnumTypeName + ") Meta() EnumMetaValue {" + "\n" + if hasDescr { + str += " return EnumMetaValue{VarName: e.VarName(), Value: e, Description: langext.Ptr(e.Description())}" + } else { + str += " return EnumMetaValue{VarName: e.VarName(), Value: e, Description: nil}" + } + str += "}" + "\n" + str += "" + "\n" + str += "func Parse" + enumdef.EnumTypeName + "(vv string) (" + enumdef.EnumTypeName + ", bool) {" + "\n" str += " for _, ev := range __" + enumdef.EnumTypeName + "Values {" + "\n" str += " if string(ev) == vv {" + "\n" @@ -348,11 +349,7 @@ func fmtOutput(cs string, enums []EnumDef, pkgname string) string { str += "func " + enumdef.EnumTypeName + "ValuesMeta() []EnumMetaValue {" + "\n" str += " return []EnumMetaValue{" + "\n" for _, v := range enumdef.Values { - if hasDescr { - str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: langext.Ptr(\"%s\")},", v.VarName, v.VarName, strings.TrimSpace(*v.Description)) + "\n" - } else { - str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: nil},", v.VarName, v.VarName) + "\n" - } + str += " " + v.VarName + ".Meta(),\n" } str += " }" + "\n" str += "}" + "\n" diff --git a/goextVersion.go b/goextVersion.go index aaf203c..05a824b 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.184" +const GoextVersion = "0.0.185" -const GoextVersionTimestamp = "2023-07-19T19:29:59+0200" +const GoextVersionTimestamp = "2023-07-19T19:34:39+0200"