diff --git a/lang/funcs/core/.gitignore b/lang/funcs/core/.gitignore index 508959f8..ef73626c 100644 --- a/lang/funcs/core/.gitignore +++ b/lang/funcs/core/.gitignore @@ -1,2 +1 @@ generated_funcs.go -generated_funcs_test.go diff --git a/lang/funcs/core/funcgen.yaml b/lang/funcs/core/funcgen.yaml index 4c616a7e..025e6381 100644 --- a/lang/funcs/core/funcgen.yaml +++ b/lang/funcs/core/funcgen.yaml @@ -5,15 +5,12 @@ packages: - name: math - name: math/rand alias: rand - mgmtAlias: rand - name: os - name: os/exec alias: exec - mgmtAlias: exec - name: path - name: path/filepath alias: filepath - mgmtAlias: filepath - name: runtime - name: strconv - name: strings diff --git a/lang/funcs/funcgen/config.go b/lang/funcs/funcgen/config.go index 291d3d76..f25164bd 100644 --- a/lang/funcs/funcgen/config.go +++ b/lang/funcs/funcgen/config.go @@ -59,7 +59,7 @@ func (obj *arg) ToMcl() (string, error) { return fmt.Sprintf("%s%s", prefix, types.TypeBool.String()), nil case "string": return fmt.Sprintf("%s%s", prefix, types.TypeStr.String()), nil - case "int64", "int": + case "int", "int64": return fmt.Sprintf("%s%s", prefix, types.TypeInt.String()), nil case "float64": return fmt.Sprintf("%s%s", prefix, types.TypeFloat.String()), nil diff --git a/lang/funcs/funcgen/fixtures/func_base.yaml b/lang/funcs/funcgen/fixtures/func_base.yaml index f549cc8c..d80616c7 100644 --- a/lang/funcs/funcgen/fixtures/func_base.yaml +++ b/lang/funcs/funcgen/fixtures/func_base.yaml @@ -1,5 +1,5 @@ - mgmtPackage: golang/testpkg - mgmtName: all_kind + mclName: all_kind internalName: TestpkgAllKind golangPackage: &pkg name: testpkg @@ -9,7 +9,7 @@ args: [{name: x, type: int64},{name: y, type: string}] return: [{type: float64}] - mgmtPackage: golang/testpkg - mgmtName: to_upper + mclName: to_upper internalName: TestpkgToUpper golangPackage: *pkg golangFunc: ToUpper @@ -17,7 +17,7 @@ args: [{name: s, type: string}] return: [{type: string}] - mgmtPackage: golang/testpkg - mgmtName: max + mclName: max internalName: TestpkgMax golangPackage: *pkg golangFunc: Max @@ -25,7 +25,7 @@ args: [{name: x, type: float64},{name: y, type: float64}] return: [{type: float64}] - mgmtPackage: golang/testpkg - mgmtName: with_error + mclName: with_error internalName: TestpkgWithError golangPackage: *pkg golangFunc: WithError @@ -33,7 +33,7 @@ args: [{name: s, type: string}] return: [{type: string}] - mgmtPackage: golang/testpkg - mgmtName: with_int + mclName: with_int internalName: TestpkgWithInt golangPackage: *pkg golangFunc: WithInt diff --git a/lang/funcs/funcgen/func.go b/lang/funcs/funcgen/func.go index 8b20e796..ca55d457 100644 --- a/lang/funcs/funcgen/func.go +++ b/lang/funcs/funcgen/func.go @@ -31,7 +31,7 @@ type function struct { // MclName is the name of the package of the function in mcl. MgmtPackage string `yaml:"mgmtPackage"` // MclName is the name of the function in mcl. - MclName string `yaml:"mgmtName"` + MclName string `yaml:"mclName"` // InternalName is the name used inside the templated file. // Used to avoid clash between same functions from different packages. InternalName string `yaml:"internalName"` diff --git a/lang/funcs/funcgen/pkg.go b/lang/funcs/funcgen/pkg.go index abeab790..0a15199e 100644 --- a/lang/funcs/funcgen/pkg.go +++ b/lang/funcs/funcgen/pkg.go @@ -33,14 +33,14 @@ import ( ) var ( - validSignature = regexp.MustCompile(`^func (?P[A-Z][a-zA-Z0-9]+)\((?P([a-zA-Z]+( (string|bool|float64|int64|int))?(, )?){0,})\) (?P(string|float64|int64|bool|int)|\((string|float64|int64|bool|int), error\))$`) + validSignature = regexp.MustCompile(`^func (?P[A-Z][a-zA-Z0-9]+)\((?P([a-zA-Z]+( (bool|string|int|int64|float64))?(, )?){0,})\) (?P(bool|string|int|int64|float64|)|\((bool|string|int|int64|float64), error\))$`) errExcluded = errors.New("function is excluded") ) type golangPackages []*golangPackage type golangPackage struct { - // Name is the name of the go package. + // Name is the name of the golang package. Name string `yaml:"name"` // Alias is the alias of the package when imported in golang. // e.g. import rand "os.rand" @@ -142,11 +142,11 @@ func (obj *golangPackage) parseFunctionLine(line string, getHelp bool) (*functio return nil, errExcluded } - mgmtpackage := obj.Name + mgmtPackage := obj.Name if obj.MgmtAlias != "" { - mgmtpackage = obj.MgmtAlias + mgmtPackage = obj.MgmtAlias } - mgmtpackage = fmt.Sprintf("golang/%s", mgmtpackage) + mgmtPackage = fmt.Sprintf("golang/%s", mgmtPackage) internalName := fmt.Sprintf("%s%s", strcase.ToCamel(strings.Replace(obj.Name, "/", "", -1)), name) internalName = strings.Replace(internalName, "Html", "HTML", -1) @@ -159,7 +159,7 @@ func (obj *golangPackage) parseFunctionLine(line string, getHelp bool) (*functio } return &function{ - MgmtPackage: mgmtpackage, + MgmtPackage: mgmtPackage, MclName: strcase.ToSnake(name), InternalName: internalName, Help: help, @@ -205,7 +205,7 @@ func parseArgs(str string) []arg { func parseReturn(str string) []arg { var returns []arg - re := regexp.MustCompile(`(int64|float64|string|bool|int)`) + re := regexp.MustCompile(`(bool|string|int|int64|float64)`) t := string(re.Find([]byte(str))) returns = append(returns, arg{Type: t}) return returns