[refactoring] update ast structure of "Echo" node
This commit is contained in:
parent
3f12ada311
commit
7678303cb9
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -240,7 +240,7 @@ import (
|
||||
%type <node> trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias
|
||||
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
|
||||
%type <node> static_scalar_value static_operation static_var_list global_var_list
|
||||
%type <node> ctor_arguments function_call_parameter_list
|
||||
%type <node> ctor_arguments function_call_parameter_list echo_expr_list
|
||||
%type <node> trait_adaptations
|
||||
%type <node> switch_case_list
|
||||
%type <node> method_body
|
||||
@ -255,7 +255,7 @@ import (
|
||||
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
|
||||
%type <list> inner_statement_list encaps_list isset_variables non_empty_array_pair_list
|
||||
%type <list> array_pair_list assignment_list lexical_var_list elseif_list new_elseif_list non_empty_for_expr
|
||||
%type <list> for_expr case_list echo_expr_list unset_variables declare_list catch_statement additional_catches
|
||||
%type <list> for_expr case_list unset_variables declare_list catch_statement additional_catches
|
||||
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
|
||||
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration
|
||||
%type <list> interface_list non_empty_function_call_parameter_list trait_list trait_adaptation_list non_empty_trait_adaptation_list
|
||||
@ -1054,16 +1054,11 @@ unticked_statement:
|
||||
}
|
||||
| T_ECHO echo_expr_list ';'
|
||||
{
|
||||
$$ = &ast.StmtEcho{ast.Node{}, $2}
|
||||
$2.(*ast.StmtEcho).EchoTkn = $1
|
||||
$2.(*ast.StmtEcho).SemiColonTkn = $3
|
||||
$2.(*ast.StmtEcho).Node.Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.Echo, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
||||
$$ = $2
|
||||
}
|
||||
| T_INLINE_HTML
|
||||
{
|
||||
@ -2874,14 +2869,16 @@ class_constant_declaration:
|
||||
echo_expr_list:
|
||||
echo_expr_list ',' expr
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
$1.(*ast.StmtEcho).Exprs = append($1.(*ast.StmtEcho).Exprs, $3)
|
||||
$1.(*ast.StmtEcho).SeparatorTkns = append($1.(*ast.StmtEcho).SeparatorTkns, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
$$ = $1
|
||||
}
|
||||
| expr
|
||||
{
|
||||
$$ = []ast.Vertex{$1}
|
||||
$$ = &ast.StmtEcho{
|
||||
Exprs: []ast.Vertex{$1},
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@ -3335,7 +3332,6 @@ expr_without_variable:
|
||||
$$.GetNode().Position = position.NewNodesPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
|
||||
}
|
||||
| expr '+' expr
|
||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -249,7 +249,7 @@ import (
|
||||
%type <node> exit_expr scalar lexical_var function_call member_name property_name
|
||||
%type <node> variable_class_name dereferencable_scalar constant dereferencable
|
||||
%type <node> callable_expr callable_variable static_member new_variable
|
||||
%type <node> encaps_var encaps_var_offset
|
||||
%type <node> encaps_var encaps_var_offset echo_expr_list
|
||||
%type <node> if_stmt
|
||||
%type <node> alt_if_stmt
|
||||
%type <node> if_stmt_without_else
|
||||
@ -275,7 +275,7 @@ import (
|
||||
|
||||
|
||||
%type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list
|
||||
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs
|
||||
%type <list> const_list for_exprs non_empty_for_exprs
|
||||
%type <list> unprefixed_use_declarations inline_use_declarations property_list
|
||||
%type <list> case_list trait_adaptation_list unset_variables
|
||||
%type <list> use_declarations lexical_var_list isset_variables non_empty_array_pair_list
|
||||
@ -954,7 +954,6 @@ statement:
|
||||
{
|
||||
$2.(*ast.StmtGlobal).GlobalTkn = $1
|
||||
$2.(*ast.StmtGlobal).SemiColonTkn = $3
|
||||
$2.(*ast.StmtGlobal).SeparatorTkns = append($2.(*ast.StmtGlobal).SeparatorTkns, nil)
|
||||
$2.(*ast.StmtGlobal).Node.Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
$$ = $2
|
||||
@ -963,23 +962,17 @@ statement:
|
||||
{
|
||||
$2.(*ast.StmtStatic).StaticTkn = $1
|
||||
$2.(*ast.StmtStatic).SemiColonTkn = $3
|
||||
$2.(*ast.StmtStatic).SeparatorTkns = append($2.(*ast.StmtStatic).SeparatorTkns, nil)
|
||||
$2.(*ast.StmtStatic).Node.Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
$$ = $2
|
||||
}
|
||||
| T_ECHO echo_expr_list ';'
|
||||
{
|
||||
$$ = &ast.StmtEcho{ast.Node{}, $2}
|
||||
$2.(*ast.StmtEcho).EchoTkn = $1
|
||||
$2.(*ast.StmtEcho).SemiColonTkn = $3
|
||||
$2.(*ast.StmtEcho).Node.Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.Echo, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
||||
$$ = $2
|
||||
}
|
||||
| T_INLINE_HTML
|
||||
{
|
||||
@ -2629,14 +2622,16 @@ const_decl:
|
||||
echo_expr_list:
|
||||
echo_expr_list ',' echo_expr
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
$1.(*ast.StmtEcho).Exprs = append($1.(*ast.StmtEcho).Exprs, $3)
|
||||
$1.(*ast.StmtEcho).SeparatorTkns = append($1.(*ast.StmtEcho).SeparatorTkns, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
$$ = $1
|
||||
}
|
||||
| echo_expr
|
||||
{
|
||||
$$ = []ast.Vertex{$1}
|
||||
$$ = &ast.StmtEcho{
|
||||
Exprs: []ast.Vertex{$1},
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@ -3061,7 +3056,6 @@ expr_without_variable:
|
||||
$$.GetNode().Position = position.NewNodesPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
|
||||
}
|
||||
| expr '+' expr
|
||||
|
@ -58,7 +58,7 @@ func (lex *Lexer) setTokenPosition(token *token.Token) {
|
||||
}
|
||||
|
||||
func (lex *Lexer) addSkippedToken(t *token.Token, id token.ID, ps, pe int) {
|
||||
if lex.sts == 0 {
|
||||
if lex.sts == -1 {
|
||||
lex.sts = lex.ts
|
||||
}
|
||||
|
||||
|
BIN
internal/scanner/scanner.go
generated
BIN
internal/scanner/scanner.go
generated
Binary file not shown.
@ -26,7 +26,7 @@ func (lex *Lexer) Lex() *token.Token {
|
||||
|
||||
tkn := lex.tokenPool.Get()
|
||||
|
||||
lex.sts = 0
|
||||
lex.sts = -1
|
||||
lex.ste = 0
|
||||
|
||||
lblStart := 0
|
||||
@ -498,9 +498,13 @@ func (lex *Lexer) Lex() *token.Token {
|
||||
write exec;
|
||||
}%%
|
||||
|
||||
if lex.sts == -1 {
|
||||
lex.sts = 0
|
||||
}
|
||||
|
||||
tkn.Value = lex.data[lex.ts:lex.te]
|
||||
tkn.ID = token.ID(tok)
|
||||
tkn.SkippedString = lex.data[lex.sts:lex.ste]
|
||||
tkn.Skipped = lex.data[lex.sts:lex.ste]
|
||||
lex.addSkippedToken(tkn, tok, lex.ts, lex.te);
|
||||
|
||||
return tkn
|
||||
|
@ -368,7 +368,10 @@ func (n *StmtDo) Accept(v NodeVisitor) {
|
||||
// StmtEcho node
|
||||
type StmtEcho struct {
|
||||
Node
|
||||
EchoTkn *token.Token
|
||||
Exprs []Vertex
|
||||
SeparatorTkns []*token.Token
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtEcho) Accept(v NodeVisitor) {
|
||||
|
@ -194,3 +194,9 @@ func (v *FilterTokens) StmtStatic(n *ast.StmtStatic) {
|
||||
func (v *FilterTokens) StmtStaticVar(n *ast.StmtStaticVar) {
|
||||
n.EqualTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtEcho(n *ast.StmtEcho) {
|
||||
n.EchoTkn = nil
|
||||
n.SeparatorTkns = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -45,7 +45,6 @@ func TestParseAndPrintPhp5Root(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Identifier(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<? ;
|
||||
/* Foo */
|
||||
Foo ( ) ;
|
||||
@ -73,8 +72,7 @@ func TestParseAndPrintPhp5Parameter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Argument(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo ( $a , $b
|
||||
, $c
|
||||
) ; `
|
||||
@ -89,8 +87,7 @@ func TestParseAndPrintPhp5Argument(t *testing.T) {
|
||||
// test name
|
||||
|
||||
func TestParseAndPrintPhp5Names(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo ( ) ;
|
||||
\ foo ( ) ;
|
||||
namespace \ foo ( ) ;
|
||||
@ -169,8 +166,7 @@ func TestParseAndPrintPhp5String(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Heredoc(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo(<<<EAP
|
||||
test
|
||||
EAP
|
||||
@ -291,8 +287,7 @@ func TestParseAndPrintPhp5Cast(t *testing.T) {
|
||||
// test expr
|
||||
|
||||
func TestParseAndPrintPhp5ArrayDimFetch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
FOO [ ] ;
|
||||
FOO [ 1 ] ;
|
||||
$a [ ] ;
|
||||
@ -418,8 +413,7 @@ func TestParseAndPrintPhp5Closure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5ConstFetch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
null ;
|
||||
`
|
||||
|
||||
@ -485,8 +479,7 @@ func TestParseAndPrintPhp5Exit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5FunctionCall(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo ( ) ;
|
||||
$var ( $a , ... $b , $c ) ;
|
||||
`
|
||||
@ -556,8 +549,7 @@ func TestParseAndPrintPhp5MethodCall(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5New(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
new Foo ;
|
||||
|
||||
@ -670,8 +662,7 @@ func TestParseAndPrintPhp5ShortArray(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
Foo :: bar ( $a , $b ) ;`
|
||||
|
||||
actual := printPhp5(parsePhp5(src))
|
||||
@ -682,8 +673,7 @@ func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5StaticPropertyFetch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
Foo :: $bar ;`
|
||||
|
||||
actual := printPhp5(parsePhp5(src))
|
||||
@ -743,8 +733,7 @@ func TestParseAndPrintPhp5Yield(t *testing.T) {
|
||||
// test stmt
|
||||
|
||||
func TestParseAndPrintPhp5AltIf(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
if ( 1 ) :
|
||||
// do nothing
|
||||
elseif ( 2 ) :
|
||||
@ -762,8 +751,7 @@ func TestParseAndPrintPhp5AltIf(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5AltFor(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
for ( $a ; $b ; $c ) :
|
||||
endfor ;
|
||||
|
||||
@ -791,8 +779,7 @@ func TestParseAndPrintPhp5AltForeach(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5AltSwitch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
switch ( $a ) :
|
||||
case 1 :
|
||||
@ -822,8 +809,7 @@ func TestParseAndPrintPhp5AltSwitch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5AltWhile(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
while ( $a ) :
|
||||
// do nothing
|
||||
@ -837,8 +823,7 @@ func TestParseAndPrintPhp5AltWhile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Break(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
break ;
|
||||
break 1 ;
|
||||
@ -901,8 +886,7 @@ func TestParseAndPrintPhp5ClassConstList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5ConstList(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
const FOO = 1 , BAR = 2 ;
|
||||
`
|
||||
|
||||
@ -914,8 +898,7 @@ func TestParseAndPrintPhp5ConstList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Continue(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
continue ;
|
||||
continue 1 ;
|
||||
@ -949,8 +932,7 @@ func TestParseAndPrintPhp5Declare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5DoWhile(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
do {
|
||||
;
|
||||
} while ( $a ) ;
|
||||
@ -992,8 +974,7 @@ func TestParseAndPrintPhp5IfExpression(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5For(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
for ( $i = 0 ; $i < 3 ; $i ++ )
|
||||
echo $i . PHP_EOL;
|
||||
|
||||
@ -1036,8 +1017,7 @@ func TestParseAndPrintPhp5Function(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Global(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
global $a , $b ;`
|
||||
|
||||
actual := printPhp5(parsePhp5(src))
|
||||
@ -1059,8 +1039,7 @@ func TestParseAndPrintPhp5Goto(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5HaltCompiler(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
__halt_compiler ( ) ;
|
||||
this text is ignored by parser
|
||||
`
|
||||
@ -1073,8 +1052,7 @@ func TestParseAndPrintPhp5HaltCompiler(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5IfElseIfElse(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
if ( 1 ) ;
|
||||
elseif ( 2 ) {
|
||||
;
|
||||
@ -1137,8 +1115,7 @@ func TestParseAndPrintPhp5GotoLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Namespace(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
namespace Foo \ Bar ;
|
||||
namespace Baz {
|
||||
|
||||
@ -1156,7 +1133,7 @@ func TestParseAndPrintPhp5Namespace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Nop(t *testing.T) {
|
||||
src := `<?php ; `
|
||||
src := `<?php `
|
||||
|
||||
actual := printPhp5(parsePhp5(src))
|
||||
|
||||
@ -1209,8 +1186,7 @@ func TestParseAndPrintPhp5Return(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5StaticVar(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
static $a , $b = ' ' ;
|
||||
`
|
||||
|
||||
@ -1222,8 +1198,7 @@ func TestParseAndPrintPhp5StaticVar(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5StmtList(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
{
|
||||
;
|
||||
}
|
||||
@ -1237,8 +1212,7 @@ func TestParseAndPrintPhp5StmtList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Switch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
switch ( $a ) {
|
||||
case 1 : ;
|
||||
@ -1332,8 +1306,7 @@ func TestParseAndPrintPhp5Unset(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5UseList(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
use Foo ;
|
||||
use \ Foo as Bar ;
|
||||
use function \ Foo as Bar ;
|
||||
@ -1348,8 +1321,7 @@ func TestParseAndPrintPhp5UseList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5While(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
while ( $a ) echo '' ;
|
||||
while ( $a ) { }
|
||||
while ( $a ) ;
|
||||
@ -1365,8 +1337,7 @@ func TestParseAndPrintPhp5While(t *testing.T) {
|
||||
// other
|
||||
|
||||
func TestParseAndPrintPhp5Parentheses(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
global $ { $b } ;
|
||||
$b = (($a));
|
||||
$b = ( ($a) );
|
||||
|
@ -13,8 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func ExamplePrinter() {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
namespace Foo;
|
||||
|
||||
@ -38,7 +37,7 @@ abstract class Bar extends Baz
|
||||
|
||||
// change namespace
|
||||
|
||||
parts := &rootNode.(*ast.Root).Stmts[1].(*ast.StmtNamespace).Name.(*ast.NameName).Parts
|
||||
parts := &rootNode.(*ast.Root).Stmts[0].(*ast.StmtNamespace).Name.(*ast.NameName).Parts
|
||||
*parts = append(*parts, &ast.NameNamePart{Value: []byte("Quuz")})
|
||||
|
||||
// print
|
||||
@ -47,7 +46,7 @@ abstract class Bar extends Baz
|
||||
p.Print(rootNode)
|
||||
|
||||
// Output:
|
||||
//<?php ;
|
||||
//<?php
|
||||
//
|
||||
// namespace Foo\Quuz;
|
||||
//
|
||||
@ -95,7 +94,6 @@ func TestParseAndPrintRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintIdentifier(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<? ;
|
||||
/* Foo */
|
||||
Foo ( ) ;
|
||||
@ -152,8 +150,7 @@ func TestParseAndPrintNullable(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintArgument(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo ( $a , $b
|
||||
, ... $c ,
|
||||
) ; `
|
||||
@ -168,8 +165,7 @@ func TestParseAndPrintArgument(t *testing.T) {
|
||||
// test name
|
||||
|
||||
func TestParseAndPrintNames(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo ( ) ;
|
||||
\ foo ( ) ;
|
||||
namespace \ foo ( ) ;
|
||||
@ -248,8 +244,7 @@ func TestParseAndPrintString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintHeredoc(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo(<<<EAP
|
||||
test
|
||||
EAP
|
||||
@ -373,8 +368,7 @@ func TestParseAndPrintCast(t *testing.T) {
|
||||
// test expr
|
||||
|
||||
func TestParseAndPrintArrayDimFetch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
FOO [ ] ;
|
||||
FOO [ 1 ] ;
|
||||
$a [ ] ;
|
||||
@ -513,8 +507,7 @@ func TestParseAndPrintArrowFunction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintConstFetch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
null ;
|
||||
`
|
||||
|
||||
@ -580,8 +573,7 @@ func TestParseAndPrintExit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintFunctionCall(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
foo ( ) ;
|
||||
$var ( $a , ... $b , $c ) ;
|
||||
`
|
||||
@ -782,8 +774,7 @@ func TestParseAndPrintShortList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintStaticCall(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
Foo :: bar ( $a , $b ) ;`
|
||||
|
||||
actual := print(parse(src))
|
||||
@ -794,8 +785,7 @@ func TestParseAndPrintStaticCall(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintStaticPropertyFetch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
Foo :: $bar ;`
|
||||
|
||||
actual := print(parse(src))
|
||||
@ -856,8 +846,7 @@ func TestParseAndPrintYield(t *testing.T) {
|
||||
// test stmt
|
||||
|
||||
func TestParseAndPrintAltIf(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
if ( 1 ) :
|
||||
// do nothing
|
||||
elseif ( 2 ) :
|
||||
@ -875,8 +864,7 @@ func TestParseAndPrintAltIf(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintAltFor(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
for ( $a ; $b ; $c ) :
|
||||
endfor ;
|
||||
|
||||
@ -904,8 +892,7 @@ func TestParseAndPrintAltForeach(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintAltSwitch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
switch ( $a ) :
|
||||
case 1 :
|
||||
@ -935,8 +922,7 @@ func TestParseAndPrintAltSwitch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintAltWhile(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
while ( $a ) :
|
||||
// do nothing
|
||||
@ -950,8 +936,7 @@ func TestParseAndPrintAltWhile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintBreak(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
break ;
|
||||
break 1 ;
|
||||
@ -1017,8 +1002,7 @@ func TestParseAndPrintClassConstList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintConstList(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
const FOO = 1 , BAR = 2 ;
|
||||
`
|
||||
|
||||
@ -1030,8 +1014,7 @@ func TestParseAndPrintConstList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintContinue(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
continue ;
|
||||
continue 1 ;
|
||||
@ -1065,8 +1048,7 @@ func TestParseAndPrintDeclare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintDoWhile(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
do {
|
||||
;
|
||||
} while ( $a ) ;
|
||||
@ -1110,8 +1092,7 @@ func TestParseAndPrintIfExpression(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintFor(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
for ( $i = 0 ; $i < 3 ; $i ++ )
|
||||
echo $i . PHP_EOL;
|
||||
|
||||
@ -1154,8 +1135,7 @@ func TestParseAndPrintFunction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintGlobal(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
global $a , $b ;`
|
||||
|
||||
actual := print(parse(src))
|
||||
@ -1177,8 +1157,7 @@ func TestParseAndPrintGoto(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintGroupUse(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
use function Foo \ { Bar as Baz , Quuz , } ;
|
||||
use Foo \ { function Bar as Baz , const Quuz } ;
|
||||
use \ Foo \ { function Bar as Baz , const Quuz , } ;
|
||||
@ -1192,8 +1171,7 @@ func TestParseAndPrintGroupUse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintHaltCompiler(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
__halt_compiler ( ) ;
|
||||
this text is ignored by parser
|
||||
`
|
||||
@ -1206,8 +1184,7 @@ func TestParseAndPrintHaltCompiler(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintIfElseIfElse(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
if ( 1 ) ;
|
||||
elseif ( 2 ) {
|
||||
;
|
||||
@ -1270,8 +1247,7 @@ func TestParseAndPrintGotoLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintNamespace(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
namespace Foo \ Bar ;
|
||||
namespace Baz {
|
||||
|
||||
@ -1289,7 +1265,7 @@ func TestParseAndPrintNamespace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintNop(t *testing.T) {
|
||||
src := `<?php ; `
|
||||
src := `<?php `
|
||||
|
||||
actual := print(parse(src))
|
||||
|
||||
@ -1342,8 +1318,7 @@ func TestParseAndPrintReturn(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintStaticVar(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
static $a , $b = foo ( ) ;
|
||||
`
|
||||
|
||||
@ -1355,8 +1330,7 @@ func TestParseAndPrintStaticVar(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintStmtList(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
{
|
||||
;
|
||||
}
|
||||
@ -1370,8 +1344,7 @@ func TestParseAndPrintStmtList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintSwitch(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
|
||||
switch ( $a ) {
|
||||
case 1 : ;
|
||||
@ -1465,8 +1438,7 @@ func TestParseAndPrintUnset(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintUseList(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
use Foo ;
|
||||
use \ Foo as Bar ;
|
||||
use function \ Foo as Bar ;
|
||||
@ -1481,8 +1453,7 @@ func TestParseAndPrintUseList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintWhile(t *testing.T) {
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
src := `<?php
|
||||
while ( $a ) echo '' ;
|
||||
while ( $a ) { }
|
||||
while ( $a ) ;
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/pkg/ast"
|
||||
"github.com/z7zmey/php-parser/pkg/token"
|
||||
|
||||
"github.com/z7zmey/php-parser/pkg/printer"
|
||||
)
|
||||
|
||||
@ -71,45 +69,25 @@ func TestPrinterPrintFileInlineHtml(t *testing.T) {
|
||||
p.Print(&ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtInlineHtml{Value: []byte("<div>HTML</div>")},
|
||||
&ast.StmtExpression{
|
||||
Expr: &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Tokens: token.Collection{
|
||||
token.Start: []*token.Token{
|
||||
{
|
||||
ID: token.ID('$'),
|
||||
Value: []byte("$"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Value: []byte("a"),
|
||||
&ast.StmtEcho{
|
||||
Exprs: []ast.Vertex{
|
||||
&ast.ScalarString{
|
||||
Value: []byte(`"a"`),
|
||||
},
|
||||
},
|
||||
},
|
||||
&ast.StmtInlineHtml{Value: []byte("<div>HTML</div>")},
|
||||
&ast.StmtExpression{
|
||||
Expr: &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Tokens: token.Collection{
|
||||
token.Start: []*token.Token{
|
||||
{
|
||||
ID: token.ID('$'),
|
||||
Value: []byte("$"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Value: []byte("a"),
|
||||
&ast.StmtEcho{
|
||||
Exprs: []ast.Vertex{
|
||||
&ast.ScalarString{
|
||||
Value: []byte(`"b"`),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := `<div>HTML</div><?php $a;?><div>HTML</div><?php $a;`
|
||||
expected := `<div>HTML</div><?php echo "a";?><div>HTML</div><?php echo "b";`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
|
Loading…
Reference in New Issue
Block a user