[refactoring] update ast structure for "Use" and "GroupUse" nodes

This commit is contained in:
Vadym Slizov 2020-08-22 16:59:26 +03:00
parent 97747c5ac0
commit 767187ff85
23 changed files with 2761 additions and 3639 deletions

View File

@ -11677,15 +11677,6 @@ func TestStmtUse(t *testing.T) {
EndPos: 11,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 10,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -11723,7 +11714,6 @@ func TestStmtUse(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -11757,15 +11747,6 @@ func TestStmtUse_FullyQualified(t *testing.T) {
EndPos: 12,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 11,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -11803,7 +11784,6 @@ func TestStmtUse_FullyQualified(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -11837,15 +11817,6 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) {
EndPos: 19,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 18,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -11894,7 +11865,6 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -11928,15 +11898,6 @@ func TestStmtUse_List(t *testing.T) {
EndPos: 16,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 15,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12007,7 +11968,6 @@ func TestStmtUse_List(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -12041,15 +12001,6 @@ func TestStmtUse_ListAlias(t *testing.T) {
EndPos: 23,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 22,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12131,7 +12082,6 @@ func TestStmtUse_ListAlias(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -12165,15 +12115,6 @@ func TestStmtUse_ListFunctionType(t *testing.T) {
EndPos: 26,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 25,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -12185,15 +12126,6 @@ func TestStmtUse_ListFunctionType(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 25,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12264,8 +12196,6 @@ func TestStmtUse_ListFunctionType(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -12299,15 +12229,6 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) {
EndPos: 40,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 39,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -12319,15 +12240,6 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 39,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12420,8 +12332,6 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -12455,16 +12365,6 @@ func TestStmtUse_ListConstType(t *testing.T) {
EndPos: 23,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 22,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -12476,15 +12376,6 @@ func TestStmtUse_ListConstType(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 22,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12555,8 +12446,6 @@ func TestStmtUse_ListConstType(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
@ -12590,15 +12479,6 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) {
EndPos: 37,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 36,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -12610,15 +12490,6 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 36,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12711,8 +12582,6 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "5.6", nil)

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -395,52 +395,48 @@ top_statement:
}
| T_USE use_declarations ';'
{
useList := &ast.StmtUseList{ast.Node{}, $2}
$$ = &ast.StmtUse{ast.Node{}, useList}
// save position
useList.GetNode().Position = position.NewNodeListPosition($2)
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
$$ = &ast.StmtUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
UseTkn: $1,
UseDeclarations: $2,
SemiColonTkn: $3,
}
}
| T_USE T_FUNCTION use_function_declarations ';'
{
identifier := &ast.Identifier{ast.Node{}, $2.Value}
useList := &ast.StmtUseList{ast.Node{}, $3}
useType := &ast.StmtUseType{ast.Node{}, identifier, useList}
$$ = &ast.StmtUse{ast.Node{}, useType}
// save position
identifier.GetNode().Position = position.NewTokenPosition($2)
useList.GetNode().Position = position.NewNodeListPosition($3)
useType.GetNode().Position = position.NewTokenNodePosition($2, useList)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating(identifier, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.SkippedTokens)
$$ = &ast.StmtUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
UseTkn: $1,
Type: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
Value: $2.Value,
},
UseDeclarations: $3,
SemiColonTkn: $4,
}
}
| T_USE T_CONST use_const_declarations ';'
{
identifier := &ast.Identifier{ast.Node{}, $2.Value}
useList := &ast.StmtUseList{ast.Node{}, $3}
useType := &ast.StmtUseType{ast.Node{}, identifier, useList}
$$ = &ast.StmtUse{ast.Node{}, useType}
// save position
identifier.GetNode().Position = position.NewTokenPosition($2)
useList.GetNode().Position = position.NewNodeListPosition($3)
useType.GetNode().Position = position.NewTokenNodePosition($2, useList)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating(identifier, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.SkippedTokens)
$$ = &ast.StmtUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
UseTkn: $1,
Type: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
Value: $2.Value,
},
UseDeclarations: $3,
SemiColonTkn: $4,
}
}
| constant_declaration ';'
{
@ -458,10 +454,9 @@ top_statement:
use_declarations:
use_declarations ',' use_declaration
{
$$ = append($1, $3)
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = append($1, $3)
}
| use_declaration
{
@ -472,73 +467,84 @@ use_declarations:
use_declaration:
namespace_name
{
name := &ast.NameName{ast.Node{}, $1}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
$$.GetNode().Position = position.NewNodeListPosition($1)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
}
}
| namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $1}
alias := &ast.Identifier{ast.Node{}, $3.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, asAlias}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
alias.GetNode().Position = position.NewTokenPosition($3)
asAlias.GetNode().Position = position.NewTokensPosition($2, $3)
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $3.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
AsTkn: $2,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
Value: $3.Value,
},
}
}
| T_NS_SEPARATOR namespace_name
{
name := &ast.NameName{ast.Node{}, $2}
useDeclaration := &ast.StmtUseDeclaration{ast.Node{}, name, nil}
$$ = &ast.ParserNsSeparator{ast.Node{}, useDeclaration}
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
useDeclaration.GetNode().Position = position.NewTokenNodePosition($1, name)
$$.GetNode().Position = position.NewTokenNodePosition($1, name)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2),
},
NsSeparatorTkn: $1,
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
}
}
| T_NS_SEPARATOR namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $2}
alias := &ast.Identifier{ast.Node{}, $4.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
useDeclaration := &ast.StmtUseDeclaration{ast.Node{}, name, alias}
$$ = &ast.ParserNsSeparator{ast.Node{}, useDeclaration}
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
alias.GetNode().Position = position.NewTokenPosition($4)
asAlias.GetNode().Position = position.NewTokensPosition($3, $4)
useDeclaration.GetNode().Position = position.NewTokensPosition($1, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $4.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
NsSeparatorTkn: $1,
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
AsTkn: $3,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
Value: $4.Value,
},
}
}
;
use_function_declarations:
use_function_declarations ',' use_function_declaration
{
$$ = append($1, $3)
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = append($1, $3)
}
| use_function_declaration
{
@ -549,73 +555,84 @@ use_function_declarations:
use_function_declaration:
namespace_name
{
name := &ast.NameName{ast.Node{}, $1}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
$$.GetNode().Position = position.NewNodeListPosition($1)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
}
}
| namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $1}
alias := &ast.Identifier{ast.Node{}, $3.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, asAlias}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
alias.GetNode().Position = position.NewTokenPosition($3)
asAlias.GetNode().Position = position.NewTokensPosition($2, $3)
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $3.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
AsTkn: $2,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
Value: $3.Value,
},
}
}
| T_NS_SEPARATOR namespace_name
{
name := &ast.NameName{ast.Node{}, $2}
useDeclaration := &ast.StmtUseDeclaration{ast.Node{}, name, nil}
$$ = &ast.ParserNsSeparator{ast.Node{}, useDeclaration}
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
useDeclaration.GetNode().Position = position.NewTokenNodePosition($1, name)
$$.GetNode().Position = position.NewTokenNodePosition($1, name)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2),
},
NsSeparatorTkn: $1,
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
}
}
| T_NS_SEPARATOR namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $2}
alias := &ast.Identifier{ast.Node{}, $4.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
useDeclaration := &ast.StmtUseDeclaration{ast.Node{}, name, alias}
$$ = &ast.ParserNsSeparator{ast.Node{}, useDeclaration}
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
alias.GetNode().Position = position.NewTokenPosition($4)
asAlias.GetNode().Position = position.NewTokensPosition($3, $4)
useDeclaration.GetNode().Position = position.NewTokensPosition($1, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $4.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
NsSeparatorTkn: $1,
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
AsTkn: $3,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
Value: $4.Value,
},
}
}
;
use_const_declarations:
use_const_declarations ',' use_const_declaration
{
$$ = append($1, $3)
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = append($1, $3)
}
| use_const_declaration
{
@ -626,63 +643,75 @@ use_const_declarations:
use_const_declaration:
namespace_name
{
name := &ast.NameName{ast.Node{}, $1}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
$$.GetNode().Position = position.NewNodeListPosition($1)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
}
}
| namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $1}
alias := &ast.Identifier{ast.Node{}, $3.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, asAlias}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
alias.GetNode().Position = position.NewTokenPosition($3)
asAlias.GetNode().Position = position.NewTokensPosition($2, $3)
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $3.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
AsTkn: $2,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
Value: $3.Value,
},
}
}
| T_NS_SEPARATOR namespace_name
{
name := &ast.NameName{ast.Node{}, $2}
useDeclaration := &ast.StmtUseDeclaration{ast.Node{}, name, nil}
$$ = &ast.ParserNsSeparator{ast.Node{}, useDeclaration}
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
useDeclaration.GetNode().Position = position.NewTokenNodePosition($1, name)
$$.GetNode().Position = position.NewTokenNodePosition($1, name)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2),
},
NsSeparatorTkn: $1,
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
}
}
| T_NS_SEPARATOR namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $2}
alias := &ast.Identifier{ast.Node{}, $4.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
useDeclaration := &ast.StmtUseDeclaration{ast.Node{}, name, alias}
$$ = &ast.ParserNsSeparator{ast.Node{}, useDeclaration}
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
alias.GetNode().Position = position.NewTokenPosition($4)
asAlias.GetNode().Position = position.NewTokensPosition($3, $4)
useDeclaration.GetNode().Position = position.NewTokensPosition($1, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $4.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
NsSeparatorTkn: $1,
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
AsTkn: $3,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
Value: $4.Value,
},
}
}
;

View File

@ -8536,15 +8536,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3289,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 154,
EndLine: 154,
StartPos: 3285,
EndPos: 3288,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -8581,7 +8572,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -8591,15 +8581,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3299,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 155,
EndLine: 155,
StartPos: 3294,
EndPos: 3298,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -8636,7 +8617,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -8646,15 +8626,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3316,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 156,
EndLine: 156,
StartPos: 3304,
EndPos: 3315,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -8702,7 +8673,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -8712,15 +8682,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3330,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 157,
EndLine: 157,
StartPos: 3321,
EndPos: 3329,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -8790,7 +8751,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -8800,15 +8760,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3351,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 158,
EndLine: 158,
StartPos: 3335,
EndPos: 3350,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -8889,7 +8840,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -8899,15 +8849,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3375,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 159,
EndLine: 159,
StartPos: 3356,
EndPos: 3374,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -8919,15 +8860,6 @@ func TestPhp5(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 159,
EndLine: 159,
StartPos: 3365,
EndPos: 3374,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -8997,8 +8929,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9008,15 +8938,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3413,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 160,
EndLine: 160,
StartPos: 3380,
EndPos: 3412,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9028,15 +8949,6 @@ func TestPhp5(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 160,
EndLine: 160,
StartPos: 3389,
EndPos: 3412,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9128,8 +9040,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9139,15 +9049,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3434,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 161,
EndLine: 161,
StartPos: 3418,
EndPos: 3433,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9159,15 +9060,6 @@ func TestPhp5(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 161,
EndLine: 161,
StartPos: 3424,
EndPos: 3433,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9237,8 +9129,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9248,15 +9138,6 @@ func TestPhp5(t *testing.T) {
EndPos: 3469,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 162,
EndLine: 162,
StartPos: 3439,
EndPos: 3468,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9268,15 +9149,6 @@ func TestPhp5(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 162,
EndLine: 162,
StartPos: 3445,
EndPos: 3468,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9368,8 +9240,6 @@ func TestPhp5(t *testing.T) {
},
},
},
},
},
&ast.StmtExpression{
Node: ast.Node{
Position: &position.Position{

View File

@ -12671,15 +12671,6 @@ func TestStmtUse(t *testing.T) {
EndPos: 11,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 10,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12717,7 +12708,6 @@ func TestStmtUse(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -12751,15 +12741,6 @@ func TestStmtUse_FullyQualified(t *testing.T) {
EndPos: 12,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 11,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12797,7 +12778,6 @@ func TestStmtUse_FullyQualified(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -12831,15 +12811,6 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) {
EndPos: 19,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 18,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -12888,7 +12859,6 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -12922,15 +12892,6 @@ func TestStmtUse_List(t *testing.T) {
EndPos: 16,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 15,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13001,7 +12962,6 @@ func TestStmtUse_List(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13035,15 +12995,6 @@ func TestStmtUse_ListAlias(t *testing.T) {
EndPos: 23,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 22,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13125,7 +13076,6 @@ func TestStmtUse_ListAlias(t *testing.T) {
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13159,15 +13109,6 @@ func TestStmtUse_ListFunctionType(t *testing.T) {
EndPos: 26,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 25,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -13179,15 +13120,6 @@ func TestStmtUse_ListFunctionType(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 25,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13258,8 +13190,6 @@ func TestStmtUse_ListFunctionType(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13293,15 +13223,6 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) {
EndPos: 40,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 39,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -13313,15 +13234,6 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 39,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13414,8 +13326,6 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13449,16 +13359,6 @@ func TestStmtUse_ListConstType(t *testing.T) {
EndPos: 23,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 22,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -13470,15 +13370,6 @@ func TestStmtUse_ListConstType(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 22,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13549,8 +13440,6 @@ func TestStmtUse_ListConstType(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13584,15 +13473,6 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) {
EndPos: 37,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 36,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -13604,15 +13484,6 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 36,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13705,8 +13576,6 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13731,7 +13600,7 @@ func TestStmtUse_GroupUse(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -13740,15 +13609,6 @@ func TestStmtUse_GroupUse(t *testing.T) {
EndPos: 22,
},
},
UseList: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 21,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -13772,15 +13632,6 @@ func TestStmtUse_GroupUse(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 20,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -13851,8 +13702,6 @@ func TestStmtUse_GroupUse(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -13877,7 +13726,7 @@ func TestStmtUse_GroupUseAlias(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -13886,15 +13735,6 @@ func TestStmtUse_GroupUseAlias(t *testing.T) {
EndPos: 30,
},
},
UseList: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 29,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -13918,15 +13758,6 @@ func TestStmtUse_GroupUseAlias(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 28,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -14008,8 +13839,6 @@ func TestStmtUse_GroupUseAlias(t *testing.T) {
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -14034,7 +13863,7 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -14043,15 +13872,6 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) {
EndPos: 31,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 30,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -14063,15 +13883,6 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 30,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -14095,15 +13906,6 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 29,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -14174,9 +13976,6 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) {
},
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -14201,7 +14000,7 @@ func TestStmtUse_ConstGroupUse(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -14210,15 +14009,6 @@ func TestStmtUse_ConstGroupUse(t *testing.T) {
EndPos: 28,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 27,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -14230,15 +14020,6 @@ func TestStmtUse_ConstGroupUse(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 27,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -14262,15 +14043,6 @@ func TestStmtUse_ConstGroupUse(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 26,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -14341,9 +14113,6 @@ func TestStmtUse_ConstGroupUse(t *testing.T) {
},
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
@ -14368,7 +14137,7 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -14377,15 +14146,6 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
EndPos: 37,
},
},
UseList: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 36,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -14409,17 +14169,8 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 35,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseType{
&ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -14439,15 +14190,6 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 21,
},
},
Use: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -14472,8 +14214,7 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
},
},
},
},
&ast.StmtUseType{
&ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@ -14493,15 +14234,6 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 32,
EndPos: 35,
},
},
Use: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -14529,9 +14261,6 @@ func TestStmtUse_MixedGroupUse(t *testing.T) {
},
},
},
},
},
},
}
lexer := scanner.NewLexer([]byte(src), "7.4", nil)

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -485,55 +485,47 @@ top_statement:
}
| T_USE mixed_group_use_declaration ';'
{
$$ = &ast.StmtUse{ast.Node{}, $2}
use := $2.(*ast.StmtGroupUse)
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
use.Node.Position = position.NewTokensPosition($1, $3)
use.UseTkn = $1
use.SemiColonTkn = $3
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
$$ = $2
}
| T_USE use_type group_use_declaration ';'
{
useType := &ast.StmtUseType{ast.Node{}, $2, $3}
$$ = &ast.StmtUse{ast.Node{}, useType}
use := $3.(*ast.StmtGroupUse)
// save position
useType.GetNode().Position = position.NewNodesPosition($2, $3)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
use.Node.Position = position.NewTokensPosition($1, $4)
use.UseTkn = $1
use.Type = $2
use.SemiColonTkn = $4
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.SkippedTokens)
$$ = $3
}
| T_USE use_declarations ';'
{
useList := &ast.StmtUseList{ast.Node{}, $2}
$$ = &ast.StmtUse{ast.Node{}, useList}
// save position
useList.GetNode().Position = position.NewNodeListPosition($2)
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
$$ = &ast.StmtUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
UseTkn: $1,
UseDeclarations: $2,
SemiColonTkn: $3,
}
}
| T_USE use_type use_declarations ';'
{
useList := &ast.StmtUseList{ast.Node{}, $3}
useType := &ast.StmtUseType{ast.Node{}, $2, useList}
$$ = &ast.StmtUse{ast.Node{}, useType}
// save position
useList.GetNode().Position = position.NewNodeListPosition($3)
useType.GetNode().Position = position.NewNodesPosition($2, useList)
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.SkippedTokens)
$$ = &ast.StmtUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $4),
},
UseTkn: $1,
Type: $2,
UseDeclarations: $3,
SemiColonTkn: $4,
}
}
| T_CONST const_list ';'
{
@ -575,104 +567,90 @@ use_type:
group_use_declaration:
namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
{
name := &ast.NameName{ast.Node{}, $1}
useList := &ast.StmtUseList{ast.Node{}, $4}
useListBrackets := &ast.ParserBrackets{ast.Node{}, useList}
useListNsSeparator := &ast.ParserNsSeparator{ast.Node{}, useListBrackets}
$$ = &ast.StmtGroupUseList{ast.Node{}, name, useListNsSeparator}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
useList.GetNode().Position = position.NewNodeListPosition($4)
useListBrackets.GetNode().Position = position.NewTokensPosition($3, $6)
useListNsSeparator.GetNode().Position = position.NewTokensPosition($2, $6)
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $6)
// save comments
if $5 != nil {
yylex.(*Parser).setFreeFloatingTokens(useList, token.End, $5.SkippedTokens)
if len($4) > 0 {
$4[len($4)-1].(*ast.StmtUseDeclaration).CommaTkn = $5
}
$$ = &ast.StmtGroupUse{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $6),
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
NsSeparatorTkn: $2,
OpenCurlyBracketTkn: $3,
UseDeclarations: $4,
CloseCurlyBracketTkn: $6,
}
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.End, $6.SkippedTokens)
yylex.(*Parser).setFreeFloating(useListNsSeparator, token.Start, $2.SkippedTokens)
}
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
{
name := &ast.NameName{ast.Node{}, $2}
prefixNsSeparator := &ast.ParserNsSeparator{ast.Node{}, name}
useList := &ast.StmtUseList{ast.Node{}, $5}
useListBrackets := &ast.ParserBrackets{ast.Node{}, useList}
useListNsSeparator := &ast.ParserNsSeparator{ast.Node{}, useListBrackets}
$$ = &ast.StmtGroupUseList{ast.Node{}, prefixNsSeparator, useListNsSeparator}
$5[len($5)-1].(*ast.StmtUseDeclaration).CommaTkn = $6
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
prefixNsSeparator.GetNode().Position = position.NewTokenNodePosition($1, name)
useList.GetNode().Position = position.NewNodeListPosition($5)
useListBrackets.GetNode().Position = position.NewTokensPosition($4, $7)
useListNsSeparator.GetNode().Position = position.NewTokensPosition($3, $7)
$$.GetNode().Position = position.NewTokensPosition($1, $7)
// save comments
yylex.(*Parser).setFreeFloating(prefixNsSeparator, token.Start, $1.SkippedTokens)
if $6 != nil {
yylex.(*Parser).setFreeFloatingTokens(useList, token.End, $6.SkippedTokens)
$$ = &ast.StmtGroupUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $7),
},
LeadingNsSeparatorTkn: $1,
Prefix: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
NsSeparatorTkn: $3,
OpenCurlyBracketTkn: $4,
UseDeclarations: $5,
CloseCurlyBracketTkn: $7,
}
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.Start, $4.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.End, $7.SkippedTokens)
yylex.(*Parser).setFreeFloating(useListNsSeparator, token.Start, $3.SkippedTokens)
}
;
mixed_group_use_declaration:
namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
{
name := &ast.NameName{ast.Node{}, $1}
useList := &ast.StmtUseList{ast.Node{}, $4}
useListBrackets := &ast.ParserBrackets{ast.Node{}, useList}
useListNsSeparator := &ast.ParserNsSeparator{ast.Node{}, useListBrackets}
$$ = &ast.StmtGroupUseList{ast.Node{}, name, useListNsSeparator}
$4[len($4)-1].(*ast.StmtUseDeclaration).CommaTkn = $5
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
useList.GetNode().Position = position.NewNodeListPosition($4)
useListBrackets.GetNode().Position = position.NewTokensPosition($3, $6)
useListNsSeparator.GetNode().Position = position.NewTokensPosition($2, $6)
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $6)
// save comments
if $5 != nil {
yylex.(*Parser).setFreeFloatingTokens(useList, token.End, $5.SkippedTokens)
$$ = &ast.StmtGroupUse{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $6),
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
NsSeparatorTkn: $2,
OpenCurlyBracketTkn: $3,
UseDeclarations: $4,
CloseCurlyBracketTkn: $6,
}
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.Start, $3.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.End, $6.SkippedTokens)
yylex.(*Parser).setFreeFloating(useListNsSeparator, token.Start, $2.SkippedTokens)
}
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
{
name := &ast.NameName{ast.Node{}, $2}
prefixNsSeparator := &ast.ParserNsSeparator{ast.Node{}, name}
useList := &ast.StmtUseList{ast.Node{}, $5}
useListBrackets := &ast.ParserBrackets{ast.Node{}, useList}
useListNsSeparator := &ast.ParserNsSeparator{ast.Node{}, useListBrackets}
$$ = &ast.StmtGroupUseList{ast.Node{}, prefixNsSeparator, useListNsSeparator}
$5[len($5)-1].(*ast.StmtUseDeclaration).CommaTkn = $6
// save position
name.GetNode().Position = position.NewNodeListPosition($2)
prefixNsSeparator.GetNode().Position = position.NewTokenNodePosition($1, name)
useList.GetNode().Position = position.NewNodeListPosition($5)
useListBrackets.GetNode().Position = position.NewTokensPosition($4, $7)
useListNsSeparator.GetNode().Position = position.NewTokensPosition($3, $7)
$$.GetNode().Position = position.NewTokensPosition($1, $7)
// save comments
yylex.(*Parser).setFreeFloating(prefixNsSeparator, token.Start, $1.SkippedTokens)
if $6 != nil {
yylex.(*Parser).setFreeFloatingTokens(useList, token.End, $6.SkippedTokens)
$$ = &ast.StmtGroupUse{
Node: ast.Node{
Position: position.NewTokensPosition($1, $7),
},
LeadingNsSeparatorTkn: $1,
Prefix: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Parts: $2,
},
NsSeparatorTkn: $3,
OpenCurlyBracketTkn: $4,
UseDeclarations: $5,
CloseCurlyBracketTkn: $7,
}
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.Start, $4.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(useListBrackets, token.End, $7.SkippedTokens)
yylex.(*Parser).setFreeFloating(useListNsSeparator, token.Start, $3.SkippedTokens)
}
;
@ -690,10 +668,9 @@ possible_comma:
inline_use_declarations:
inline_use_declarations ',' inline_use_declaration
{
$$ = append($1, $3)
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = append($1, $3)
}
| inline_use_declaration
{
@ -704,10 +681,9 @@ inline_use_declarations:
unprefixed_use_declarations:
unprefixed_use_declarations ',' unprefixed_use_declaration
{
$$ = append($1, $3)
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = append($1, $3)
}
| unprefixed_use_declaration
{
@ -718,10 +694,9 @@ unprefixed_use_declarations:
use_declarations:
use_declarations ',' use_declaration
{
$$ = append($1, $3)
$1[len($1)-1].(*ast.StmtUseDeclaration).CommaTkn = $2
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = append($1, $3)
}
| use_declaration
{
@ -736,39 +711,49 @@ inline_use_declaration:
}
| use_type unprefixed_use_declaration
{
$$ = &ast.StmtUseType{ast.Node{}, $1, $2}
decl := $2.(*ast.StmtUseDeclaration)
decl.Type = $1
decl.Node.Position = position.NewNodesPosition($1, $2)
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $2)
$$ = $2
}
;
unprefixed_use_declaration:
namespace_name
{
name := &ast.NameName{ast.Node{}, $1}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
$$.GetNode().Position = position.NewNodePosition(name)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
}
}
| namespace_name T_AS T_STRING
{
name := &ast.NameName{ast.Node{}, $1}
alias := &ast.Identifier{ast.Node{}, $3.Value}
asAlias := &ast.ParserAs{ast.Node{}, alias}
$$ = &ast.StmtUseDeclaration{ast.Node{}, name, asAlias}
// save position
name.GetNode().Position = position.NewNodeListPosition($1)
alias.GetNode().Position = position.NewTokenPosition($3)
asAlias.GetNode().Position = position.NewTokensPosition($2, $3)
$$.GetNode().Position = position.NewNodeListTokenPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating(asAlias, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating(alias, token.Start, $3.SkippedTokens)
$$ = &ast.StmtUseDeclaration{
Node: ast.Node{
Position: position.NewNodeListTokenPosition($1, $3),
},
Use: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
AsTkn: $2,
Alias: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
Value: $3.Value,
},
}
}
;
@ -779,14 +764,11 @@ use_declaration:
}
| T_NS_SEPARATOR unprefixed_use_declaration
{
$$ = &ast.ParserNsSeparator{ast.Node{}, $2}
decl := $2.(*ast.StmtUseDeclaration)
decl.NsSeparatorTkn = $1
decl.Node.Position = position.NewTokenNodePosition($1, $2)
// save position
$2.GetNode().Position = position.NewTokenNodePosition($1, $2)
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = $2
}
;

View File

@ -9024,15 +9024,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3370,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 161,
EndLine: 161,
StartPos: 3366,
EndPos: 3369,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9069,7 +9060,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9079,15 +9069,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3380,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 162,
EndLine: 162,
StartPos: 3375,
EndPos: 3379,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9124,7 +9105,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9134,15 +9114,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3397,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 163,
EndLine: 163,
StartPos: 3385,
EndPos: 3396,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9190,7 +9161,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9200,15 +9170,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3411,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 164,
EndLine: 164,
StartPos: 3402,
EndPos: 3410,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9278,7 +9239,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9288,15 +9248,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3432,
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 165,
EndLine: 165,
StartPos: 3416,
EndPos: 3431,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9377,7 +9328,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9387,15 +9337,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3456,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 166,
EndLine: 166,
StartPos: 3437,
EndPos: 3455,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9407,15 +9348,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 166,
EndLine: 166,
StartPos: 3446,
EndPos: 3455,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9485,8 +9417,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9496,15 +9426,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3494,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 167,
EndLine: 167,
StartPos: 3461,
EndPos: 3493,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9516,15 +9437,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 167,
EndLine: 167,
StartPos: 3470,
EndPos: 3493,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9616,8 +9528,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9627,15 +9537,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3515,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 168,
EndLine: 168,
StartPos: 3499,
EndPos: 3514,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9647,15 +9548,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 168,
EndLine: 168,
StartPos: 3505,
EndPos: 3514,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9725,8 +9617,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
Node: ast.Node{
Position: &position.Position{
@ -9736,15 +9626,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3550,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 169,
EndLine: 169,
StartPos: 3520,
EndPos: 3549,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -9756,15 +9637,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 169,
EndLine: 169,
StartPos: 3526,
EndPos: 3549,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9856,9 +9728,7 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 171,
@ -9867,15 +9737,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3572,
},
},
UseList: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 171,
EndLine: 171,
StartPos: 3556,
EndPos: 3571,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -9899,15 +9760,6 @@ func TestPhp7(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 171,
EndLine: 171,
StartPos: 3562,
EndPos: 3570,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -9977,9 +9829,7 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 172,
@ -9988,15 +9838,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3600,
},
},
UseList: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 172,
EndLine: 172,
StartPos: 3577,
EndPos: 3599,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -10020,15 +9861,6 @@ func TestPhp7(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 172,
EndLine: 172,
StartPos: 3582,
EndPos: 3598,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -10109,9 +9941,7 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 173,
@ -10120,15 +9950,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3629,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 173,
EndLine: 173,
StartPos: 3605,
EndPos: 3628,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -10140,15 +9961,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 173,
EndLine: 173,
StartPos: 3614,
EndPos: 3628,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -10172,15 +9984,6 @@ func TestPhp7(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 173,
EndLine: 173,
StartPos: 3619,
EndPos: 3627,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -10250,10 +10053,7 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
},
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 174,
@ -10262,15 +10062,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3656,
},
},
UseList: &ast.StmtUseType{
Node: ast.Node{
Position: &position.Position{
StartLine: 174,
EndLine: 174,
StartPos: 3634,
EndPos: 3655,
},
},
Type: &ast.Identifier{
Node: ast.Node{
Position: &position.Position{
@ -10282,15 +10073,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 174,
EndLine: 174,
StartPos: 3640,
EndPos: 3655,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -10314,15 +10096,6 @@ func TestPhp7(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 174,
EndLine: 174,
StartPos: 3646,
EndPos: 3654,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Node: ast.Node{
@ -10392,10 +10165,7 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
},
&ast.StmtUse{
&ast.StmtGroupUse{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
@ -10404,15 +10174,6 @@ func TestPhp7(t *testing.T) {
EndPos: 3691,
},
},
UseList: &ast.StmtGroupUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
EndLine: 175,
StartPos: 3661,
EndPos: 3690,
},
},
Prefix: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -10436,17 +10197,8 @@ func TestPhp7(t *testing.T) {
},
},
},
UseList: &ast.StmtUseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
EndLine: 175,
StartPos: 3666,
EndPos: 3689,
},
},
UseDeclarations: []ast.Vertex{
&ast.StmtUseType{
&ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
@ -10466,15 +10218,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("const"),
},
Use: &ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
EndLine: 175,
StartPos: 3672,
EndPos: 3675,
},
},
Use: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -10499,8 +10242,7 @@ func TestPhp7(t *testing.T) {
},
},
},
},
&ast.StmtUseType{
&ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
@ -10520,15 +10262,6 @@ func TestPhp7(t *testing.T) {
},
Value: []byte("function"),
},
Use: &ast.StmtUseDeclaration{
Node: ast.Node{
Position: &position.Position{
StartLine: 175,
EndLine: 175,
StartPos: 3686,
EndPos: 3689,
},
},
Use: &ast.NameName{
Node: ast.Node{
Position: &position.Position{
@ -10555,9 +10288,6 @@ func TestPhp7(t *testing.T) {
},
},
},
},
},
},
&ast.StmtExpression{
Node: ast.Node{
Position: &position.Position{

View File

@ -84,10 +84,8 @@ type NodeVisitor interface {
StmtTry(n *StmtTry)
StmtUnset(n *StmtUnset)
StmtUse(n *StmtUse)
StmtGroupUseList(n *StmtGroupUseList)
StmtUseList(n *StmtUseList)
StmtGroupUse(n *StmtGroupUse)
StmtUseDeclaration(n *StmtUseDeclaration)
StmtUseType(n *StmtUseType)
StmtWhile(n *StmtWhile)
ExprArray(n *ExprArray)

View File

@ -796,56 +796,49 @@ func (n *StmtUnset) Accept(v NodeVisitor) {
// StmtUse node
type StmtUse struct {
Node
UseList Vertex
UseTkn *token.Token
Type Vertex
UseDeclarations []Vertex
SemiColonTkn *token.Token
}
func (n *StmtUse) Accept(v NodeVisitor) {
v.StmtUse(n)
}
// StmtGroupUseList node
type StmtGroupUseList struct {
// StmtGroupUse node
type StmtGroupUse struct {
Node
UseTkn *token.Token
Type Vertex
LeadingNsSeparatorTkn *token.Token
Prefix Vertex
UseList Vertex
}
func (n *StmtGroupUseList) Accept(v NodeVisitor) {
v.StmtGroupUseList(n)
}
// StmtUseList node
type StmtUseList struct {
Node
NsSeparatorTkn *token.Token
OpenCurlyBracketTkn *token.Token
UseDeclarations []Vertex
CloseCurlyBracketTkn *token.Token
SemiColonTkn *token.Token
}
func (n *StmtUseList) Accept(v NodeVisitor) {
v.StmtUseList(n)
func (n *StmtGroupUse) Accept(v NodeVisitor) {
v.StmtGroupUse(n)
}
// StmtUseDeclaration node
type StmtUseDeclaration struct {
Node
Type Vertex
NsSeparatorTkn *token.Token
Use Vertex
AsTkn *token.Token
Alias Vertex
CommaTkn *token.Token
}
func (n *StmtUseDeclaration) Accept(v NodeVisitor) {
v.StmtUseDeclaration(n)
}
// StmtUseType node
type StmtUseType struct {
Node
Type Vertex
Use Vertex
}
func (n *StmtUseType) Accept(v NodeVisitor) {
v.StmtUseType(n)
}
// StmtWhile node
type StmtWhile struct {
Node

View File

@ -1150,35 +1150,35 @@ func (t *DFS) Traverse(n ast.Vertex) {
if !t.visitor.EnterNode(nn) {
return
}
if nn.UseList != nil {
t.visitor.Enter("UseList", true)
t.Traverse(nn.UseList)
t.visitor.Leave("UseList", true)
if nn.Type != nil {
t.visitor.Enter("Type", true)
t.Traverse(nn.Type)
t.visitor.Leave("Type", true)
}
case *ast.StmtGroupUseList:
if nn.UseDeclarations != nil {
t.visitor.Enter("UseDeclarations", false)
for _, c := range nn.UseDeclarations {
t.Traverse(c)
}
t.visitor.Leave("UseDeclarations", false)
}
case *ast.StmtGroupUse:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Type != nil {
t.visitor.Enter("Type", true)
t.Traverse(nn.Type)
t.visitor.Leave("Type", true)
}
if nn.Prefix != nil {
t.visitor.Enter("Prefix", true)
t.Traverse(nn.Prefix)
t.visitor.Leave("Prefix", true)
}
if nn.UseList != nil {
t.visitor.Enter("UseList", true)
t.Traverse(nn.UseList)
t.visitor.Leave("UseList", true)
}
case *ast.StmtUseList:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.UseDeclarations != nil {
t.visitor.Enter("UseDeclarations", false)
for _, c := range nn.UseDeclarations {
@ -1187,23 +1187,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.visitor.Leave("UseDeclarations", false)
}
case *ast.StmtUseDeclaration:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Use != nil {
t.visitor.Enter("Use", true)
t.Traverse(nn.Use)
t.visitor.Leave("Use", true)
}
if nn.Alias != nil {
t.visitor.Enter("Alias", true)
t.Traverse(nn.Alias)
t.visitor.Leave("Alias", true)
}
case *ast.StmtUseType:
if nn == nil {
return
}
@ -1220,6 +1203,11 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Use)
t.visitor.Leave("Use", true)
}
if nn.Alias != nil {
t.visitor.Enter("Alias", true)
t.Traverse(nn.Alias)
t.visitor.Leave("Alias", true)
}
case *ast.StmtWhile:
if nn == nil {
return

View File

@ -169,6 +169,28 @@ func (v *Dump) printNode(n *ast.Node) {
v.print("},\n")
}
func (v *Dump) printToken(key string, t *token.Token) {
if t == nil {
return
}
v.printIndent(v.indent)
v.print(key)
v.print(": &token.Token{\n")
v.printIndent(v.indent + 1)
v.print("ID: token." + t.ID.String() + ",\n")
v.printIndent(v.indent + 1)
v.print("Value: []byte(" + strconv.Quote(string(t.Value)) + "),\n")
v.printIndent(v.indent + 1)
v.print("Skipped: []byte(" + strconv.Quote(string(t.Skipped)) + "),\n")
v.printIndent(v.indent)
v.print("},\n")
}
func (v *Dump) Root(n *ast.Root) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.Root{\n")
@ -588,30 +610,30 @@ func (v *Dump) StmtUse(n *ast.StmtUse) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtUse{\n")
v.printNode(n.GetNode())
v.printToken("UseTkn", n.UseTkn)
v.printToken("SemiColonTkn", n.SemiColonTkn)
}
func (v *Dump) StmtGroupUseList(n *ast.StmtGroupUseList) {
func (v *Dump) StmtGroupUse(n *ast.StmtGroupUse) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtGroupUseList{\n")
v.printNode(n.GetNode())
}
func (v *Dump) StmtUseList(n *ast.StmtUseList) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtUseList{\n")
v.print("&ast.StmtGroupUse{\n")
v.printNode(n.GetNode())
v.printToken("UseTkn", n.UseTkn)
v.printToken("LeadingNsSeparatorTkn", n.LeadingNsSeparatorTkn)
v.printToken("NsSeparatorTkn", n.NsSeparatorTkn)
v.printToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.printToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
v.printToken("SemiColonTkn", n.SemiColonTkn)
}
func (v *Dump) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtUseDeclaration{\n")
v.printNode(n.GetNode())
}
func (v *Dump) StmtUseType(n *ast.StmtUseType) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtUseType{\n")
v.printNode(n.GetNode())
v.printToken("NsSeparatorTkn", n.NsSeparatorTkn)
v.printToken("AsTkn", n.AsTkn)
v.printToken("CommaTkn", n.CommaTkn)
}
func (v *Dump) StmtWhile(n *ast.StmtWhile) {

View File

@ -13,34 +13,6 @@ func (v *FilterParserNodes) EnterNode(n ast.Vertex) bool {
return true
}
func (v *FilterParserNodes) StmtGroupUseList(n *ast.StmtGroupUseList) {
if nn, ok := n.Prefix.(*ast.ParserNsSeparator); ok {
n.Prefix = nn.Child
}
if nn, ok := n.UseList.(*ast.ParserNsSeparator); ok {
n.UseList = nn.Child
}
if nn, ok := n.UseList.(*ast.ParserBrackets); ok {
n.UseList = nn.Child
}
}
func (v *FilterParserNodes) StmtUseList(n *ast.StmtUseList) {
for k, v := range n.UseDeclarations {
if nn, ok := v.(*ast.ParserNsSeparator); ok {
n.UseDeclarations[k] = nn.Child
}
}
}
func (v *FilterParserNodes) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
if nn, ok := n.Alias.(*ast.ParserAs); ok {
n.Alias = nn.Child
}
}
func (v *FilterParserNodes) StmtAltIf(n *ast.StmtAltIf) {
for {
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {

View File

@ -10,5 +10,26 @@ type FilterTokens struct {
func (v *FilterTokens) EnterNode(n ast.Vertex) bool {
n.GetNode().Tokens = nil
n.Accept(v)
return true
}
func (v *FilterTokens) StmtUse(n *ast.StmtUse) {
n.UseTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtGroupUse(n *ast.StmtGroupUse) {
n.UseTkn = nil
n.LeadingNsSeparatorTkn = nil
n.NsSeparatorTkn = nil
n.OpenCurlyBracketTkn = nil
n.CloseCurlyBracketTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
n.NsSeparatorTkn = nil
n.AsTkn = nil
n.CommaTkn = nil
}

View File

@ -14,8 +14,6 @@ type NamespaceResolver struct {
ResolvedNames map[ast.Vertex]string
goDeep bool
useType string
usePrefix []ast.Vertex
}
// NewNamespaceResolver NamespaceResolver type constructor
@ -47,28 +45,28 @@ func (nsr *NamespaceResolver) StmtNamespace(n *ast.StmtNamespace) {
}
}
func (nsr *NamespaceResolver) StmtUseType(n *ast.StmtUseType) {
func (nsr *NamespaceResolver) StmtUse(n *ast.StmtUse) {
useType := ""
if n.Type != nil {
nsr.useType = string(n.Type.(*ast.Identifier).Value)
}
useType = string(n.Type.(*ast.Identifier).Value)
}
func (nsr *NamespaceResolver) StmtGroupUseList(n *ast.StmtGroupUseList) {
if n.Prefix != nil {
nsr.usePrefix = n.Prefix.(*ast.NameName).Parts
}
for _, nn := range n.UseDeclarations {
nsr.AddAlias(useType, nn, nil)
}
func (nsr *NamespaceResolver) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
useNameParts := n.Use.(*ast.NameName).Parts
var alias string
if n.Alias == nil {
alias = string(useNameParts[len(useNameParts)-1].(*ast.NameNamePart).Value)
} else {
alias = string(n.Alias.(*ast.Identifier).Value)
nsr.goDeep = false
}
nsr.Namespace.AddAlias(nsr.useType, concatNameParts(nsr.usePrefix, useNameParts), alias)
func (nsr *NamespaceResolver) StmtGroupUse(n *ast.StmtGroupUse) {
useType := ""
if n.Type != nil {
useType = string(n.Type.(*ast.Identifier).Value)
}
for _, nn := range n.UseDeclarations {
nsr.AddAlias(useType, nn, n.Prefix.(*ast.NameName).Parts)
}
nsr.goDeep = false
}
@ -215,10 +213,26 @@ func (nsr *NamespaceResolver) LeaveNode(n ast.Vertex) {
if nn.Stmts != nil {
nsr.Namespace = NewNamespace("")
}
case *ast.StmtUseType:
nsr.useType = ""
case *ast.StmtGroupUseList:
nsr.usePrefix = nil
}
}
// AddAlias adds a new alias
func (nsr *NamespaceResolver) AddAlias(useType string, nn ast.Vertex, prefix []ast.Vertex) {
switch use := nn.(type) {
case *ast.StmtUseDeclaration:
if use.Type != nil {
useType = string(use.Type.(*ast.Identifier).Value)
}
useNameParts := use.Use.(*ast.NameName).Parts
var alias string
if use.Alias == nil {
alias = string(useNameParts[len(useNameParts)-1].(*ast.NameNamePart).Value)
} else {
alias = string(use.Alias.(*ast.Identifier).Value)
}
nsr.Namespace.AddAlias(useType, concatNameParts(prefix, useNameParts), alias)
}
}

View File

@ -17,14 +17,12 @@ func TestResolveStaticCall(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
&ast.ExprStaticCall{
Class: nameBC,
Call: &ast.Identifier{Value: []byte("foo")},
@ -51,14 +49,12 @@ func TestResolveStaticPropertyFetch(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
&ast.ExprStaticPropertyFetch{
Class: nameBC,
Property: &ast.Identifier{Value: []byte("foo")},
@ -84,14 +80,12 @@ func TestResolveClassConstFetch(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
&ast.ExprClassConstFetch{
Class: nameBC,
ConstantName: &ast.Identifier{Value: []byte("FOO")},
@ -117,14 +111,12 @@ func TestResolveNew(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
&ast.ExprNew{
Class: nameBC,
ArgumentList: &ast.ArgumentList{},
@ -150,14 +142,12 @@ func TestResolveInstanceOf(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
&ast.ExprInstanceOf{
Expr: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
Class: nameBC,
@ -186,17 +176,16 @@ func TestResolveInstanceCatch(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
}, &ast.StmtUseDeclaration{
},
&ast.StmtUseDeclaration{
Use: nameDE,
Alias: &ast.Identifier{Value: []byte("F")},
},
},
},
},
&ast.StmtTry{
Stmts: []ast.Vertex{},
Catches: []ast.Vertex{
@ -232,17 +221,13 @@ func TestResolveFunctionCall(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseType{
Type: &ast.Identifier{Value: []byte("function")},
Use: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
},
&ast.ExprFunctionCall{
Function: nameB,
ArgumentList: &ast.ArgumentList{},
@ -268,17 +253,13 @@ func TestResolveConstFetch(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseType{
Type: &ast.Identifier{Value: []byte("const")},
Use: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
},
&ast.ExprConstFetch{
Const: nameB,
},
@ -305,42 +286,28 @@ func TestResolveGroupUse(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtGroupUseList{
&ast.StmtGroupUse{
Prefix: nameAB,
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseType{
&ast.StmtUseDeclaration{
Type: &ast.Identifier{Value: []byte("Function")},
Use: &ast.StmtUseDeclaration{
Use: nameF,
},
},
&ast.StmtUseType{
&ast.StmtUseDeclaration{
Type: &ast.Identifier{Value: []byte("const")},
Use: &ast.StmtUseDeclaration{
Use: nameC,
},
},
},
},
},
},
&ast.StmtUse{
UseList: &ast.StmtUseType{
Type: &ast.Identifier{Value: []byte("Function")},
Use: &ast.StmtGroupUseList{
&ast.StmtGroupUse{
Prefix: nameBD,
UseList: &ast.StmtUseList{
Type: &ast.Identifier{Value: []byte("Function")},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameE,
},
},
},
},
},
},
&ast.ExprConstFetch{
Const: nameC,
},
@ -381,14 +348,12 @@ func TestResolveTraitUse(t *testing.T) {
stxTree := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAB,
},
},
},
},
&ast.StmtTraitUse{
Traits: []ast.Vertex{
nameB,
@ -704,14 +669,12 @@ func TestResolveNamespaces(t *testing.T) {
NamespaceName: namespaceCD,
Stmts: []ast.Vertex{
&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: nameAC,
},
},
},
},
&ast.ExprStaticCall{
Class: relativeNameCE,
Call: &ast.Identifier{Value: []byte("foo")},

View File

@ -282,11 +282,7 @@ func (v *Null) StmtUse(_ *ast.StmtUse) {
// do nothing
}
func (v *Null) StmtGroupUseList(_ *ast.StmtGroupUseList) {
// do nothing
}
func (v *Null) StmtUseList(_ *ast.StmtUseList) {
func (v *Null) StmtGroupUse(_ *ast.StmtGroupUse) {
// do nothing
}
@ -294,10 +290,6 @@ func (v *Null) StmtUseDeclaration(_ *ast.StmtUseDeclaration) {
// do nothing
}
func (v *Null) StmtUseType(_ *ast.StmtUseType) {
// do nothing
}
func (v *Null) StmtWhile(_ *ast.StmtWhile) {
// do nothing
}

View File

@ -399,14 +399,10 @@ func (p *PrettyPrinter) printNode(n ast.Vertex) {
p.printStmtUnset(n)
case *ast.StmtUse:
p.printStmtUse(n)
case *ast.StmtGroupUseList:
p.printStmtGroupUseList(n)
case *ast.StmtUseList:
p.printStmtUseList(n)
case *ast.StmtGroupUse:
p.printStmtGroupUse(n)
case *ast.StmtUseDeclaration:
p.printStmtUseDeclaration(n)
case *ast.StmtUseType:
p.printStmtUseType(n)
case *ast.StmtWhile:
p.printStmtWhile(n)
}
@ -2139,30 +2135,41 @@ func (p *PrettyPrinter) printStmtUse(n ast.Vertex) {
io.WriteString(p.w, "use ")
p.Print(nn.UseList)
if nn.Type != nil {
p.Print(nn.Type)
io.WriteString(p.w, " ")
}
p.joinPrint(", ", nn.UseDeclarations)
io.WriteString(p.w, ";")
}
func (p *PrettyPrinter) printStmtGroupUseList(n ast.Vertex) {
nn := n.(*ast.StmtGroupUseList)
func (p *PrettyPrinter) printStmtGroupUse(n ast.Vertex) {
nn := n.(*ast.StmtGroupUse)
io.WriteString(p.w, "use ")
if nn.Type != nil {
p.Print(nn.Type)
io.WriteString(p.w, " ")
}
p.Print(nn.Prefix)
io.WriteString(p.w, "\\{")
p.Print(nn.UseList)
io.WriteString(p.w, "}")
}
func (p *PrettyPrinter) printStmtUseList(n ast.Vertex) {
nn := n.(*ast.StmtUseList)
p.joinPrint(", ", nn.UseDeclarations)
io.WriteString(p.w, "}")
}
func (p *PrettyPrinter) printStmtUseDeclaration(n ast.Vertex) {
nn := n.(*ast.StmtUseDeclaration)
if nn.Type != nil {
p.Print(nn.Type)
io.WriteString(p.w, " ")
}
p.Print(nn.Use)
if nn.Alias != nil {
@ -2171,15 +2178,6 @@ func (p *PrettyPrinter) printStmtUseDeclaration(n ast.Vertex) {
}
}
func (p *PrettyPrinter) printStmtUseType(n ast.Vertex) {
nn := n.(*ast.StmtUseType)
p.Print(nn.Type)
io.WriteString(p.w, " ")
p.Print(nn.Use)
}
func (p *PrettyPrinter) printStmtWhile(n ast.Vertex) {
nn := n.(*ast.StmtWhile)

View File

@ -3954,39 +3954,7 @@ func TestPrintUse(t *testing.T) {
p := printer.NewPrettyPrinter(o, " ")
p.Print(&ast.StmtUse{
UseList: &ast.StmtUseList{},
})
expected := `use ;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrintStmtGroupUseList(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrettyPrinter(o, " ")
p.Print(&ast.StmtGroupUseList{
Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
UseList: &ast.StmtUseList{},
})
expected := `Foo\{}`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrintStmtUseList(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrettyPrinter(o, " ")
p.Print(&ast.StmtUseList{
Type: &ast.Identifier{Value: []byte("function")},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
@ -3998,7 +3966,33 @@ func TestPrintStmtUseList(t *testing.T) {
},
})
expected := `Foo as Bar, Baz`
expected := `use function Foo as Bar, Baz;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrintStmtGroupUse(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrettyPrinter(o, " ")
p.Print(&ast.StmtGroupUse{
Type: &ast.Identifier{Value: []byte("function")},
Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Alias: &ast.Identifier{Value: []byte("Bar")},
},
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
},
},
})
expected := `use function Foo\{Foo as Bar, Baz}`
actual := o.String()
if expected != actual {
@ -4011,28 +4005,9 @@ func TestPrintUseDeclaration(t *testing.T) {
p := printer.NewPrettyPrinter(o, " ")
p.Print(&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Alias: &ast.Identifier{Value: []byte("Bar")},
})
expected := `Foo as Bar`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrintUseType(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrettyPrinter(o, " ")
p.Print(&ast.StmtUseType{
Type: &ast.Identifier{Value: []byte("function")},
Use: &ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Alias: &ast.Identifier{Value: []byte("Bar")},
},
})
expected := `function Foo as Bar`

View File

@ -76,6 +76,23 @@ func (p *Printer) printFreeFloatingOrDefault(n ast.Vertex, pos token.Position, d
}
}
func (p *Printer) printToken(t *token.Token, def string) {
if t != nil {
p.w.Write(t.Skipped)
p.w.Write(t.Value)
p.bufStart = ""
return
}
if def != "" {
p.w.Write([]byte(p.bufStart))
p.bufStart = ""
p.w.Write([]byte(def))
return
}
}
func (p *Printer) printFreeFloating(n ast.Vertex, pos token.Position) {
if n == nil {
return
@ -87,7 +104,7 @@ func (p *Printer) printFreeFloating(n ast.Vertex, pos token.Position) {
}
func (p *Printer) printNode(n ast.Vertex) {
switch n.(type) {
switch n := n.(type) {
// node
@ -438,14 +455,10 @@ func (p *Printer) printNode(n ast.Vertex) {
p.printStmtUnset(n)
case *ast.StmtUse:
p.printStmtUse(n)
case *ast.StmtGroupUseList:
p.printStmtGroupUseList(n)
case *ast.StmtUseList:
p.printStmtUseList(n)
case *ast.StmtGroupUse:
p.printStmtGroupUse(n)
case *ast.StmtUseDeclaration:
p.printStmtUseDeclaration(n)
case *ast.StmtUseType:
p.printStmtUseType(n)
case *ast.StmtWhile:
p.printStmtWhile(n)
case *ast.ParserAs:
@ -3260,74 +3273,66 @@ func (p *Printer) printStmtUnset(n ast.Vertex) {
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printStmtUse(n ast.Vertex) {
nn := n.(*ast.StmtUse)
p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "use")
func (p *Printer) printStmtUse(n *ast.StmtUse) {
p.printToken(n.UseTkn, "use")
p.bufStart = " "
p.Print(nn.UseList)
p.Print(n.Type)
p.printFreeFloatingOrDefault(nn, token.End, ";")
p.bufStart = " "
p.joinPrint(",", n.UseDeclarations)
p.printToken(n.SemiColonTkn, ";")
}
func (p *Printer) printStmtGroupUseList(n ast.Vertex) {
nn := n.(*ast.StmtGroupUseList)
p.printFreeFloating(nn, token.Start)
func (p *Printer) printStmtGroupUse(n *ast.StmtGroupUse) {
p.printToken(n.UseTkn, "use")
p.Print(nn.Prefix)
p.bufStart = " "
p.Print(n.Type)
if _, ok := nn.UseList.(*ast.ParserNsSeparator); !ok {
io.WriteString(p.w, "\\{")
p.bufStart = " "
p.printToken(n.LeadingNsSeparatorTkn, "")
p.Print(n.Prefix)
p.printToken(n.NsSeparatorTkn, "\\")
p.printToken(n.OpenCurlyBracketTkn, "{")
for k, v := range n.UseDeclarations {
p.Print(v)
var def string
if k != len(n.UseDeclarations)-1 {
def = ","
}
if decl, ok := v.(*ast.StmtUseDeclaration); ok {
p.printToken(decl.CommaTkn, def)
}
}
p.Print(nn.UseList)
if _, ok := nn.UseList.(*ast.ParserNsSeparator); !ok {
io.WriteString(p.w, "}")
p.printToken(n.CloseCurlyBracketTkn, "}")
p.printToken(n.SemiColonTkn, ";")
}
p.printFreeFloating(nn, token.End)
func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
p.Print(n.Type)
if n.Type != nil {
p.bufStart = " "
}
func (p *Printer) printStmtUseList(n ast.Vertex) {
nn := n.(*ast.StmtUseList)
p.printFreeFloating(nn, token.Start)
p.printToken(n.NsSeparatorTkn, "")
p.joinPrint(",", nn.UseDeclarations)
p.Print(n.Use)
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printStmtUseDeclaration(n ast.Vertex) {
nn := n.(*ast.StmtUseDeclaration)
p.printFreeFloating(nn, token.Start)
p.Print(nn.Use)
if nn.Alias != nil {
if _, ok := nn.Alias.(*ast.ParserAs); !ok {
io.WriteString(p.w, " as")
if n.Alias == nil {
return
}
p.bufStart = " "
p.Print(nn.Alias)
}
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printStmtUseType(n ast.Vertex) {
nn := n.(*ast.StmtUseType)
p.printFreeFloating(nn, token.Start)
p.Print(nn.Type)
p.printToken(n.AsTkn, "as")
p.bufStart = " "
p.Print(nn.Use)
p.printFreeFloating(nn, token.End)
p.Print(n.Alias)
}
func (p *Printer) printStmtWhile(n ast.Vertex) {

View File

@ -1308,7 +1308,8 @@ func TestParseAndPrintPhp5Unset(t *testing.T) {
}
func TestParseAndPrintPhp5UseList(t *testing.T) {
src := `<?php
// TODO: remove ; after <?php
src := `<?php ;
use Foo ;
use \ Foo as Bar ;
use function \ Foo as Bar ;

View File

@ -1159,7 +1159,8 @@ func TestParseAndPrintGoto(t *testing.T) {
}
func TestParseAndPrintGroupUse(t *testing.T) {
src := `<?php
// TODO: remove ; after <?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 , } ;
@ -1440,7 +1441,8 @@ func TestParseAndPrintUnset(t *testing.T) {
}
func TestParseAndPrintUseList(t *testing.T) {
src := `<?php
// TODO: remove ; after <?php
src := `<?php ;
use Foo ;
use \ Foo as Bar ;
use function \ Foo as Bar ;

View File

@ -4391,45 +4391,7 @@ func TestPrinterPrintUse(t *testing.T) {
p := printer.NewPrinter(o)
p.Print(&ast.StmtUse{
UseList: &ast.StmtUseList{
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
},
},
},
})
expected := `use Foo;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintStmtGroupUseList(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o)
p.Print(&ast.StmtGroupUseList{
Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
UseList: &ast.StmtUseList{},
})
expected := `Foo\{}`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintStmtUseList(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o)
p.Print(&ast.StmtUseList{
Type: &ast.Identifier{Value: []byte("function")},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
@ -4441,7 +4403,33 @@ func TestPrinterPrintStmtUseList(t *testing.T) {
},
})
expected := `Foo as Bar,Baz`
expected := `use function Foo as Bar,Baz;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintStmtGroupUse(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o)
p.Print(&ast.StmtGroupUse{
Type: &ast.Identifier{Value: []byte("function")},
Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
UseDeclarations: []ast.Vertex{
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Alias: &ast.Identifier{Value: []byte("Bar")},
},
&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
},
},
})
expected := `use function Foo\{Foo as Bar,Baz};`
actual := o.String()
if expected != actual {
@ -4454,28 +4442,9 @@ func TestPrinterPrintUseDeclaration(t *testing.T) {
p := printer.NewPrinter(o)
p.Print(&ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Alias: &ast.Identifier{Value: []byte("Bar")},
})
expected := `Foo as Bar`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintUseType(t *testing.T) {
o := bytes.NewBufferString("")
p := printer.NewPrinter(o)
p.Print(&ast.StmtUseType{
Type: &ast.Identifier{Value: []byte("function")},
Use: &ast.StmtUseDeclaration{
Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Alias: &ast.Identifier{Value: []byte("Bar")},
},
})
expected := `function Foo as Bar`