[refactoring] update ast structure of "StmtList" nodes

This commit is contained in:
Vadym Slizov
2020-09-02 22:58:19 +03:00
parent c63213630a
commit 954208510e
9 changed files with 1075 additions and 959 deletions

View File

@@ -691,7 +691,9 @@ func (n *StmtStaticVar) Accept(v NodeVisitor) {
// StmtStmtList node
type StmtStmtList struct {
Node
Stmts []Vertex
OpenCurlyBracket *token.Token
Stmts []Vertex
CloseCurlyBracket *token.Token
}
func (n *StmtStmtList) Accept(v NodeVisitor) {

View File

@@ -82,3 +82,8 @@ func (v *FilterTokens) StmtConstant(n *ast.StmtConstant) {
n.EqualTkn = nil
n.CommaTkn = nil
}
func (v *FilterTokens) StmtStmtList(n *ast.StmtStmtList) {
n.OpenCurlyBracket = nil
n.CloseCurlyBracket = nil
}

View File

@@ -2530,6 +2530,7 @@ func (p *Printer) printStmtDo(n ast.Vertex) {
}
p.Print(nn.Stmt)
p.printFreeFloating(nn, token.Stmts)
io.WriteString(p.w, "while")
@@ -3001,16 +3002,10 @@ func (p *Printer) printStmtStatic(n ast.Vertex) {
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printStmtStmtList(n ast.Vertex) {
nn := n.(*ast.StmtStmtList)
p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "{")
p.printNodes(nn.Stmts)
p.printFreeFloating(nn, token.Stmts)
io.WriteString(p.w, "}")
p.printFreeFloating(nn, token.End)
func (p *Printer) printStmtStmtList(n *ast.StmtStmtList) {
p.printToken(n.OpenCurlyBracket, "{")
p.printNodes(n.Stmts)
p.printToken(n.CloseCurlyBracket, "}")
}
func (p *Printer) printStmtSwitch(n ast.Vertex) {

View File

@@ -1211,7 +1211,8 @@ func TestParseAndPrintPhp5StaticVar(t *testing.T) {
}
func TestParseAndPrintPhp5StmtList(t *testing.T) {
src := `<?php
// TODO: remove ; after <?php
src := `<?php ;
{
;
}

View File

@@ -1344,7 +1344,8 @@ func TestParseAndPrintStaticVar(t *testing.T) {
}
func TestParseAndPrintStmtList(t *testing.T) {
src := `<?php
// TODO: remove ; after <?php
src := `<?php ;
{
;
}