php2go/normalisealts.go

44 lines
833 B
Go
Raw Normal View History

2020-04-10 05:20:54 +00:00
package main
import (
//"fmt"
2020-04-10 05:20:54 +00:00
//"io/ioutil"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
//"github.com/z7zmey/php-parser/walker"
2020-04-10 05:20:54 +00:00
)
func normaliseAltCb(n_ *node.Node) error {
2020-04-10 05:20:54 +00:00
switch n := (*n_).(type) {
2020-04-10 05:20:54 +00:00
case *stmt.AltIf:
// Build replacement node
ifStmt := stmt.NewIf(n.Cond, n.Stmt, n.ElseIf, n.Else)
ifStmt.FreeFloating = n.FreeFloating
ifStmt.Position = n.Position
// ifStmt has no .Attributes prop
*n_ = ifStmt
2020-04-10 05:20:54 +00:00
case *stmt.AltElse:
elseStmt := stmt.NewElse(n.Stmt)
elseStmt.FreeFloating = n.FreeFloating
elseStmt.Position = n.Position
*n_ = elseStmt
2020-04-10 05:20:54 +00:00
case *stmt.AltElseIf:
elifStmt := stmt.NewElseIf(n.Cond, n.Stmt)
elifStmt.FreeFloating = n.FreeFloating
elifStmt.Position = n.Position
*n_ = elifStmt
2020-04-10 05:20:54 +00:00
default:
// no change
2020-04-10 05:20:54 +00:00
}
return nil // always
2020-04-10 05:20:54 +00:00
}