[refactoring] update ast structure of "Try", "Catch" and "Finally" nodes
This commit is contained in:
@@ -203,9 +203,15 @@ func (n *StmtCase) Accept(v NodeVisitor) {
|
||||
// StmtCatch node
|
||||
type StmtCatch struct {
|
||||
Node
|
||||
Types []Vertex
|
||||
Var Vertex
|
||||
Stmts []Vertex
|
||||
CatchTkn *token.Token
|
||||
OpenParenthesisTkn *token.Token
|
||||
Types []Vertex
|
||||
SeparatorTkns []*token.Token
|
||||
Var Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtCatch) Accept(v NodeVisitor) {
|
||||
@@ -415,7 +421,10 @@ func (n *StmtExpression) Accept(v NodeVisitor) {
|
||||
// StmtFinally node
|
||||
type StmtFinally struct {
|
||||
Node
|
||||
Stmts []Vertex
|
||||
FinallyTkn *token.Token
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtFinally) Accept(v NodeVisitor) {
|
||||
@@ -776,9 +785,12 @@ func (n *StmtTraitUsePrecedence) Accept(v NodeVisitor) {
|
||||
// StmtTry node
|
||||
type StmtTry struct {
|
||||
Node
|
||||
Stmts []Vertex
|
||||
Catches []Vertex
|
||||
Finally Vertex
|
||||
TryTkn *token.Token
|
||||
OpenCurlyBracket *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracket *token.Token
|
||||
Catches []Vertex
|
||||
Finally Vertex
|
||||
}
|
||||
|
||||
func (n *StmtTry) Accept(v NodeVisitor) {
|
||||
|
||||
@@ -239,3 +239,24 @@ func (v *FilterTokens) StmtDeclare(n *ast.StmtDeclare) {
|
||||
func (v *FilterTokens) StmtNop(n *ast.StmtNop) {
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtTry(n *ast.StmtTry) {
|
||||
n.TryTkn = nil
|
||||
n.OpenCurlyBracket = nil
|
||||
n.CloseCurlyBracket = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtCatch(n *ast.StmtCatch) {
|
||||
n.CatchTkn = nil
|
||||
n.OpenParenthesisTkn = nil
|
||||
n.SeparatorTkns = nil
|
||||
n.CloseParenthesisTkn = nil
|
||||
n.OpenCurlyBracketTkn = nil
|
||||
n.CloseCurlyBracketTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtFinally(n *ast.StmtFinally) {
|
||||
n.FinallyTkn = nil
|
||||
n.OpenCurlyBracketTkn = nil
|
||||
n.CloseCurlyBracketTkn = nil
|
||||
}
|
||||
|
||||
@@ -2009,26 +2009,15 @@ func (p *Printer) printStmtCase(n *ast.StmtCase) {
|
||||
p.printNodes(n.Stmts)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtCatch(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtCatch)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
p.write([]byte("catch"))
|
||||
p.printFreeFloating(nn, token.Catch)
|
||||
p.write([]byte("("))
|
||||
|
||||
p.joinPrintRefactored("|", nn.Types)
|
||||
|
||||
p.Print(nn.Var)
|
||||
p.printFreeFloating(nn, token.Var)
|
||||
p.write([]byte(")"))
|
||||
p.printFreeFloating(nn, token.Cond)
|
||||
p.write([]byte("{"))
|
||||
p.printNodes(nn.Stmts)
|
||||
p.printFreeFloating(nn, token.Stmts)
|
||||
p.write([]byte("}"))
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
func (p *Printer) printStmtCatch(n *ast.StmtCatch) {
|
||||
p.printToken(n.CatchTkn, "catch")
|
||||
p.printToken(n.OpenParenthesisTkn, "(")
|
||||
p.printSeparatedList(n.Types, n.SeparatorTkns, "|")
|
||||
p.Print(n.Var)
|
||||
p.printToken(n.CloseParenthesisTkn, ")")
|
||||
p.printToken(n.OpenCurlyBracketTkn, "{")
|
||||
p.printNodes(n.Stmts)
|
||||
p.printToken(n.CloseCurlyBracketTkn, "}")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtClassMethod(n ast.Vertex) {
|
||||
@@ -2296,18 +2285,11 @@ func (p *Printer) printStmtExpression(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtFinally(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtFinally)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
p.write([]byte("finally"))
|
||||
p.printFreeFloating(nn, token.Finally)
|
||||
p.write([]byte("{"))
|
||||
p.printNodes(nn.Stmts)
|
||||
p.printFreeFloating(nn, token.Stmts)
|
||||
p.write([]byte("}"))
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
func (p *Printer) printStmtFinally(n *ast.StmtFinally) {
|
||||
p.printToken(n.FinallyTkn, "finally")
|
||||
p.printToken(n.OpenCurlyBracketTkn, "{")
|
||||
p.printNodes(n.Stmts)
|
||||
p.printToken(n.CloseCurlyBracketTkn, "}")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtFor(n *ast.StmtFor) {
|
||||
@@ -2828,26 +2810,19 @@ func (p *Printer) printStmtTrait(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtTry(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtTry)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
func (p *Printer) printStmtTry(n *ast.StmtTry) {
|
||||
p.printToken(n.TryTkn, "try")
|
||||
p.printToken(n.OpenCurlyBracket, "{")
|
||||
p.printNodes(n.Stmts)
|
||||
p.printToken(n.CloseCurlyBracket, "}")
|
||||
|
||||
p.write([]byte("try"))
|
||||
p.printFreeFloating(nn, token.Try)
|
||||
p.write([]byte("{"))
|
||||
p.printNodes(nn.Stmts)
|
||||
p.printFreeFloating(nn, token.Stmts)
|
||||
p.write([]byte("}"))
|
||||
|
||||
if nn.Catches != nil {
|
||||
p.printNodes(nn.Catches)
|
||||
if n.Catches != nil {
|
||||
p.printNodes(n.Catches)
|
||||
}
|
||||
|
||||
if nn.Finally != nil {
|
||||
p.Print(nn.Finally)
|
||||
if n.Finally != nil {
|
||||
p.Print(n.Finally)
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtUnset(n *ast.StmtUnset) {
|
||||
|
||||
Reference in New Issue
Block a user