xgo/ast/for_stmt.go

41 lines
667 B
Go
Raw Normal View History

2019-01-09 10:17:42 +03:00
package ast
import "github.com/d5/tengo/source"
2019-01-09 10:17:42 +03:00
type ForStmt struct {
ForPos source.Pos
2019-01-09 10:17:42 +03:00
Init Stmt
Cond Expr
Post Stmt
Body *BlockStmt
}
func (s *ForStmt) stmtNode() {}
func (s *ForStmt) Pos() source.Pos {
2019-01-09 10:17:42 +03:00
return s.ForPos
}
func (s *ForStmt) End() source.Pos {
2019-01-09 10:17:42 +03:00
return s.Body.End()
}
func (s *ForStmt) String() string {
var init, cond, post string
if s.Init != nil {
init = s.Init.String()
}
if s.Cond != nil {
cond = s.Cond.String() + " "
}
if s.Post != nil {
post = s.Post.String()
}
if init != "" || post != "" {
return "for " + init + " ; " + cond + " ; " + post + s.Body.String()
}
return "for " + cond + s.Body.String()
}