-
Notifications
You must be signed in to change notification settings - Fork 0
/
for_stmt.go
48 lines (36 loc) · 1012 Bytes
/
for_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
package ast
import (
"bytes"
"github.com/textwire/textwire/token"
)
type ForStmt struct {
Token token.Token // The '@for' token
Init Statement // The initialization statement; or nil
Condition Expression // The condition expression; or nil
Post Statement // The post iteration statement; or nil
Alternative *BlockStmt // The @else block
Block *BlockStmt
}
func (fs *ForStmt) statementNode() {
}
func (fs *ForStmt) TokenLiteral() string {
return fs.Token.Literal
}
func (fs *ForStmt) String() string {
var out bytes.Buffer
out.WriteString("@for(")
out.WriteString(fs.Init.String() + "; ")
out.WriteString(fs.Condition.String() + "; ")
out.WriteString(fs.Post.String())
out.WriteString(")\n")
out.WriteString(fs.Block.String() + "\n")
if fs.Alternative != nil {
out.WriteString("@else\n")
out.WriteString(fs.Alternative.String() + "\n")
}
out.WriteString("@end\n")
return out.String()
}
func (fs *ForStmt) Line() uint {
return fs.Token.Line
}