2023-03-28 23:45:26 +08:00
|
|
|
package ast
|
|
|
|
|
|
|
|
|
|
import "github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/token"
|
|
|
|
|
|
|
|
|
|
// KVExpr is a key value expression.
|
|
|
|
|
type KVExpr struct {
|
|
|
|
|
// Key is the key of the key value expression.
|
|
|
|
|
Key *TokenNode
|
2025-01-18 23:46:24 +08:00
|
|
|
// Colon is the colon of the key value expression.
|
|
|
|
|
Colon *TokenNode
|
2023-03-28 23:45:26 +08:00
|
|
|
// Value is the value of the key value expression.
|
|
|
|
|
Value *TokenNode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) HasHeadCommentGroup() bool {
|
|
|
|
|
return i.Key.HasHeadCommentGroup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) HasLeadingCommentGroup() bool {
|
|
|
|
|
return i.Value.HasLeadingCommentGroup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) CommentGroup() (head, leading CommentGroup) {
|
|
|
|
|
return i.Key.HeadCommentGroup, i.Value.LeadingCommentGroup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) Format(prefix ...string) string {
|
|
|
|
|
w := NewBufferWriter()
|
2025-01-18 23:46:24 +08:00
|
|
|
node := transferNilInfixNode([]*TokenNode{i.Key, i.Colon})
|
|
|
|
|
w.Write(withNode(node, i.Value), withPrefix(prefix...), withInfix(Indent), withRawText())
|
2023-03-28 23:45:26 +08:00
|
|
|
return w.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) End() token.Position {
|
|
|
|
|
return i.Value.End()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) Pos() token.Position {
|
|
|
|
|
return i.Key.Pos()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *KVExpr) exprNode() {}
|