diff --git a/internal/php5/parser_test.go b/internal/php5/parser_test.go index bc6d43c..6ab5b7a 100644 --- a/internal/php5/parser_test.go +++ b/internal/php5/parser_test.go @@ -11677,17 +11677,17 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11696,27 +11696,17 @@ func TestStmtUse(t *testing.T) { EndPos: 10, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -11757,46 +11747,36 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 11, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, - StartPos: 7, + StartPos: 8, EndPos: 11, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 11, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -11837,59 +11817,49 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 18, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, - StartPos: 7, + StartPos: 8, + EndPos: 11, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 11, + }, + }, + Value: []byte("Foo"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, EndPos: 18, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 18, - }, - }, - Value: []byte("Bar"), - }, + Value: []byte("Bar"), }, }, }, @@ -11928,17 +11898,17 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11947,31 +11917,31 @@ func TestStmtUse_List(t *testing.T) { EndPos: 10, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11980,27 +11950,17 @@ func TestStmtUse_List(t *testing.T) { EndPos: 15, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, }, - Value: []byte("Bar"), }, + Value: []byte("Bar"), }, }, }, @@ -12041,17 +12001,17 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12060,73 +12020,63 @@ func TestStmtUse_ListAlias(t *testing.T) { EndPos: 10, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 22, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, + EndPos: 15, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, + }, + Value: []byte("Bar"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, EndPos: 22, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 19, - EndPos: 22, - }, - }, - Value: []byte("Baz"), - }, + Value: []byte("Baz"), }, }, }, @@ -12165,46 +12115,38 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 26, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 25, + EndPos: 15, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 15, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 25, + EndPos: 19, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12213,31 +12155,31 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 19, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 21, - EndPos: 25, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 21, + EndPos: 25, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 22, + EndPos: 25, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12246,19 +12188,7 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 25, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 22, - EndPos: 25, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -12299,46 +12229,38 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 40, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 39, + EndPos: 15, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 15, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 39, + EndPos: 26, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 26, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12347,42 +12269,42 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 19, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 26, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 28, - EndPos: 39, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 26, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 28, + EndPos: 39, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 32, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12391,33 +12313,21 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 32, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 32, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 36, - EndPos: 39, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 36, + EndPos: 39, + }, + }, + Value: []byte("bar"), + }, }, }, }, @@ -12455,47 +12365,38 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 23, }, }, - - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 22, + EndPos: 12, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 12, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 22, + EndPos: 16, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12504,31 +12405,31 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 16, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 22, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 22, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 22, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12537,19 +12438,7 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 22, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 19, - EndPos: 22, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -12590,46 +12479,38 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 37, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 36, + EndPos: 12, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 12, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 36, + EndPos: 23, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 23, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12638,42 +12519,42 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 16, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 20, - EndPos: 23, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 25, - EndPos: 36, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 20, + EndPos: 23, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 36, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 26, + EndPos: 29, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12682,33 +12563,21 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 29, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 29, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 33, - EndPos: 36, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 33, + EndPos: 36, + }, + }, + Value: []byte("bar"), + }, }, }, }, diff --git a/internal/php5/php5.go b/internal/php5/php5.go index f05d452..a1be3c0 100644 Binary files a/internal/php5/php5.go and b/internal/php5/php5.go differ diff --git a/internal/php5/php5.y b/internal/php5/php5.y index d328d44..a462f00 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -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, + }, + } } ; diff --git a/internal/php5/php5_test.go b/internal/php5/php5_test.go index 051917b..d802b19 100644 --- a/internal/php5/php5_test.go +++ b/internal/php5/php5_test.go @@ -8536,17 +8536,17 @@ 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{ + Position: &position.Position{ + StartLine: 154, + EndLine: 154, + StartPos: 3285, + EndPos: 3288, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 154, @@ -8555,27 +8555,17 @@ func TestPhp5(t *testing.T) { EndPos: 3288, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 154, - EndLine: 154, - StartPos: 3285, - EndPos: 3288, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 154, - EndLine: 154, - StartPos: 3285, - EndPos: 3288, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 154, + EndLine: 154, + StartPos: 3285, + EndPos: 3288, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -8591,46 +8581,36 @@ 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{ + Position: &position.Position{ + StartLine: 155, + EndLine: 155, + StartPos: 3294, + EndPos: 3298, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 155, EndLine: 155, - StartPos: 3294, + StartPos: 3295, EndPos: 3298, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 155, - EndLine: 155, - StartPos: 3295, - EndPos: 3298, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 155, - EndLine: 155, - StartPos: 3295, - EndPos: 3298, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 155, + EndLine: 155, + StartPos: 3295, + EndPos: 3298, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -8646,59 +8626,49 @@ 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{ + Position: &position.Position{ + StartLine: 156, + EndLine: 156, + StartPos: 3304, + EndPos: 3315, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 156, EndLine: 156, - StartPos: 3304, + StartPos: 3305, + EndPos: 3308, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 156, + EndLine: 156, + StartPos: 3305, + EndPos: 3308, + }, + }, + Value: []byte("Foo"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 156, + EndLine: 156, + StartPos: 3312, EndPos: 3315, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 156, - EndLine: 156, - StartPos: 3305, - EndPos: 3308, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 156, - EndLine: 156, - StartPos: 3305, - EndPos: 3308, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 156, - EndLine: 156, - StartPos: 3312, - EndPos: 3315, - }, - }, - Value: []byte("Bar"), - }, + Value: []byte("Bar"), }, }, }, @@ -8712,17 +8682,17 @@ 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{ + Position: &position.Position{ + StartLine: 157, + EndLine: 157, + StartPos: 3321, + EndPos: 3324, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 157, @@ -8731,31 +8701,31 @@ func TestPhp5(t *testing.T) { EndPos: 3324, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3321, - EndPos: 3324, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3321, - EndPos: 3324, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 157, + EndLine: 157, + StartPos: 3321, + EndPos: 3324, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 157, + EndLine: 157, + StartPos: 3326, + EndPos: 3329, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 157, @@ -8764,27 +8734,17 @@ func TestPhp5(t *testing.T) { EndPos: 3329, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3326, - EndPos: 3329, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3326, - EndPos: 3329, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 157, + EndLine: 157, + StartPos: 3326, + EndPos: 3329, }, - Value: []byte("Bar"), }, + Value: []byte("Bar"), }, }, }, @@ -8800,17 +8760,17 @@ 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{ + Position: &position.Position{ + StartLine: 158, + EndLine: 158, + StartPos: 3335, + EndPos: 3338, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 158, @@ -8819,73 +8779,63 @@ func TestPhp5(t *testing.T) { EndPos: 3338, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3335, - EndPos: 3338, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3335, - EndPos: 3338, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 158, + EndLine: 158, + StartPos: 3335, + EndPos: 3338, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 158, + EndLine: 158, + StartPos: 3340, + EndPos: 3350, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 158, EndLine: 158, StartPos: 3340, + EndPos: 3343, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 158, + EndLine: 158, + StartPos: 3340, + EndPos: 3343, + }, + }, + Value: []byte("Bar"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 158, + EndLine: 158, + StartPos: 3347, EndPos: 3350, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3340, - EndPos: 3343, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3340, - EndPos: 3343, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3347, - EndPos: 3350, - }, - }, - Value: []byte("Baz"), - }, + Value: []byte("Baz"), }, }, }, @@ -8899,46 +8849,38 @@ func TestPhp5(t *testing.T) { EndPos: 3375, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, EndLine: 159, StartPos: 3356, - EndPos: 3374, + EndPos: 3364, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3356, - EndPos: 3364, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, EndLine: 159, StartPos: 3365, - EndPos: 3374, + EndPos: 3368, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3365, - EndPos: 3368, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3365, + EndPos: 3368, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, @@ -8947,31 +8889,31 @@ func TestPhp5(t *testing.T) { EndPos: 3368, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3365, - EndPos: 3368, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3370, - EndPos: 3374, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3370, + EndPos: 3374, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3371, + EndPos: 3374, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, @@ -8980,19 +8922,7 @@ func TestPhp5(t *testing.T) { EndPos: 3374, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3371, - EndPos: 3374, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -9008,46 +8938,38 @@ func TestPhp5(t *testing.T) { EndPos: 3413, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, EndLine: 160, StartPos: 3380, - EndPos: 3412, + EndPos: 3388, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3380, - EndPos: 3388, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, EndLine: 160, StartPos: 3389, - EndPos: 3412, + EndPos: 3399, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3389, - EndPos: 3399, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3389, + EndPos: 3392, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, @@ -9056,42 +8978,42 @@ func TestPhp5(t *testing.T) { EndPos: 3392, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3389, - EndPos: 3392, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3396, - EndPos: 3399, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3401, - EndPos: 3412, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3396, + EndPos: 3399, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3401, + EndPos: 3412, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3402, + EndPos: 3405, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, @@ -9100,33 +9022,21 @@ func TestPhp5(t *testing.T) { EndPos: 3405, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3402, - EndPos: 3405, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3409, - EndPos: 3412, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3409, + EndPos: 3412, + }, + }, + Value: []byte("bar"), + }, }, }, }, @@ -9139,46 +9049,38 @@ func TestPhp5(t *testing.T) { EndPos: 3434, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, EndLine: 161, StartPos: 3418, - EndPos: 3433, + EndPos: 3423, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3418, - EndPos: 3423, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, EndLine: 161, StartPos: 3424, - EndPos: 3433, + EndPos: 3427, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3424, - EndPos: 3427, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3424, + EndPos: 3427, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9187,31 +9089,31 @@ func TestPhp5(t *testing.T) { EndPos: 3427, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3424, - EndPos: 3427, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3429, - EndPos: 3433, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3429, + EndPos: 3433, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3430, + EndPos: 3433, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9220,19 +9122,7 @@ func TestPhp5(t *testing.T) { EndPos: 3433, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3430, - EndPos: 3433, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -9248,46 +9138,38 @@ func TestPhp5(t *testing.T) { EndPos: 3469, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, EndLine: 162, StartPos: 3439, - EndPos: 3468, + EndPos: 3444, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3439, - EndPos: 3444, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, EndLine: 162, StartPos: 3445, - EndPos: 3468, + EndPos: 3455, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3445, - EndPos: 3455, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3445, + EndPos: 3448, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9296,42 +9178,42 @@ func TestPhp5(t *testing.T) { EndPos: 3448, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3445, - EndPos: 3448, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3452, - EndPos: 3455, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3457, - EndPos: 3468, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3452, + EndPos: 3455, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3457, + EndPos: 3468, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3458, + EndPos: 3461, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9340,33 +9222,21 @@ func TestPhp5(t *testing.T) { EndPos: 3461, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3458, - EndPos: 3461, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3465, - EndPos: 3468, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3465, + EndPos: 3468, + }, + }, + Value: []byte("bar"), + }, }, }, }, diff --git a/internal/php7/parser_test.go b/internal/php7/parser_test.go index d909c98..b33e201 100644 --- a/internal/php7/parser_test.go +++ b/internal/php7/parser_test.go @@ -12671,17 +12671,17 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12690,27 +12690,17 @@ func TestStmtUse(t *testing.T) { EndPos: 10, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -12751,46 +12741,36 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 11, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, - StartPos: 7, + StartPos: 8, EndPos: 11, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 11, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -12831,59 +12811,49 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 18, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, - StartPos: 7, + StartPos: 8, + EndPos: 11, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 11, + }, + }, + Value: []byte("Foo"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 15, EndPos: 18, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 15, - EndPos: 18, - }, - }, - Value: []byte("Bar"), - }, + Value: []byte("Bar"), }, }, }, @@ -12922,17 +12892,17 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12941,31 +12911,31 @@ func TestStmtUse_List(t *testing.T) { EndPos: 10, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12974,27 +12944,17 @@ func TestStmtUse_List(t *testing.T) { EndPos: 15, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, }, - Value: []byte("Bar"), }, + Value: []byte("Bar"), }, }, }, @@ -13035,17 +12995,17 @@ 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{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13054,73 +13014,63 @@ func TestStmtUse_ListAlias(t *testing.T) { EndPos: 10, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 22, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, + EndPos: 15, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, + }, + Value: []byte("Bar"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, EndPos: 22, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 19, - EndPos: 22, - }, - }, - Value: []byte("Baz"), - }, + Value: []byte("Baz"), }, }, }, @@ -13159,46 +13109,38 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 26, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 25, + EndPos: 15, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 15, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 25, + EndPos: 19, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13207,31 +13149,31 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 19, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 21, - EndPos: 25, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 21, + EndPos: 25, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 22, + EndPos: 25, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13240,19 +13182,7 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 25, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 22, - EndPos: 25, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -13293,46 +13223,38 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 40, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 39, + EndPos: 15, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 15, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 39, + EndPos: 26, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 26, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13341,42 +13263,42 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 19, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 26, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 28, - EndPos: 39, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 26, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 28, + EndPos: 39, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 32, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13385,33 +13307,21 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 32, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 32, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 36, - EndPos: 39, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 36, + EndPos: 39, + }, + }, + Value: []byte("bar"), + }, }, }, }, @@ -13449,47 +13359,38 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 23, }, }, - - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 22, + EndPos: 12, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 12, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 22, + EndPos: 16, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13498,31 +13399,31 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 16, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 22, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 22, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 22, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13531,19 +13432,7 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 22, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 19, - EndPos: 22, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -13584,46 +13473,38 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 37, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 36, + EndPos: 12, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 12, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 36, + EndPos: 23, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 23, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13632,42 +13513,42 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 16, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 20, - EndPos: 23, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 25, - EndPos: 36, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 20, + EndPos: 23, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 25, + EndPos: 36, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 26, + EndPos: 29, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13676,33 +13557,21 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 29, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 29, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 33, - EndPos: 36, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 33, + EndPos: 36, + }, + }, + Value: []byte("bar"), + }, }, }, }, @@ -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,58 +13609,50 @@ func TestStmtUse_GroupUse(t *testing.T) { EndPos: 22, }, }, - UseList: &ast.StmtGroupUseList{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 21, + EndPos: 10, }, }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, - UseList: &ast.StmtUseList{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, - EndPos: 20, + EndPos: 15, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13800,31 +13661,31 @@ func TestStmtUse_GroupUse(t *testing.T) { EndPos: 15, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 17, - EndPos: 20, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 20, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 20, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13833,19 +13694,7 @@ func TestStmtUse_GroupUse(t *testing.T) { EndPos: 20, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 17, - EndPos: 20, - }, - }, - Value: []byte("Baz"), - }, - }, + Value: []byte("Baz"), }, }, }, @@ -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,58 +13735,50 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { EndPos: 30, }, }, - UseList: &ast.StmtGroupUseList{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 29, + EndPos: 10, }, }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, - UseList: &ast.StmtUseList{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, - EndPos: 28, + EndPos: 15, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13946,31 +13787,31 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { EndPos: 15, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 17, - EndPos: 28, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 28, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 20, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13979,33 +13820,21 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { EndPos: 20, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 17, - EndPos: 20, - }, - }, - Value: []byte("Baz"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 28, - }, - }, - Value: []byte("quux"), + Value: []byte("Baz"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 24, + EndPos: 28, + }, + }, + Value: []byte("quux"), + }, }, }, }, @@ -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,36 +13872,28 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 31, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 30, + EndPos: 15, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 15, - }, + Value: []byte("function"), + }, + Prefix: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, }, - Value: []byte("function"), }, - Use: &ast.StmtGroupUseList{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 30, - }, - }, - Prefix: &ast.NameName{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14081,31 +13902,31 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 19, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, - }, - }, - Value: []byte("Foo"), - }, + Value: []byte("Foo"), + }, + }, + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 21, + EndPos: 24, }, }, - UseList: &ast.StmtUseList{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 21, - EndPos: 29, + EndPos: 24, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14114,31 +13935,31 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 24, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 21, - EndPos: 24, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 21, - EndPos: 24, - }, - }, - Value: []byte("Bar"), - }, - }, - }, + Value: []byte("Bar"), }, - &ast.StmtUseDeclaration{ + }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 26, + EndPos: 29, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 26, + EndPos: 29, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14147,29 +13968,7 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 29, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 29, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 29, - }, - }, - Value: []byte("Baz"), - }, - }, - }, + Value: []byte("Baz"), }, }, }, @@ -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,36 +14009,28 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 28, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 27, + EndPos: 12, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 12, - }, + Value: []byte("const"), + }, + Prefix: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, }, - Value: []byte("const"), }, - Use: &ast.StmtGroupUseList{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 27, - }, - }, - Prefix: &ast.NameName{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14248,31 +14039,31 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 16, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, - }, - }, - Value: []byte("Foo"), - }, + Value: []byte("Foo"), + }, + }, + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 21, }, }, - UseList: &ast.StmtUseList{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 18, - EndPos: 26, + EndPos: 21, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14281,31 +14072,31 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 21, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 21, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 21, - }, - }, - Value: []byte("Bar"), - }, - }, - }, + Value: []byte("Bar"), }, - &ast.StmtUseDeclaration{ + }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 26, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 26, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14314,29 +14105,7 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 26, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 26, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 26, - }, - }, - Value: []byte("Baz"), - }, - }, - }, + Value: []byte("Baz"), }, }, }, @@ -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,69 +14146,61 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { EndPos: 37, }, }, - UseList: &ast.StmtGroupUseList{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 36, + EndPos: 10, }, }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, - UseList: &ast.StmtUseList{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, - EndPos: 35, + EndPos: 21, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseType{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 21, - }, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 17, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 17, - }, - }, - Value: []byte("const"), + }, + Value: []byte("const"), + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 18, + EndPos: 21, }, - Use: &ast.StmtUseDeclaration{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14448,52 +14209,42 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { EndPos: 21, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 21, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 21, - }, - }, - Value: []byte("Bar"), - }, - }, - }, + Value: []byte("Bar"), }, }, - &ast.StmtUseType{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 35, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 35, + }, + }, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 31, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 31, - }, - }, - Value: []byte("function"), + }, + Value: []byte("function"), + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 32, + EndPos: 35, }, - Use: &ast.StmtUseDeclaration{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -14502,29 +14253,7 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { EndPos: 35, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 32, - EndPos: 35, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 32, - EndPos: 35, - }, - }, - Value: []byte("Baz"), - }, - }, - }, + Value: []byte("Baz"), }, }, }, diff --git a/internal/php7/php7.go b/internal/php7/php7.go index 7ed02ea..2e0a57b 100644 Binary files a/internal/php7/php7.go and b/internal/php7/php7.go differ diff --git a/internal/php7/php7.y b/internal/php7/php7.y index 23503c6..f6589cd 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -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 } ; diff --git a/internal/php7/php7_test.go b/internal/php7/php7_test.go index 8d52038..00d02cc 100644 --- a/internal/php7/php7_test.go +++ b/internal/php7/php7_test.go @@ -9024,17 +9024,17 @@ 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{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3366, + EndPos: 3369, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9043,27 +9043,17 @@ func TestPhp7(t *testing.T) { EndPos: 3369, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3366, - EndPos: 3369, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3366, - EndPos: 3369, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3366, + EndPos: 3369, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -9079,46 +9069,36 @@ 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{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3375, + EndPos: 3379, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, EndLine: 162, - StartPos: 3375, + StartPos: 3376, EndPos: 3379, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3376, - EndPos: 3379, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3376, - EndPos: 3379, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3376, + EndPos: 3379, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, @@ -9134,59 +9114,49 @@ 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{ + Position: &position.Position{ + StartLine: 163, + EndLine: 163, + StartPos: 3385, + EndPos: 3396, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 163, EndLine: 163, - StartPos: 3385, + StartPos: 3386, + EndPos: 3389, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 163, + EndLine: 163, + StartPos: 3386, + EndPos: 3389, + }, + }, + Value: []byte("Foo"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 163, + EndLine: 163, + StartPos: 3393, EndPos: 3396, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 163, - EndLine: 163, - StartPos: 3386, - EndPos: 3389, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 163, - EndLine: 163, - StartPos: 3386, - EndPos: 3389, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 163, - EndLine: 163, - StartPos: 3393, - EndPos: 3396, - }, - }, - Value: []byte("Bar"), - }, + Value: []byte("Bar"), }, }, }, @@ -9200,17 +9170,17 @@ 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{ + Position: &position.Position{ + StartLine: 164, + EndLine: 164, + StartPos: 3402, + EndPos: 3405, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 164, @@ -9219,31 +9189,31 @@ func TestPhp7(t *testing.T) { EndPos: 3405, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3402, - EndPos: 3405, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3402, - EndPos: 3405, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 164, + EndLine: 164, + StartPos: 3402, + EndPos: 3405, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 164, + EndLine: 164, + StartPos: 3407, + EndPos: 3410, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 164, @@ -9252,27 +9222,17 @@ func TestPhp7(t *testing.T) { EndPos: 3410, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3407, - EndPos: 3410, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3407, - EndPos: 3410, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 164, + EndLine: 164, + StartPos: 3407, + EndPos: 3410, }, - Value: []byte("Bar"), }, + Value: []byte("Bar"), }, }, }, @@ -9288,17 +9248,17 @@ 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{ + Position: &position.Position{ + StartLine: 165, + EndLine: 165, + StartPos: 3416, + EndPos: 3419, + }, }, - }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 165, @@ -9307,73 +9267,63 @@ func TestPhp7(t *testing.T) { EndPos: 3419, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3416, - EndPos: 3419, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3416, - EndPos: 3419, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 165, + EndLine: 165, + StartPos: 3416, + EndPos: 3419, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, }, - &ast.StmtUseDeclaration{ + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 165, + EndLine: 165, + StartPos: 3421, + EndPos: 3431, + }, + }, + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 165, EndLine: 165, StartPos: 3421, + EndPos: 3424, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 165, + EndLine: 165, + StartPos: 3421, + EndPos: 3424, + }, + }, + Value: []byte("Bar"), + }, + }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 165, + EndLine: 165, + StartPos: 3428, EndPos: 3431, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3421, - EndPos: 3424, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3421, - EndPos: 3424, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3428, - EndPos: 3431, - }, - }, - Value: []byte("Baz"), - }, + Value: []byte("Baz"), }, }, }, @@ -9387,46 +9337,38 @@ func TestPhp7(t *testing.T) { EndPos: 3456, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, EndLine: 166, StartPos: 3437, - EndPos: 3455, + EndPos: 3445, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3437, - EndPos: 3445, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, EndLine: 166, StartPos: 3446, - EndPos: 3455, + EndPos: 3449, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3446, - EndPos: 3449, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3446, + EndPos: 3449, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, @@ -9435,31 +9377,31 @@ func TestPhp7(t *testing.T) { EndPos: 3449, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3446, - EndPos: 3449, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3451, - EndPos: 3455, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3451, + EndPos: 3455, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3452, + EndPos: 3455, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, @@ -9468,19 +9410,7 @@ func TestPhp7(t *testing.T) { EndPos: 3455, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3452, - EndPos: 3455, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -9496,46 +9426,38 @@ func TestPhp7(t *testing.T) { EndPos: 3494, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, EndLine: 167, StartPos: 3461, - EndPos: 3493, + EndPos: 3469, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3461, - EndPos: 3469, - }, - }, - Value: []byte("function"), - }, - Use: &ast.StmtUseList{ + Value: []byte("function"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, EndLine: 167, StartPos: 3470, - EndPos: 3493, + EndPos: 3480, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3470, - EndPos: 3480, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3470, + EndPos: 3473, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, @@ -9544,42 +9466,42 @@ func TestPhp7(t *testing.T) { EndPos: 3473, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3470, - EndPos: 3473, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3477, - EndPos: 3480, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3482, - EndPos: 3493, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3477, + EndPos: 3480, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3482, + EndPos: 3493, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3483, + EndPos: 3486, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, @@ -9588,33 +9510,21 @@ func TestPhp7(t *testing.T) { EndPos: 3486, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3483, - EndPos: 3486, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3490, - EndPos: 3493, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3490, + EndPos: 3493, + }, + }, + Value: []byte("bar"), + }, }, }, }, @@ -9627,46 +9537,38 @@ func TestPhp7(t *testing.T) { EndPos: 3515, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, EndLine: 168, StartPos: 3499, - EndPos: 3514, + EndPos: 3504, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3499, - EndPos: 3504, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, EndLine: 168, StartPos: 3505, - EndPos: 3514, + EndPos: 3508, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3505, - EndPos: 3508, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3505, + EndPos: 3508, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, @@ -9675,31 +9577,31 @@ func TestPhp7(t *testing.T) { EndPos: 3508, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3505, - EndPos: 3508, - }, - }, - Value: []byte("Foo"), - }, - }, + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3510, - EndPos: 3514, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3510, + EndPos: 3514, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3511, + EndPos: 3514, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, @@ -9708,19 +9610,7 @@ func TestPhp7(t *testing.T) { EndPos: 3514, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3511, - EndPos: 3514, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, }, @@ -9736,46 +9626,38 @@ func TestPhp7(t *testing.T) { EndPos: 3550, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, EndLine: 169, StartPos: 3520, - EndPos: 3549, + EndPos: 3525, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3520, - EndPos: 3525, - }, - }, - Value: []byte("const"), - }, - Use: &ast.StmtUseList{ + Value: []byte("const"), + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, EndLine: 169, StartPos: 3526, - EndPos: 3549, + EndPos: 3536, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3526, - EndPos: 3536, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3526, + EndPos: 3529, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, @@ -9784,42 +9666,42 @@ func TestPhp7(t *testing.T) { EndPos: 3529, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3526, - EndPos: 3529, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3533, - EndPos: 3536, - }, - }, - Value: []byte("foo"), + Value: []byte("Foo"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3538, - EndPos: 3549, - }, + }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3533, + EndPos: 3536, }, - Use: &ast.NameName{ + }, + Value: []byte("foo"), + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3538, + EndPos: 3549, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3539, + EndPos: 3542, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, @@ -9828,37 +9710,25 @@ func TestPhp7(t *testing.T) { EndPos: 3542, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3539, - EndPos: 3542, - }, - }, - Value: []byte("Bar"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3546, - EndPos: 3549, - }, - }, - Value: []byte("bar"), + Value: []byte("Bar"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3546, + EndPos: 3549, + }, + }, + Value: []byte("bar"), + }, }, }, }, - &ast.StmtUse{ + &ast.StmtGroupUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, @@ -9867,58 +9737,50 @@ func TestPhp7(t *testing.T) { EndPos: 3572, }, }, - UseList: &ast.StmtGroupUseList{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, EndLine: 171, - StartPos: 3556, - EndPos: 3571, + StartPos: 3557, + EndPos: 3560, }, }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3557, - EndPos: 3560, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3557, - EndPos: 3560, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3557, + EndPos: 3560, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, - UseList: &ast.StmtUseList{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, EndLine: 171, StartPos: 3562, - EndPos: 3570, + EndPos: 3565, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3562, - EndPos: 3565, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3562, + EndPos: 3565, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, @@ -9927,31 +9789,31 @@ func TestPhp7(t *testing.T) { EndPos: 3565, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3562, - EndPos: 3565, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3567, - EndPos: 3570, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3567, + EndPos: 3570, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3567, + EndPos: 3570, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, @@ -9960,26 +9822,14 @@ func TestPhp7(t *testing.T) { EndPos: 3570, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3567, - EndPos: 3570, - }, - }, - Value: []byte("Baz"), - }, - }, + Value: []byte("Baz"), }, }, }, }, }, }, - &ast.StmtUse{ + &ast.StmtGroupUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, @@ -9988,58 +9838,50 @@ func TestPhp7(t *testing.T) { EndPos: 3600, }, }, - UseList: &ast.StmtGroupUseList{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, EndLine: 172, StartPos: 3577, - EndPos: 3599, + EndPos: 3580, }, }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3577, - EndPos: 3580, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3577, - EndPos: 3580, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3577, + EndPos: 3580, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, - UseList: &ast.StmtUseList{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, EndLine: 172, StartPos: 3582, - EndPos: 3598, + EndPos: 3585, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3582, - EndPos: 3585, - }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3582, + EndPos: 3585, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, @@ -10048,31 +9890,31 @@ func TestPhp7(t *testing.T) { EndPos: 3585, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3582, - EndPos: 3585, - }, - }, - Value: []byte("Bar"), - }, - }, + Value: []byte("Bar"), }, }, - &ast.StmtUseDeclaration{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3587, - EndPos: 3598, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3587, + EndPos: 3598, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3587, + EndPos: 3590, }, - Use: &ast.NameName{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, @@ -10081,37 +9923,25 @@ func TestPhp7(t *testing.T) { EndPos: 3590, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3587, - EndPos: 3590, - }, - }, - Value: []byte("Baz"), - }, - }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3594, - EndPos: 3598, - }, - }, - Value: []byte("quux"), + Value: []byte("Baz"), }, }, }, + Alias: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3594, + EndPos: 3598, + }, + }, + Value: []byte("quux"), + }, }, }, }, - &ast.StmtUse{ + &ast.StmtGroupUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -10120,36 +9950,28 @@ func TestPhp7(t *testing.T) { EndPos: 3629, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, EndLine: 173, StartPos: 3605, - EndPos: 3628, + EndPos: 3613, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3605, - EndPos: 3613, - }, + Value: []byte("function"), + }, + Prefix: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 173, + EndLine: 173, + StartPos: 3614, + EndPos: 3617, }, - Value: []byte("function"), }, - Use: &ast.StmtGroupUseList{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3614, - EndPos: 3628, - }, - }, - Prefix: &ast.NameName{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -10158,31 +9980,31 @@ func TestPhp7(t *testing.T) { EndPos: 3617, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3614, - EndPos: 3617, - }, - }, - Value: []byte("Foo"), - }, + Value: []byte("Foo"), + }, + }, + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 173, + EndLine: 173, + StartPos: 3619, + EndPos: 3622, }, }, - UseList: &ast.StmtUseList{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, EndLine: 173, StartPos: 3619, - EndPos: 3627, + EndPos: 3622, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -10191,31 +10013,31 @@ func TestPhp7(t *testing.T) { EndPos: 3622, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3619, - EndPos: 3622, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3619, - EndPos: 3622, - }, - }, - Value: []byte("Bar"), - }, - }, - }, + Value: []byte("Bar"), }, - &ast.StmtUseDeclaration{ + }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 173, + EndLine: 173, + StartPos: 3624, + EndPos: 3627, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 173, + EndLine: 173, + StartPos: 3624, + EndPos: 3627, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -10224,36 +10046,14 @@ func TestPhp7(t *testing.T) { EndPos: 3627, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3624, - EndPos: 3627, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3624, - EndPos: 3627, - }, - }, - Value: []byte("Baz"), - }, - }, - }, + Value: []byte("Baz"), }, }, }, }, }, }, - &ast.StmtUse{ + &ast.StmtGroupUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10262,36 +10062,28 @@ func TestPhp7(t *testing.T) { EndPos: 3656, }, }, - UseList: &ast.StmtUseType{ + Type: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, EndLine: 174, StartPos: 3634, - EndPos: 3655, + EndPos: 3639, }, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3634, - EndPos: 3639, - }, + Value: []byte("const"), + }, + Prefix: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 174, + EndLine: 174, + StartPos: 3641, + EndPos: 3644, }, - Value: []byte("const"), }, - Use: &ast.StmtGroupUseList{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3640, - EndPos: 3655, - }, - }, - Prefix: &ast.NameName{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10300,31 +10092,31 @@ func TestPhp7(t *testing.T) { EndPos: 3644, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3641, - EndPos: 3644, - }, - }, - Value: []byte("Foo"), - }, + Value: []byte("Foo"), + }, + }, + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 174, + EndLine: 174, + StartPos: 3646, + EndPos: 3649, }, }, - UseList: &ast.StmtUseList{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, EndLine: 174, StartPos: 3646, - EndPos: 3654, + EndPos: 3649, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10333,31 +10125,31 @@ func TestPhp7(t *testing.T) { EndPos: 3649, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3646, - EndPos: 3649, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3646, - EndPos: 3649, - }, - }, - Value: []byte("Bar"), - }, - }, - }, + Value: []byte("Bar"), }, - &ast.StmtUseDeclaration{ + }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 174, + EndLine: 174, + StartPos: 3651, + EndPos: 3654, + }, + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 174, + EndLine: 174, + StartPos: 3651, + EndPos: 3654, + }, + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10366,36 +10158,14 @@ func TestPhp7(t *testing.T) { EndPos: 3654, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3651, - EndPos: 3654, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3651, - EndPos: 3654, - }, - }, - Value: []byte("Baz"), - }, - }, - }, + Value: []byte("Baz"), }, }, }, }, }, }, - &ast.StmtUse{ + &ast.StmtGroupUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, @@ -10404,69 +10174,61 @@ func TestPhp7(t *testing.T) { EndPos: 3691, }, }, - UseList: &ast.StmtGroupUseList{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, EndLine: 175, StartPos: 3661, - EndPos: 3690, + EndPos: 3664, }, }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3661, - EndPos: 3664, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3661, - EndPos: 3664, - }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3661, + EndPos: 3664, }, - Value: []byte("Foo"), }, + Value: []byte("Foo"), }, }, - UseList: &ast.StmtUseList{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, EndLine: 175, StartPos: 3666, - EndPos: 3689, + EndPos: 3675, }, }, - UseDeclarations: []ast.Vertex{ - &ast.StmtUseType{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3666, - EndPos: 3675, - }, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3666, + EndPos: 3671, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3666, - EndPos: 3671, - }, - }, - Value: []byte("const"), + }, + Value: []byte("const"), + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3672, + EndPos: 3675, }, - Use: &ast.StmtUseDeclaration{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, @@ -10475,52 +10237,42 @@ func TestPhp7(t *testing.T) { EndPos: 3675, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3672, - EndPos: 3675, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3672, - EndPos: 3675, - }, - }, - Value: []byte("Bar"), - }, - }, - }, + Value: []byte("Bar"), }, }, - &ast.StmtUseType{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3677, - EndPos: 3689, - }, + }, + }, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3677, + EndPos: 3689, + }, + }, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3677, + EndPos: 3685, }, - Type: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3677, - EndPos: 3685, - }, - }, - Value: []byte("function"), + }, + Value: []byte("function"), + }, + Use: &ast.NameName{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3686, + EndPos: 3689, }, - Use: &ast.StmtUseDeclaration{ + }, + Parts: []ast.Vertex{ + &ast.NameNamePart{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, @@ -10529,29 +10281,7 @@ func TestPhp7(t *testing.T) { EndPos: 3689, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3686, - EndPos: 3689, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3686, - EndPos: 3689, - }, - }, - Value: []byte("Baz"), - }, - }, - }, + Value: []byte("Baz"), }, }, }, diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 4259f92..2da9b8e 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -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) diff --git a/pkg/ast/node.go b/pkg/ast/node.go index 85b494a..d7dd01d 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -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 - Prefix Vertex - UseList Vertex + UseTkn *token.Token + Type Vertex + LeadingNsSeparatorTkn *token.Token + Prefix Vertex + NsSeparatorTkn *token.Token + OpenCurlyBracketTkn *token.Token + UseDeclarations []Vertex + CloseCurlyBracketTkn *token.Token + SemiColonTkn *token.Token } -func (n *StmtGroupUseList) Accept(v NodeVisitor) { - v.StmtGroupUseList(n) -} - -// StmtUseList node -type StmtUseList struct { - Node - UseDeclarations []Vertex -} - -func (n *StmtUseList) Accept(v NodeVisitor) { - v.StmtUseList(n) +func (n *StmtGroupUse) Accept(v NodeVisitor) { + v.StmtGroupUse(n) } // StmtUseDeclaration node type StmtUseDeclaration struct { Node - Use Vertex - Alias Vertex + 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 diff --git a/pkg/ast/traverser/dfs.go b/pkg/ast/traverser/dfs.go index 03ebbad..20eecf3 100644 --- a/pkg/ast/traverser/dfs.go +++ b/pkg/ast/traverser/dfs.go @@ -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 diff --git a/pkg/ast/visitor/dump.go b/pkg/ast/visitor/dump.go index 67bbaac..61deec6 100644 --- a/pkg/ast/visitor/dump.go +++ b/pkg/ast/visitor/dump.go @@ -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) { diff --git a/pkg/ast/visitor/filter_parser_nodes.go b/pkg/ast/visitor/filter_parser_nodes.go index f1a5655..4df410a 100644 --- a/pkg/ast/visitor/filter_parser_nodes.go +++ b/pkg/ast/visitor/filter_parser_nodes.go @@ -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 { diff --git a/pkg/ast/visitor/filter_tokens.go b/pkg/ast/visitor/filter_tokens.go index c69a3f6..7101b86 100644 --- a/pkg/ast/visitor/filter_tokens.go +++ b/pkg/ast/visitor/filter_tokens.go @@ -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 +} diff --git a/pkg/ast/visitor/namespace_resolver.go b/pkg/ast/visitor/namespace_resolver.go index 65f0f54..34c92c7 100644 --- a/pkg/ast/visitor/namespace_resolver.go +++ b/pkg/ast/visitor/namespace_resolver.go @@ -13,9 +13,7 @@ type NamespaceResolver struct { Namespace *Namespace ResolvedNames map[ast.Vertex]string - goDeep bool - useType string - usePrefix []ast.Vertex + goDeep bool } // 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) } + + for _, nn := range n.UseDeclarations { + nsr.AddAlias(useType, nn, nil) + } + + nsr.goDeep = false } -func (nsr *NamespaceResolver) StmtGroupUseList(n *ast.StmtGroupUseList) { - if n.Prefix != nil { - nsr.usePrefix = n.Prefix.(*ast.NameName).Parts - } -} - -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) +func (nsr *NamespaceResolver) StmtGroupUse(n *ast.StmtGroupUse) { + useType := "" + if n.Type != nil { + useType = string(n.Type.(*ast.Identifier).Value) } - nsr.Namespace.AddAlias(nsr.useType, concatNameParts(nsr.usePrefix, useNameParts), alias) + 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) } } diff --git a/pkg/ast/visitor/namespace_resolver_test.go b/pkg/ast/visitor/namespace_resolver_test.go index 22eb8bc..34a31f7 100644 --- a/pkg/ast/visitor/namespace_resolver_test.go +++ b/pkg/ast/visitor/namespace_resolver_test.go @@ -17,11 +17,9 @@ func TestResolveStaticCall(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAB, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -51,11 +49,9 @@ func TestResolveStaticPropertyFetch(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAB, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -84,11 +80,9 @@ func TestResolveClassConstFetch(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAB, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -117,11 +111,9 @@ func TestResolveNew(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAB, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -150,11 +142,9 @@ func TestResolveInstanceOf(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAB, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -186,14 +176,13 @@ 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{ - Use: nameDE, - Alias: &ast.Identifier{Value: []byte("F")}, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, + &ast.StmtUseDeclaration{ + Use: nameDE, + Alias: &ast.Identifier{Value: []byte("F")}, }, }, }, @@ -232,14 +221,10 @@ 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, - }, - }, + Type: &ast.Identifier{Value: []byte("function")}, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -268,14 +253,10 @@ 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, - }, - }, + Type: &ast.Identifier{Value: []byte("const")}, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -305,39 +286,25 @@ func TestResolveGroupUse(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUse{ - UseList: &ast.StmtGroupUseList{ - Prefix: nameAB, - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseType{ - Type: &ast.Identifier{Value: []byte("Function")}, - Use: &ast.StmtUseDeclaration{ - Use: nameF, - }, - }, - &ast.StmtUseType{ - Type: &ast.Identifier{Value: []byte("const")}, - Use: &ast.StmtUseDeclaration{ - Use: nameC, - }, - }, - }, + &ast.StmtGroupUse{ + Prefix: nameAB, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Type: &ast.Identifier{Value: []byte("Function")}, + Use: nameF, + }, + &ast.StmtUseDeclaration{ + Type: &ast.Identifier{Value: []byte("const")}, + Use: nameC, }, }, }, - &ast.StmtUse{ - UseList: &ast.StmtUseType{ - Type: &ast.Identifier{Value: []byte("Function")}, - Use: &ast.StmtGroupUseList{ - Prefix: nameBD, - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameE, - }, - }, - }, + &ast.StmtGroupUse{ + Prefix: nameBD, + Type: &ast.Identifier{Value: []byte("Function")}, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameE, }, }, }, @@ -381,11 +348,9 @@ func TestResolveTraitUse(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAB, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, }, }, }, @@ -704,11 +669,9 @@ func TestResolveNamespaces(t *testing.T) { NamespaceName: namespaceCD, Stmts: []ast.Vertex{ &ast.StmtUse{ - UseList: &ast.StmtUseList{ - UseDeclarations: []ast.Vertex{ - &ast.StmtUseDeclaration{ - Use: nameAC, - }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAC, }, }, }, diff --git a/pkg/ast/visitor/null.go b/pkg/ast/visitor/null.go index 033a77f..291d8f9 100644 --- a/pkg/ast/visitor/null.go +++ b/pkg/ast/visitor/null.go @@ -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 } diff --git a/pkg/printer/pretty_printer.go b/pkg/printer/pretty_printer.go index 71a89a8..1aab5d1 100644 --- a/pkg/printer/pretty_printer.go +++ b/pkg/printer/pretty_printer.go @@ -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) diff --git a/pkg/printer/pretty_printer_test.go b/pkg/printer/pretty_printer_test.go index 72f4988..199bc2f 100644 --- a/pkg/printer/pretty_printer_test.go +++ b/pkg/printer/pretty_printer_test.go @@ -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,30 +4005,11 @@ func TestPrintUseDeclaration(t *testing.T) { p := printer.NewPrettyPrinter(o, " ") p.Print(&ast.StmtUseDeclaration{ + Type: &ast.Identifier{Value: []byte("function")}, 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` actual := o.String() diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 3951b6f..8d73f1b 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -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(nn.UseList) + p.Print(n.Prefix) + p.printToken(n.NsSeparatorTkn, "\\") + p.printToken(n.OpenCurlyBracketTkn, "{") - if _, ok := nn.UseList.(*ast.ParserNsSeparator); !ok { - io.WriteString(p.w, "}") - } - - p.printFreeFloating(nn, token.End) -} - -func (p *Printer) printStmtUseList(n ast.Vertex) { - nn := n.(*ast.StmtUseList) - p.printFreeFloating(nn, token.Start) - - p.joinPrint(",", nn.UseDeclarations) - - 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") + 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.bufStart = " " - p.Print(nn.Alias) } - p.printFreeFloating(nn, token.End) + p.printToken(n.CloseCurlyBracketTkn, "}") + p.printToken(n.SemiColonTkn, ";") } -func (p *Printer) printStmtUseType(n ast.Vertex) { - nn := n.(*ast.StmtUseType) - p.printFreeFloating(nn, token.Start) +func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) { + p.Print(n.Type) - p.Print(nn.Type) + if n.Type != nil { + p.bufStart = " " + } + + p.printToken(n.NsSeparatorTkn, "") + + p.Print(n.Use) + + if n.Alias == nil { + return + } p.bufStart = " " - p.Print(nn.Use) + p.printToken(n.AsTkn, "as") - p.printFreeFloating(nn, token.End) + p.bufStart = " " + p.Print(n.Alias) } func (p *Printer) printStmtWhile(n ast.Vertex) { diff --git a/pkg/printer/printer_parsed_php5_test.go b/pkg/printer/printer_parsed_php5_test.go index 2745542..60cdc39 100644 --- a/pkg/printer/printer_parsed_php5_test.go +++ b/pkg/printer/printer_parsed_php5_test.go @@ -1308,7 +1308,8 @@ func TestParseAndPrintPhp5Unset(t *testing.T) { } func TestParseAndPrintPhp5UseList(t *testing.T) { - src := `