fix syntax of the key expression (#4586)

This commit is contained in:
kesonan
2025-01-18 23:46:24 +08:00
committed by GitHub
parent 3d931d7030
commit b650c8c425
9 changed files with 127 additions and 69 deletions

View File

@@ -46,7 +46,8 @@ func (i *InfoStmt) Format(prefix ...string) string {
w.Write(withNode(infoNode, i.LParen))
w.NewLine()
for _, v := range i.Values {
node := transferTokenNode(v.Key, withTokenNodePrefix(peekOne(prefix)+Indent), ignoreLeadingComment())
node := transferNilInfixNode([]*TokenNode{v.Key, v.Colon})
node = transferTokenNode(node, withTokenNodePrefix(peekOne(prefix)+Indent), ignoreLeadingComment())
w.Write(withNode(node, v.Value), expectIndentInfix(), expectSameLine())
w.NewLine()
}

View File

@@ -6,6 +6,8 @@ import "github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/token"
type KVExpr struct {
// Key is the key of the key value expression.
Key *TokenNode
// Colon is the colon of the key value expression.
Colon *TokenNode
// Value is the value of the key value expression.
Value *TokenNode
}
@@ -24,7 +26,8 @@ func (i *KVExpr) CommentGroup() (head, leading CommentGroup) {
func (i *KVExpr) Format(prefix ...string) string {
w := NewBufferWriter()
w.Write(withNode(i.Key, i.Value), withPrefix(prefix...), withInfix(Indent), withRawText())
node := transferNilInfixNode([]*TokenNode{i.Key, i.Colon})
w.Write(withNode(node, i.Value), withPrefix(prefix...), withInfix(Indent), withRawText())
return w.String()
}

View File

@@ -46,7 +46,8 @@ func (a *AtServerStmt) Format(prefix ...string) string {
w.Write(withNode(atServerNode, a.LParen), expectSameLine())
w.NewLine()
for _, v := range a.Values {
node := transferTokenNode(v.Key, withTokenNodePrefix(peekOne(prefix)+Indent), ignoreLeadingComment())
node := transferNilInfixNode([]*TokenNode{v.Key, v.Colon})
node = transferTokenNode(node, withTokenNodePrefix(peekOne(prefix)+Indent), ignoreLeadingComment())
w.Write(withNode(node, v.Value), expectIndentInfix(), expectSameLine())
w.NewLine()
}
@@ -148,7 +149,8 @@ func (a *AtDocGroupStmt) Format(prefix ...string) string {
w.Write(withNode(atDocNode, a.LParen), expectSameLine())
w.NewLine()
for _, v := range a.Values {
node := transferTokenNode(v.Key, withTokenNodePrefix(peekOne(prefix)+Indent), ignoreLeadingComment())
node := transferNilInfixNode([]*TokenNode{v.Key, v.Colon})
node = transferTokenNode(node, withTokenNodePrefix(peekOne(prefix)+Indent), ignoreLeadingComment())
w.Write(withNode(node, v.Value), expectIndentInfix(), expectSameLine())
w.NewLine()
}