feature: refactor api parse to g4 (#365)
* feature: refactor api parse to g4 * new g4 parser * add CHANGE_LOG.MD * refactor * fix byte bug * refactor * optimized * optimized * revert * update readme.md * update readme.md * update readme.md * update readme.md * remove no need * fix java gen * add upgrade * resolve confilits Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
@@ -19,11 +19,7 @@ func DartCommand(c *cli.Context) error {
|
||||
return errors.New("missing -dir")
|
||||
}
|
||||
|
||||
p, err := parser.NewParser(apiFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
api, err := p.Parse()
|
||||
api, err := parser.Parse(apiFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ func genData(dir string, api *spec.ApiSpec) error {
|
||||
return e
|
||||
}
|
||||
|
||||
convertMemberType(api)
|
||||
return t.Execute(file, api)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package dartgen
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/util"
|
||||
)
|
||||
|
||||
@@ -39,47 +37,6 @@ func tagGet(tag, k string) (reflect.Value, error) {
|
||||
return reflect.ValueOf(out), nil
|
||||
}
|
||||
|
||||
func convertMemberType(api *spec.ApiSpec) {
|
||||
for i, t := range api.Types {
|
||||
for j, mem := range t.Members {
|
||||
api.Types[i].Members[j].Type = goTypeToDart(mem.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func goTypeToDart(t string) string {
|
||||
t = strings.Replace(t, "*", "", -1)
|
||||
if strings.HasPrefix(t, "[]") {
|
||||
return "List<" + goTypeToDart(t[2:]) + ">"
|
||||
}
|
||||
|
||||
if strings.HasPrefix(t, "map") {
|
||||
tys, e := util.DecomposeType(t)
|
||||
if e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
|
||||
if len(tys) != 2 {
|
||||
log.Fatal("Map type number !=2")
|
||||
}
|
||||
|
||||
return "Map<String," + goTypeToDart(tys[1]) + ">"
|
||||
}
|
||||
|
||||
switch t {
|
||||
case "string":
|
||||
return "String"
|
||||
case "int", "int32", "int64":
|
||||
return "int"
|
||||
case "float", "float32", "float64":
|
||||
return "double"
|
||||
case "bool":
|
||||
return "bool"
|
||||
default:
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
||||
func isDirectType(s string) bool {
|
||||
return isAtomicType(s) || isListType(s) && isAtomicType(getCoreType(s))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user