[refactoring] update ast structure of "Do" node
This commit is contained in:
parent
3b85f5e82b
commit
c274c4f92f
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -911,16 +911,18 @@ unticked_statement:
|
|||||||
}
|
}
|
||||||
| T_DO statement T_WHILE parenthesis_expr ';'
|
| T_DO statement T_WHILE parenthesis_expr ';'
|
||||||
{
|
{
|
||||||
$$ = &ast.StmtDo{ast.Node{}, $2, $4}
|
$$ = &ast.StmtDo{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $5),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $5)
|
},
|
||||||
|
DoTkn: $1,
|
||||||
// save comments
|
Stmt: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
WhileTkn: $3,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.SkippedTokens)
|
OpenParenthesisTkn: $4.(*ast.ParserBrackets).OpenBracketTkn,
|
||||||
yylex.(*Parser).setFreeFloating($4, token.End, $5.SkippedTokens)
|
Cond: $4.(*ast.ParserBrackets).Child,
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $5.SkippedTokens)
|
CloseParenthesisTkn: $4.(*ast.ParserBrackets).CloseBracketTkn,
|
||||||
|
SemiColonTkn: $5,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
|
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
|
||||||
{
|
{
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -880,25 +880,18 @@ statement:
|
|||||||
}
|
}
|
||||||
| T_DO statement T_WHILE '(' expr ')' ';'
|
| T_DO statement T_WHILE '(' expr ')' ';'
|
||||||
{
|
{
|
||||||
exprBrackets := &ast.ParserBrackets{
|
$$ = &ast.StmtDo{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokensPosition($4, $6),
|
Position: position.NewTokensPosition($1, $7),
|
||||||
},
|
},
|
||||||
OpenBracketTkn: $4,
|
DoTkn: $1,
|
||||||
Child: $5,
|
Stmt: $2,
|
||||||
CloseBracketTkn: $6,
|
WhileTkn: $3,
|
||||||
|
OpenParenthesisTkn: $4,
|
||||||
|
Cond: $5,
|
||||||
|
CloseParenthesisTkn: $6,
|
||||||
|
SemiColonTkn: $7,
|
||||||
}
|
}
|
||||||
$$ = &ast.StmtDo{ast.Node{}, $2, exprBrackets}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $7)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $4.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating(exprBrackets, token.End, append($6.SkippedTokens, $7.SkippedTokens...))
|
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $7.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement
|
| T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement
|
||||||
{
|
{
|
||||||
|
@ -378,8 +378,13 @@ func (n *StmtDefault) Accept(v NodeVisitor) {
|
|||||||
// StmtDo node
|
// StmtDo node
|
||||||
type StmtDo struct {
|
type StmtDo struct {
|
||||||
Node
|
Node
|
||||||
|
DoTkn *token.Token
|
||||||
Stmt Vertex
|
Stmt Vertex
|
||||||
|
WhileTkn *token.Token
|
||||||
|
OpenParenthesisTkn *token.Token
|
||||||
Cond Vertex
|
Cond Vertex
|
||||||
|
CloseParenthesisTkn *token.Token
|
||||||
|
SemiColonTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtDo) Accept(v NodeVisitor) {
|
func (n *StmtDo) Accept(v NodeVisitor) {
|
||||||
|
@ -13,16 +13,6 @@ func (v *FilterParserNodes) EnterNode(n ast.Vertex) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FilterParserNodes) StmtDo(n *ast.StmtDo) {
|
|
||||||
for {
|
|
||||||
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {
|
|
||||||
n.Cond = nn.Child
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *FilterParserNodes) StmtSwitch(n *ast.StmtSwitch) {
|
func (v *FilterParserNodes) StmtSwitch(n *ast.StmtSwitch) {
|
||||||
for {
|
for {
|
||||||
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {
|
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {
|
||||||
|
@ -122,3 +122,11 @@ func (v *FilterTokens) StmtWhile(n *ast.StmtWhile) {
|
|||||||
n.EndWhileTkn = nil
|
n.EndWhileTkn = nil
|
||||||
n.SemiColonTkn = nil
|
n.SemiColonTkn = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *FilterTokens) StmtDo(n *ast.StmtDo) {
|
||||||
|
n.DoTkn = nil
|
||||||
|
n.WhileTkn = nil
|
||||||
|
n.OpenParenthesisTkn = nil
|
||||||
|
n.CloseParenthesisTkn = nil
|
||||||
|
n.SemiColonTkn = nil
|
||||||
|
}
|
||||||
|
@ -2361,42 +2361,17 @@ func (p *Printer) printStmtDefault(n ast.Vertex) {
|
|||||||
p.printFreeFloating(nn, token.End)
|
p.printFreeFloating(nn, token.End)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtDo(n ast.Vertex) {
|
func (p *Printer) printStmtDo(n *ast.StmtDo) {
|
||||||
nn := n.(*ast.StmtDo)
|
p.printToken(n.DoTkn, "do")
|
||||||
p.printFreeFloating(nn, token.Start)
|
p.bufStart = " "
|
||||||
|
|
||||||
io.WriteString(p.w, "do")
|
p.Print(n.Stmt)
|
||||||
|
|
||||||
if _, ok := nn.Stmt.(*ast.StmtStmtList); !ok {
|
p.printToken(n.WhileTkn, "while")
|
||||||
if nn.Stmt.GetNode().Tokens.IsEmpty() {
|
p.printToken(n.OpenParenthesisTkn, "(")
|
||||||
io.WriteString(p.w, " ")
|
p.Print(n.Cond)
|
||||||
}
|
p.printToken(n.CloseParenthesisTkn, ")")
|
||||||
}
|
p.printToken(n.SemiColonTkn, ";")
|
||||||
|
|
||||||
p.Print(nn.Stmt)
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.Stmts)
|
|
||||||
|
|
||||||
io.WriteString(p.w, "while")
|
|
||||||
|
|
||||||
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
|
|
||||||
io.WriteString(p.w, "(")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.Print(nn.Cond)
|
|
||||||
|
|
||||||
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
|
|
||||||
io.WriteString(p.w, ")")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.Cond)
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.SemiColon)
|
|
||||||
if nn.GetNode().Tokens.IsEmpty() {
|
|
||||||
io.WriteString(p.w, ";")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.End)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtEcho(n ast.Vertex) {
|
func (p *Printer) printStmtEcho(n ast.Vertex) {
|
||||||
|
@ -945,7 +945,8 @@ func TestParseAndPrintPhp5Declare(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5DoWhile(t *testing.T) {
|
func TestParseAndPrintPhp5DoWhile(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
do {
|
do {
|
||||||
;
|
;
|
||||||
} while ( $a ) ;
|
} while ( $a ) ;
|
||||||
|
@ -1061,7 +1061,8 @@ func TestParseAndPrintDeclare(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintDoWhile(t *testing.T) {
|
func TestParseAndPrintDoWhile(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
do {
|
do {
|
||||||
;
|
;
|
||||||
} while ( $a ) ;
|
} while ( $a ) ;
|
||||||
|
Loading…
Reference in New Issue
Block a user