mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-25 02:08:44 +08:00
ee19fb736b
* 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>
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package ast
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
|
|
)
|
|
|
|
type KvExpr struct {
|
|
Key Expr
|
|
Value Expr
|
|
DocExpr []Expr
|
|
CommentExpr Expr
|
|
}
|
|
|
|
func (v *ApiVisitor) VisitKvLit(ctx *api.KvLitContext) interface{} {
|
|
var kvExpr KvExpr
|
|
kvExpr.Key = v.newExprWithToken(ctx.GetKey())
|
|
commentExpr := v.getComment(ctx)
|
|
if ctx.GetValue() != nil {
|
|
valueText := ctx.GetValue().GetText()
|
|
valueExpr := v.newExprWithToken(ctx.GetValue())
|
|
if strings.Contains(valueText, "//") {
|
|
if commentExpr == nil {
|
|
commentExpr = v.newExprWithToken(ctx.GetValue())
|
|
commentExpr.SetText("")
|
|
}
|
|
|
|
index := strings.Index(valueText, "//")
|
|
commentExpr.SetText(valueText[index:])
|
|
valueExpr.SetText(strings.TrimSpace(valueText[:index]))
|
|
} else if strings.Contains(valueText, "/*") {
|
|
if commentExpr == nil {
|
|
commentExpr = v.newExprWithToken(ctx.GetValue())
|
|
commentExpr.SetText("")
|
|
}
|
|
|
|
index := strings.Index(valueText, "/*")
|
|
commentExpr.SetText(valueText[index:])
|
|
valueExpr.SetText(strings.TrimSpace(valueText[:index]))
|
|
}
|
|
|
|
kvExpr.Value = valueExpr
|
|
}
|
|
|
|
kvExpr.DocExpr = v.getDoc(ctx)
|
|
kvExpr.CommentExpr = commentExpr
|
|
return &kvExpr
|
|
}
|
|
|
|
func (k *KvExpr) Format() error {
|
|
// todo
|
|
return nil
|
|
}
|
|
|
|
func (k *KvExpr) Equal(v interface{}) bool {
|
|
if v == nil {
|
|
return false
|
|
}
|
|
|
|
kv, ok := v.(*KvExpr)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
if !EqualDoc(k, kv) {
|
|
return false
|
|
}
|
|
|
|
return k.Key.Equal(kv.Key) && k.Value.Equal(kv.Value)
|
|
}
|
|
|
|
func (k *KvExpr) Doc() []Expr {
|
|
return k.DocExpr
|
|
}
|
|
|
|
func (k *KvExpr) Comment() Expr {
|
|
return k.CommentExpr
|
|
}
|