-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathif_expression.go
49 lines (39 loc) · 932 Bytes
/
if_expression.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
package ast
import (
"bytes"
)
type IfExpression struct {
TokenAble
Condition Expression
Block *BlockStatement
ElseIf []*ElseIfExpression
ElseBlock *BlockStatement
}
var _ Expression = &IfExpression{}
type ElseIfExpression struct {
TokenAble
Condition Expression
Block *BlockStatement
}
func (ie *IfExpression) expressionNode() {}
func (ie *IfExpression) String() string {
var out bytes.Buffer
out.WriteString("if (")
out.WriteString(ie.Condition.String())
out.WriteString(") { ")
out.WriteString(ie.Block.String())
out.WriteString(" }")
for _, elseIf := range ie.ElseIf {
out.WriteString(" } else if (")
out.WriteString(elseIf.Condition.String())
out.WriteString(") { ")
out.WriteString(elseIf.Block.String())
out.WriteString(" }")
}
if ie.ElseBlock != nil {
out.WriteString(" } else { ")
out.WriteString(ie.ElseBlock.String())
out.WriteString(" }")
}
return out.String()
}