2020-04-10 05:20:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-04-10 05:37:59 +00:00
|
|
|
//"fmt"
|
2020-04-10 05:20:54 +00:00
|
|
|
//"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
2020-04-10 05:37:59 +00:00
|
|
|
//"github.com/z7zmey/php-parser/walker"
|
2020-04-10 05:20:54 +00:00
|
|
|
)
|
|
|
|
|
2020-04-12 02:42:01 +00:00
|
|
|
func normaliseAltCb(n_ *node.Node) error {
|
2020-04-10 05:20:54 +00:00
|
|
|
|
2020-04-10 05:37:59 +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
|
2020-04-10 05:37:59 +00:00
|
|
|
|
|
|
|
*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
|
2020-04-10 05:37:59 +00:00
|
|
|
|
|
|
|
*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
|
|
|
|
|
2020-04-10 05:37:59 +00:00
|
|
|
*n_ = elifStmt
|
2020-04-10 05:20:54 +00:00
|
|
|
|
|
|
|
default:
|
2020-04-12 02:42:01 +00:00
|
|
|
// no change
|
2020-04-10 05:20:54 +00:00
|
|
|
}
|
2020-04-12 02:42:01 +00:00
|
|
|
|
|
|
|
return nil // always
|
2020-04-10 05:20:54 +00:00
|
|
|
}
|