lang: funcs: Add nitpicks from funcgen
Discussed nitpicks with roidelapluie to clean up slightly for consistency.
This commit is contained in:
1
lang/funcs/core/.gitignore
vendored
1
lang/funcs/core/.gitignore
vendored
@@ -1,2 +1 @@
|
||||
generated_funcs.go
|
||||
generated_funcs_test.go
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -33,14 +33,14 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
validSignature = regexp.MustCompile(`^func (?P<name>[A-Z][a-zA-Z0-9]+)\((?P<args>([a-zA-Z]+( (string|bool|float64|int64|int))?(, )?){0,})\) (?P<return>(string|float64|int64|bool|int)|\((string|float64|int64|bool|int), error\))$`)
|
||||
validSignature = regexp.MustCompile(`^func (?P<name>[A-Z][a-zA-Z0-9]+)\((?P<args>([a-zA-Z]+( (bool|string|int|int64|float64))?(, )?){0,})\) (?P<return>(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
|
||||
|
||||
Reference in New Issue
Block a user