diff --git a/internal/php5/php5.go b/internal/php5/php5.go index b074c96..926e1be 100644 Binary files a/internal/php5/php5.go and b/internal/php5/php5.go differ diff --git a/internal/php5/php5.y b/internal/php5/php5.y index 668b080..5d11a5d 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -344,14 +344,15 @@ top_statement: } | T_HALT_COMPILER '(' ')' ';' { - $$ = &ast.StmtHaltCompiler{ast.Node{}} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($2.SkippedTokens, append($3.SkippedTokens, $4.SkippedTokens...)...)) + $$ = &ast.StmtHaltCompiler{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $4), + }, + HaltCompilerTkn: $1, + OpenParenthesisTkn: $2, + CloseParenthesisTkn: $3, + SemiColonTkn: $4, + } } | T_NAMESPACE namespace_name ';' { @@ -799,14 +800,15 @@ inner_statement: } | T_HALT_COMPILER '(' ')' ';' { - $$ = &ast.StmtHaltCompiler{ast.Node{}} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($2.SkippedTokens, append($3.SkippedTokens, $4.SkippedTokens...)...)) + $$ = &ast.StmtHaltCompiler{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $4), + }, + HaltCompilerTkn: $1, + OpenParenthesisTkn: $2, + CloseParenthesisTkn: $3, + SemiColonTkn: $4, + } } ; diff --git a/internal/php7/php7.go b/internal/php7/php7.go index e818e2c..f9ec7d4 100644 Binary files a/internal/php7/php7.go and b/internal/php7/php7.go differ diff --git a/internal/php7/php7.y b/internal/php7/php7.y index 33c558c..3013dfd 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -434,14 +434,15 @@ top_statement: } | T_HALT_COMPILER '(' ')' ';' { - $$ = &ast.StmtHaltCompiler{ast.Node{}} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($2.SkippedTokens, append($3.SkippedTokens, $4.SkippedTokens...)...)) + $$ = &ast.StmtHaltCompiler{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $4), + }, + HaltCompilerTkn: $1, + OpenParenthesisTkn: $2, + CloseParenthesisTkn: $3, + SemiColonTkn: $4, + } } | T_NAMESPACE namespace_name ';' { @@ -838,14 +839,15 @@ inner_statement: } | T_HALT_COMPILER '(' ')' ';' { - $$ = &ast.StmtHaltCompiler{ast.Node{}} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($2.SkippedTokens, append($3.SkippedTokens, $4.SkippedTokens...)...)) + $$ = &ast.StmtHaltCompiler{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $4), + }, + HaltCompilerTkn: $1, + OpenParenthesisTkn: $2, + CloseParenthesisTkn: $3, + SemiColonTkn: $4, + } } statement: diff --git a/pkg/ast/node.go b/pkg/ast/node.go index d64da63..4b633fe 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -539,6 +539,10 @@ func (n *StmtGoto) Accept(v NodeVisitor) { // StmtHaltCompiler node type StmtHaltCompiler struct { Node + HaltCompilerTkn *token.Token + OpenParenthesisTkn *token.Token + CloseParenthesisTkn *token.Token + SemiColonTkn *token.Token } func (n *StmtHaltCompiler) Accept(v NodeVisitor) { diff --git a/pkg/ast/visitor/filter_tokens.go b/pkg/ast/visitor/filter_tokens.go index adba189..ff7f336 100644 --- a/pkg/ast/visitor/filter_tokens.go +++ b/pkg/ast/visitor/filter_tokens.go @@ -60,3 +60,10 @@ func (v *FilterTokens) StmtNamespace(n *ast.StmtNamespace) { n.CloseCurlyBracket = nil n.SemiColonTkn = nil } + +func (v *FilterTokens) StmtHaltCompiler(n *ast.StmtHaltCompiler) { + n.HaltCompilerTkn = nil + n.OpenParenthesisTkn = nil + n.CloseParenthesisTkn = nil + n.SemiColonTkn = nil +} diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 0e8a0dd..450f928 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -2823,13 +2823,11 @@ func (p *Printer) printStmtGoto(n ast.Vertex) { p.printFreeFloating(nn, token.End) } -func (p *Printer) printStmtHaltCompiler(n ast.Vertex) { - nn := n.(*ast.StmtHaltCompiler) - p.printFreeFloating(nn, token.Start) - - io.WriteString(p.w, "__halt_compiler") - - p.printFreeFloatingOrDefault(nn, token.End, "();") +func (p *Printer) printStmtHaltCompiler(n *ast.StmtHaltCompiler) { + p.printToken(n.HaltCompilerTkn, "__halt_compiler") + p.printToken(n.OpenParenthesisTkn, "(") + p.printToken(n.CloseParenthesisTkn, ")") + p.printToken(n.SemiColonTkn, ";") } func (p *Printer) printStmtIf(n ast.Vertex) { diff --git a/pkg/printer/printer_parsed_php5_test.go b/pkg/printer/printer_parsed_php5_test.go index 17cef65..a65bd6b 100644 --- a/pkg/printer/printer_parsed_php5_test.go +++ b/pkg/printer/printer_parsed_php5_test.go @@ -1049,7 +1049,8 @@ func TestParseAndPrintPhp5Goto(t *testing.T) { } func TestParseAndPrintPhp5HaltCompiler(t *testing.T) { - src := `