[refactoring] update ast structure of "Break", "Continue" nodes
This commit is contained in:
@@ -191,7 +191,9 @@ func (n *StmtAltForeach) Accept(v NodeVisitor) {
|
||||
// StmtBreak node
|
||||
type StmtBreak struct {
|
||||
Node
|
||||
Expr Vertex
|
||||
BreakTkn *token.Token
|
||||
Expr Vertex
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtBreak) Accept(v NodeVisitor) {
|
||||
@@ -314,7 +316,9 @@ func (n *StmtConstant) Accept(v NodeVisitor) {
|
||||
// StmtContinue node
|
||||
type StmtContinue struct {
|
||||
Node
|
||||
Expr Vertex
|
||||
ContinueTkn *token.Token
|
||||
Expr Vertex
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtContinue) Accept(v NodeVisitor) {
|
||||
|
||||
@@ -163,3 +163,13 @@ func (v *FilterTokens) StmtDefault(n *ast.StmtDefault) {
|
||||
n.DefaultTkn = nil
|
||||
n.CaseSeparatorTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtBreak(n *ast.StmtBreak) {
|
||||
n.BreakTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtContinue(n *ast.StmtContinue) {
|
||||
n.ContinueTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
@@ -2017,25 +2017,15 @@ func (p *Printer) printStmtAltForeach(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtBreak(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtBreak)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
func (p *Printer) printStmtBreak(n *ast.StmtBreak) {
|
||||
p.printToken(n.BreakTkn, "break")
|
||||
|
||||
io.WriteString(p.w, "break")
|
||||
if nn.Expr != nil {
|
||||
if nn.Expr.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
p.Print(nn.Expr)
|
||||
}
|
||||
p.printFreeFloating(nn, token.Expr)
|
||||
|
||||
p.printFreeFloating(nn, token.SemiColon)
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, ";")
|
||||
if n.Expr != nil {
|
||||
p.bufStart = " "
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.Print(n.Expr)
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtCase(n *ast.StmtCase) {
|
||||
@@ -2202,26 +2192,15 @@ func (p *Printer) printStmtConstant(n *ast.StmtConstant) {
|
||||
p.printToken(n.CommaTkn, "")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtContinue(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtContinue)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
func (p *Printer) printStmtContinue(n *ast.StmtContinue) {
|
||||
p.printToken(n.ContinueTkn, "continue")
|
||||
|
||||
io.WriteString(p.w, "continue")
|
||||
|
||||
if nn.Expr != nil {
|
||||
if nn.Expr.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
p.Print(nn.Expr)
|
||||
}
|
||||
p.printFreeFloating(nn, token.Expr)
|
||||
|
||||
p.printFreeFloating(nn, token.SemiColon)
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, ";")
|
||||
if n.Expr != nil {
|
||||
p.bufStart = " "
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.Print(n.Expr)
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtDeclare(n ast.Vertex) {
|
||||
|
||||
@@ -837,7 +837,8 @@ func TestParseAndPrintPhp5AltWhile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Break(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
|
||||
break ;
|
||||
break 1 ;
|
||||
@@ -913,7 +914,8 @@ func TestParseAndPrintPhp5ConstList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Continue(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
|
||||
continue ;
|
||||
continue 1 ;
|
||||
|
||||
@@ -950,7 +950,8 @@ func TestParseAndPrintAltWhile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintBreak(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
|
||||
break ;
|
||||
break 1 ;
|
||||
@@ -1029,7 +1030,8 @@ func TestParseAndPrintConstList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintContinue(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
|
||||
continue ;
|
||||
continue 1 ;
|
||||
|
||||
Reference in New Issue
Block a user