php2go/normalisealts.go

68 lines
1.4 KiB
Go
Raw Permalink Normal View History

2020-04-10 05:20:54 +00:00
package main
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
)
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
case *stmt.AltFor:
forStmt := stmt.NewFor(n.Init, n.Cond, n.Loop, n.Stmt)
forStmt.FreeFloating = n.FreeFloating
forStmt.Position = n.Position
*n_ = forStmt
case *stmt.AltForeach:
feStmt := stmt.NewForeach(n.Expr, n.Key, n.Variable, n.Stmt)
feStmt.FreeFloating = n.FreeFloating
feStmt.Position = n.Position
*n_ = feStmt
case *stmt.AltSwitch:
swStmt := stmt.NewSwitch(n.Cond, n.CaseList)
swStmt.FreeFloating = n.FreeFloating
swStmt.Position = n.Position
*n_ = swStmt
case *stmt.AltWhile:
wStmt := stmt.NewWhile(n.Cond, n.Stmt)
wStmt.FreeFloating = n.FreeFloating
wStmt.Position = n.Position
*n_ = wStmt
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
}