浏览代码

optimize parser (#206)

* add comment support

* add comment support

* 1. group support multi level folder
2. remove force flag

* bug fix

* refactor parser and remove deprecated code

* refactor parser and remove deprecated code

* refactor parser and remove deprecated code

* refactor parser and remove deprecated code

* refactor parser and remove deprecated code

* refactor parser and remove deprecated code

* refactor parser and remove deprecated code

* optimized parser

Co-authored-by: kim <xutao@xiaoheiban.cn>
kingxt 4 年之前
父节点
当前提交
88da8685dd
共有 2 个文件被更改,包括 11 次插入2 次删除
  1. 6 2
      tools/goctl/api/gogen/gen_test.go
  2. 5 0
      tools/goctl/api/parser/apifileparser.go

+ 6 - 2
tools/goctl/api/gogen/gen_test.go

@@ -22,10 +22,14 @@ info(
     version: 1.0
     version: 1.0
 )
 )
 
 
-type Request struct {
+// TODO: test
+// {
+type Request struct {  // TODO: test
+  // TOOD
   Name string ` + "`" + `path:"name,options=you|me"` + "`" + `   // }
   Name string ` + "`" + `path:"name,options=you|me"` + "`" + `   // }
-}
+} // TODO: test
 
 
+// TODO: test
 type Response struct {
 type Response struct {
   Message string ` + "`" + `json:"message"` + "`" + `
   Message string ` + "`" + `json:"message"` + "`" + `
 }
 }

+ 5 - 0
tools/goctl/api/parser/apifileparser.go

@@ -139,6 +139,7 @@ func (s *apiImportState) process(api *ApiStruct, token string) (apiFileState, er
 	}
 	}
 
 
 	line = token + line
 	line = token + line
+	line = removeComment(line)
 	if len(strings.Fields(line)) != 2 {
 	if len(strings.Fields(line)) != 2 {
 		return nil, errors.New("import syntax error: " + line)
 		return nil, errors.New("import syntax error: " + line)
 	}
 	}
@@ -159,6 +160,8 @@ func (s *apiTypeState) process(api *ApiStruct, token string) (apiFileState, erro
 		token = ""
 		token = ""
 		line = strings.TrimSpace(line)
 		line = strings.TrimSpace(line)
 		line = removeComment(line)
 		line = removeComment(line)
+		line = strings.TrimSpace(line)
+
 		if strings.HasSuffix(line, leftBrace) {
 		if strings.HasSuffix(line, leftBrace) {
 			blockCount++
 			blockCount++
 		}
 		}
@@ -191,6 +194,8 @@ func (s *apiServiceState) process(api *ApiStruct, token string) (apiFileState, e
 		api.Service += "\n" + line
 		api.Service += "\n" + line
 		line = strings.TrimSpace(line)
 		line = strings.TrimSpace(line)
 		line = removeComment(line)
 		line = removeComment(line)
+		line = strings.TrimSpace(line)
+
 		if strings.HasSuffix(line, leftBrace) {
 		if strings.HasSuffix(line, leftBrace) {
 			blockCount++
 			blockCount++
 		}
 		}