[refactoring] update ast structure of "Break", "Continue" nodes
This commit is contained in:
		
							parent
							
								
									f6cb2bff4d
								
							
						
					
					
						commit
						e817f8dd8d
					
				
							
								
								
									
										1000
									
								
								internal/php5/php5.go
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1000
									
								
								internal/php5/php5.go
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -950,51 +950,45 @@ unticked_statement: | |||||||
|             } |             } | ||||||
|     |   T_BREAK ';' |     |   T_BREAK ';' | ||||||
|             { |             { | ||||||
|                 $$ = &ast.StmtBreak{ast.Node{}, nil} |                 $$ = &ast.StmtBreak{ | ||||||
| 
 |                     Node: ast.Node{ | ||||||
|                 // save position |                         Position: position.NewTokensPosition($1, $2), | ||||||
|                 $$.GetNode().Position = position.NewTokensPosition($1, $2) |                     }, | ||||||
| 
 |                     BreakTkn:     $1, | ||||||
|                 // save comments |                     SemiColonTkn: $2, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) |                 } | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) |  | ||||||
|                 yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens) |  | ||||||
|             } |             } | ||||||
|     |   T_BREAK expr ';' |     |   T_BREAK expr ';' | ||||||
|             { |             { | ||||||
|                 $$ = &ast.StmtBreak{ast.Node{}, $2} |                 $$ = &ast.StmtBreak{ | ||||||
| 
 |                     Node: ast.Node{ | ||||||
|                 // save position |                         Position: position.NewTokensPosition($1, $3), | ||||||
|                 $$.GetNode().Position = position.NewTokensPosition($1, $3) |                     }, | ||||||
| 
 |                     BreakTkn:     $1, | ||||||
|                 // save comments |                     Expr:         $2, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) |                     SemiColonTkn: $3, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) |                 } | ||||||
|                 yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens) |  | ||||||
|             } |             } | ||||||
|     |   T_CONTINUE ';' |     |   T_CONTINUE ';' | ||||||
|             { |             { | ||||||
|                 $$ = &ast.StmtContinue{ast.Node{}, nil} |                 $$ = &ast.StmtContinue{ | ||||||
| 
 |                     Node: ast.Node{ | ||||||
|                 // save position |                         Position: position.NewTokensPosition($1, $2), | ||||||
|                 $$.GetNode().Position = position.NewTokensPosition($1, $2) |                     }, | ||||||
| 
 |                     ContinueTkn:  $1, | ||||||
|                 // save comments |                     SemiColonTkn: $2, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) |                 } | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) |  | ||||||
|                 yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens) |  | ||||||
|             } |             } | ||||||
|     |   T_CONTINUE expr ';' |     |   T_CONTINUE expr ';' | ||||||
|             { |             { | ||||||
|                 $$ = &ast.StmtContinue{ast.Node{}, $2} |                 $$ = &ast.StmtContinue{ | ||||||
| 
 |                     Node: ast.Node{ | ||||||
|                 // save position |                         Position: position.NewTokensPosition($1, $3), | ||||||
|                 $$.GetNode().Position = position.NewTokensPosition($1, $3) |                     }, | ||||||
| 
 |                     ContinueTkn:  $1, | ||||||
|                 // save comments |                     Expr:         $2, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) |                     SemiColonTkn: $3, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) |                 } | ||||||
|                 yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens) |  | ||||||
|             } |             } | ||||||
|     |   T_RETURN ';' |     |   T_RETURN ';' | ||||||
|             { |             { | ||||||
|  | |||||||
							
								
								
									
										744
									
								
								internal/php7/php7.go
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										744
									
								
								internal/php7/php7.go
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -919,27 +919,25 @@ statement: | |||||||
|             } |             } | ||||||
|     |   T_BREAK optional_expr ';' |     |   T_BREAK optional_expr ';' | ||||||
|             { |             { | ||||||
|                 $$ = &ast.StmtBreak{ast.Node{}, $2} |                 $$ = &ast.StmtBreak{ | ||||||
| 
 |                     Node: ast.Node{ | ||||||
|                 // save position |                         Position: position.NewTokensPosition($1, $3), | ||||||
|                 $$.GetNode().Position = position.NewTokensPosition($1, $3) |                     }, | ||||||
| 
 |                     BreakTkn:     $1, | ||||||
|                 // save comments |                     Expr:         $2, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) |                     SemiColonTkn: $3, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) |                 } | ||||||
|                 yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens) |  | ||||||
|             } |             } | ||||||
|     |   T_CONTINUE optional_expr ';' |     |   T_CONTINUE optional_expr ';' | ||||||
|             { |             { | ||||||
|                 $$ = &ast.StmtContinue{ast.Node{}, $2} |                 $$ = &ast.StmtContinue{ | ||||||
| 
 |                     Node: ast.Node{ | ||||||
|                 // save position |                         Position: position.NewTokensPosition($1, $3), | ||||||
|                 $$.GetNode().Position = position.NewTokensPosition($1, $3) |                     }, | ||||||
| 
 |                     ContinueTkn:  $1, | ||||||
|                 // save comments |                     Expr:         $2, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) |                     SemiColonTkn: $3, | ||||||
|                 yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) |                 } | ||||||
|                 yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens) |  | ||||||
|             } |             } | ||||||
|     |   T_RETURN optional_expr ';' |     |   T_RETURN optional_expr ';' | ||||||
|             { |             { | ||||||
|  | |||||||
| @ -191,7 +191,9 @@ func (n *StmtAltForeach) Accept(v NodeVisitor) { | |||||||
| // StmtBreak node | // StmtBreak node | ||||||
| type StmtBreak struct { | type StmtBreak struct { | ||||||
| 	Node | 	Node | ||||||
|  | 	BreakTkn     *token.Token | ||||||
| 	Expr         Vertex | 	Expr         Vertex | ||||||
|  | 	SemiColonTkn *token.Token | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (n *StmtBreak) Accept(v NodeVisitor) { | func (n *StmtBreak) Accept(v NodeVisitor) { | ||||||
| @ -314,7 +316,9 @@ func (n *StmtConstant) Accept(v NodeVisitor) { | |||||||
| // StmtContinue node | // StmtContinue node | ||||||
| type StmtContinue struct { | type StmtContinue struct { | ||||||
| 	Node | 	Node | ||||||
|  | 	ContinueTkn  *token.Token | ||||||
| 	Expr         Vertex | 	Expr         Vertex | ||||||
|  | 	SemiColonTkn *token.Token | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (n *StmtContinue) Accept(v NodeVisitor) { | func (n *StmtContinue) Accept(v NodeVisitor) { | ||||||
|  | |||||||
| @ -163,3 +163,13 @@ func (v *FilterTokens) StmtDefault(n *ast.StmtDefault) { | |||||||
| 	n.DefaultTkn = nil | 	n.DefaultTkn = nil | ||||||
| 	n.CaseSeparatorTkn = 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) | 	p.printFreeFloating(nn, token.End) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *Printer) printStmtBreak(n ast.Vertex) { | func (p *Printer) printStmtBreak(n *ast.StmtBreak) { | ||||||
| 	nn := n.(*ast.StmtBreak) | 	p.printToken(n.BreakTkn, "break") | ||||||
| 	p.printFreeFloating(nn, token.Start) |  | ||||||
| 
 | 
 | ||||||
| 	io.WriteString(p.w, "break") | 	if n.Expr != nil { | ||||||
| 	if nn.Expr != nil { | 		p.bufStart = " " | ||||||
| 		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, ";") |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	p.printFreeFloating(nn, token.End) | 	p.Print(n.Expr) | ||||||
|  | 	p.printToken(n.SemiColonTkn, ";") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *Printer) printStmtCase(n *ast.StmtCase) { | func (p *Printer) printStmtCase(n *ast.StmtCase) { | ||||||
| @ -2202,26 +2192,15 @@ func (p *Printer) printStmtConstant(n *ast.StmtConstant) { | |||||||
| 	p.printToken(n.CommaTkn, "") | 	p.printToken(n.CommaTkn, "") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *Printer) printStmtContinue(n ast.Vertex) { | func (p *Printer) printStmtContinue(n *ast.StmtContinue) { | ||||||
| 	nn := n.(*ast.StmtContinue) | 	p.printToken(n.ContinueTkn, "continue") | ||||||
| 	p.printFreeFloating(nn, token.Start) |  | ||||||
| 
 | 
 | ||||||
| 	io.WriteString(p.w, "continue") | 	if n.Expr != nil { | ||||||
| 
 | 		p.bufStart = " " | ||||||
| 	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, ";") |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	p.printFreeFloating(nn, token.End) | 	p.Print(n.Expr) | ||||||
|  | 	p.printToken(n.SemiColonTkn, ";") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *Printer) printStmtDeclare(n ast.Vertex) { | func (p *Printer) printStmtDeclare(n ast.Vertex) { | ||||||
|  | |||||||
| @ -837,7 +837,8 @@ func TestParseAndPrintPhp5AltWhile(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestParseAndPrintPhp5Break(t *testing.T) { | func TestParseAndPrintPhp5Break(t *testing.T) { | ||||||
| 	src := `<?php | 	// TODO: remove ; after <?php | ||||||
|  | 	src := `<?php ; | ||||||
| 
 | 
 | ||||||
| 	break ; | 	break ; | ||||||
| 	break 1 ; | 	break 1 ; | ||||||
| @ -913,7 +914,8 @@ func TestParseAndPrintPhp5ConstList(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestParseAndPrintPhp5Continue(t *testing.T) { | func TestParseAndPrintPhp5Continue(t *testing.T) { | ||||||
| 	src := `<?php | 	// TODO: remove ; after <?php | ||||||
|  | 	src := `<?php ; | ||||||
| 
 | 
 | ||||||
| 	continue ; | 	continue ; | ||||||
| 	continue 1 ; | 	continue 1 ; | ||||||
|  | |||||||
| @ -950,7 +950,8 @@ func TestParseAndPrintAltWhile(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestParseAndPrintBreak(t *testing.T) { | func TestParseAndPrintBreak(t *testing.T) { | ||||||
| 	src := `<?php | 	// TODO: remove ; after <?php | ||||||
|  | 	src := `<?php ; | ||||||
| 
 | 
 | ||||||
| 	break ; | 	break ; | ||||||
| 	break 1 ; | 	break 1 ; | ||||||
| @ -1029,7 +1030,8 @@ func TestParseAndPrintConstList(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestParseAndPrintContinue(t *testing.T) { | func TestParseAndPrintContinue(t *testing.T) { | ||||||
| 	src := `<?php | 	// TODO: remove ; after <?php | ||||||
|  | 	src := `<?php ; | ||||||
| 
 | 
 | ||||||
| 	continue ; | 	continue ; | ||||||
| 	continue 1 ; | 	continue 1 ; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user