-
Notifications
You must be signed in to change notification settings - Fork 0
/
range_stmt.go
53 lines (42 loc) · 1.25 KB
/
range_stmt.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
45
46
47
48
49
50
51
52
53
package goastutil
import (
"fmt"
"go/ast"
)
type RangeStmt struct {
parent Stmt
*ast.RangeStmt
}
func NewRangeStmt(parent Stmt, stmt *ast.RangeStmt) *RangeStmt {
return &RangeStmt{RangeStmt: stmt, parent: parent}
}
func (s *RangeStmt) PrependStmt(st string) error {
return prependStmt(st, s.parent, s.RangeStmt)
}
func (s *RangeStmt) AppendStmt(st string) error {
return appendStmt(st, s.parent, s.RangeStmt)
}
func (rs *RangeStmt) StmtType() StmtType {
return RangeStmtType
}
func (rs *RangeStmt) Key() Expr {
return NewExpr(rs.RangeStmt.Key)
}
func (rs *RangeStmt) Value() Expr {
return NewExpr(rs.RangeStmt.Value)
}
func (rs *RangeStmt) Expr() Expr {
return NewExpr(rs.RangeStmt.X)
}
func (rs *RangeStmt) Body() *BlockStmt {
return NewBlockStmt(rs, rs.RangeStmt.Body)
}
// String returns a string representation of the RangeStmt.
//
// The String method returns a formatted string that represents the RangeStmt.
// It includes the key, value, token, expression, and body of the RangeStmt.
// The returned string can be used for debugging and logging purposes.
// The return type of the String method is string.
func (rs *RangeStmt) String() string {
return fmt.Sprintf("for %s, %s %s range %s %s", rs.Key(), rs.Value(), rs.Tok, rs.Expr(), rs.Body())
}