Improve IF / ELSE statement formatting

This commit is contained in:
Tobie Morgan Hitchcock 2017-12-05 11:07:48 +00:00
parent 7e8d5f9fe9
commit 19ce0b7cad

View file

@ -168,6 +168,17 @@ func (this InfoStatement) String() string {
} }
} }
func (this IfStatement) String() string {
m := make([]string, len(this.Cond))
for k := range this.Cond {
m[k] = print("%v THEN %v", this.Cond[k], this.Then[k])
}
return print("IF %v%v END",
strings.Join(m, " ELSE IF "),
maybe(this.Else != nil, print(" ELSE %v", this.Else)),
)
}
func (this LetStatement) String() string { func (this LetStatement) String() string {
return print("LET %v = %v", return print("LET %v = %v",
this.Name, this.Name,
@ -722,10 +733,13 @@ func (this SubExpression) String() string {
} }
func (this IfelExpression) String() string { func (this IfelExpression) String() string {
return print("IF %v THEN %v%v", m := make([]string, len(this.Cond))
this.Cond, for k := range this.Cond {
this.Then, m[k] = print("%v THEN %v", this.Cond[k], this.Then[k])
maybe(this.Else != nil, print("ELSE %v END", this.Else)), }
return print("IF %v%v END",
strings.Join(m, " ELSE IF "),
maybe(this.Else != nil, print(" ELSE %v", this.Else)),
) )
} }