-
Notifications
You must be signed in to change notification settings - Fork 14
/
syntaxstatement.go
44 lines (35 loc) · 1.13 KB
/
syntaxstatement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package ast
import "github.com/suyuan32/goctls/pkg/parser/api/token"
// SyntaxStmt represents a syntax statement.
type SyntaxStmt struct {
// Syntax is the syntax token.
Syntax *TokenNode
// Assign is the assign token.
Assign *TokenNode
// Value is the syntax value.
Value *TokenNode
}
func (s *SyntaxStmt) HasHeadCommentGroup() bool {
return s.Syntax.HasHeadCommentGroup()
}
func (s *SyntaxStmt) HasLeadingCommentGroup() bool {
return s.Value.HasLeadingCommentGroup()
}
func (s *SyntaxStmt) CommentGroup() (head, leading CommentGroup) {
return s.Syntax.HeadCommentGroup, s.Syntax.LeadingCommentGroup
}
func (s *SyntaxStmt) Format(prefix ...string) string {
w := NewBufferWriter()
syntaxNode := transferTokenNode(s.Syntax,
withTokenNodePrefix(prefix...), ignoreLeadingComment())
assignNode := transferTokenNode(s.Assign, ignoreLeadingComment())
w.Write(withNode(syntaxNode, assignNode, s.Value), withPrefix(prefix...), expectSameLine())
return w.String()
}
func (s *SyntaxStmt) End() token.Position {
return s.Value.End()
}
func (s *SyntaxStmt) Pos() token.Position {
return s.Syntax.Pos()
}
func (s *SyntaxStmt) stmtNode() {}