(goctl)fix parser issues (#3930)

This commit is contained in:
kesonan
2024-03-02 22:27:39 +08:00
committed by GitHub
parent a5d2b971a1
commit e08ba2fee8
13 changed files with 179 additions and 24 deletions

View File

@@ -84,6 +84,19 @@ func (t *TokenNode) SetLeadingCommentGroup(cg CommentGroup) {
t.LeadingCommentGroup = cg
}
// RawText returns the node's raw text.
func (t *TokenNode) RawText() string {
text := t.Token.Text
if strings.HasPrefix(text, "`") {
text = strings.TrimPrefix(text, "`")
text = strings.TrimSuffix(text, "`")
} else if strings.HasPrefix(text, `"`) {
text = strings.TrimPrefix(text, `"`)
text = strings.TrimSuffix(text, `"`)
}
return text
}
func (t *TokenNode) HasLeadingCommentGroup() bool {
return t.LeadingCommentGroup.Valid() || t.leadingFlag
}