diff --git a/internal/php5/parser_test.go b/internal/php5/parser_test.go index dcb70ae..b210323 100644 --- a/internal/php5/parser_test.go +++ b/internal/php5/parser_test.go @@ -11442,7 +11442,7 @@ func TestStmtUse(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11451,17 +11451,17 @@ func TestStmtUse(t *testing.T) { EndPos: 11, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11470,17 +11470,27 @@ func TestStmtUse(t *testing.T) { EndPos: 10, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, @@ -11510,7 +11520,7 @@ func TestStmtUse_FullyQualified(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11519,17 +11529,17 @@ func TestStmtUse_FullyQualified(t *testing.T) { EndPos: 12, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 11, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11538,17 +11548,27 @@ func TestStmtUse_FullyQualified(t *testing.T) { EndPos: 11, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, @@ -11578,7 +11598,7 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11587,49 +11607,59 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) { EndPos: 19, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 18, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 18, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, @@ -11657,7 +11687,7 @@ func TestStmtUse_List(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11666,17 +11696,17 @@ func TestStmtUse_List(t *testing.T) { EndPos: 16, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11685,31 +11715,31 @@ func TestStmtUse_List(t *testing.T) { EndPos: 10, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11718,17 +11748,27 @@ func TestStmtUse_List(t *testing.T) { EndPos: 15, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - 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, + }, + }, + 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"), }, }, }, @@ -11758,7 +11798,7 @@ func TestStmtUse_ListAlias(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11767,17 +11807,17 @@ func TestStmtUse_ListAlias(t *testing.T) { EndPos: 23, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 22, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11786,63 +11826,73 @@ func TestStmtUse_ListAlias(t *testing.T) { EndPos: 10, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 22, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, @@ -11870,7 +11920,7 @@ func TestStmtUse_ListFunctionType(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11879,38 +11929,46 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 26, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 15, + EndPos: 25, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 19, + EndPos: 25, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11919,31 +11977,31 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 19, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 22, - EndPos: 25, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 22, - EndPos: 25, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 22, + EndPos: 25, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11952,7 +12010,19 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 25, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 22, + EndPos: 25, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, @@ -11982,7 +12052,7 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -11991,38 +12061,46 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 40, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 15, + EndPos: 39, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 26, + EndPos: 39, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 26, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12031,42 +12109,42 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 19, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 26, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 39, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 39, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 32, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12075,21 +12153,33 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 32, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 36, - EndPos: 39, - }, - }, - Value: []byte("bar"), - }, }, }, }, @@ -12116,7 +12206,7 @@ func TestStmtUse_ListConstType(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12125,38 +12215,47 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 23, }, }, - UseType: &ast.Identifier{ + + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 12, + EndPos: 22, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 12, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 16, + EndPos: 22, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12165,31 +12264,31 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 16, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - 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: 19, - EndPos: 22, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 22, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12198,7 +12297,19 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 22, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 22, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, @@ -12228,7 +12339,7 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12237,38 +12348,46 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 37, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 12, + EndPos: 36, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 12, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 23, + EndPos: 36, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 23, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12277,42 +12396,42 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 16, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 20, - EndPos: 23, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 26, + EndPos: 36, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 36, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 29, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12321,21 +12440,33 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 29, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - 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 162c382..7a695b7 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 50aa2a5..3e87194 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -428,49 +428,56 @@ top_statement: } | T_USE use_declarations ';' { - $$ = &ast.StmtUseList{ast.Node{}, nil, $2} + 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.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $3.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $3.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | T_USE T_FUNCTION use_function_declarations ';' { - useType := &ast.Identifier{ast.Node{}, $2.Value} - $$ = &ast.StmtUseList{ast.Node{}, useType, $3} + 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 - useType.GetNode().Position = position.NewTokenPosition($2) + 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.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setFreeFloating(useType, token.Start, $2.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $4.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $4.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | T_USE T_CONST use_const_declarations ';' { - useType := &ast.Identifier{ast.Node{}, $2.Value} - $$ = &ast.StmtUseList{ast.Node{}, useType, $3} + 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 - useType.GetNode().Position = position.NewTokenPosition($2) + 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.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setFreeFloating(useType, token.Start, $2.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $4.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $4.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -511,22 +518,19 @@ use_declaration: namespace_name { name := &ast.NameName{ast.Node{}, $1} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($1) $$.GetNode().Position = position.NewNodeListPosition($1) - // save comments - yylex.(*Parser).MoveFreeFloating($1[0], $$) - yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | namespace_name T_AS T_STRING { name := &ast.NameName{ast.Node{}, $1} alias := &ast.Identifier{ast.Node{}, $3.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($1) @@ -534,7 +538,6 @@ use_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($1, $3) // save comments - yylex.(*Parser).MoveFreeFloating($1[0], $$) yylex.(*Parser).setFreeFloating(name, token.End, $2.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $3.Tokens) @@ -543,16 +546,14 @@ use_declaration: | T_NS_SEPARATOR namespace_name { name := &ast.NameName{ast.Node{}, $2} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($2) $$.GetNode().Position = position.NewNodeListPosition($2) // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -560,7 +561,7 @@ use_declaration: { name := &ast.NameName{ast.Node{}, $2} alias := &ast.Identifier{ast.Node{}, $4.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($2) @@ -568,9 +569,7 @@ use_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($2, $4) // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating(name, token.End, $3.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $4.Tokens) @@ -600,22 +599,19 @@ use_function_declaration: namespace_name { name := &ast.NameName{ast.Node{}, $1} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($1) $$.GetNode().Position = position.NewNodeListPosition($1) - // save comments - yylex.(*Parser).MoveFreeFloating($1[0], $$) - yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | namespace_name T_AS T_STRING { name := &ast.NameName{ast.Node{}, $1} alias := &ast.Identifier{ast.Node{}, $3.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($1) @@ -623,7 +619,6 @@ use_function_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($1, $3) // save comments - yylex.(*Parser).MoveFreeFloating($1[0], $$) yylex.(*Parser).setFreeFloating(name, token.End, $2.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $3.Tokens) @@ -632,16 +627,14 @@ use_function_declaration: | T_NS_SEPARATOR namespace_name { name := &ast.NameName{ast.Node{}, $2} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($2) $$.GetNode().Position = position.NewNodeListPosition($2) // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -649,7 +642,7 @@ use_function_declaration: { name := &ast.NameName{ast.Node{}, $2} alias := &ast.Identifier{ast.Node{}, $4.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($2) @@ -657,9 +650,7 @@ use_function_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($2, $4) // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating(name, token.End, $3.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $4.Tokens) @@ -689,22 +680,19 @@ use_const_declaration: namespace_name { name := &ast.NameName{ast.Node{}, $1} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($1) $$.GetNode().Position = position.NewNodeListPosition($1) - // save comments - yylex.(*Parser).MoveFreeFloating($1[0], $$) - yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | namespace_name T_AS T_STRING { name := &ast.NameName{ast.Node{}, $1} alias := &ast.Identifier{ast.Node{}, $3.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($1) @@ -712,7 +700,6 @@ use_const_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($1, $3) // save comments - yylex.(*Parser).MoveFreeFloating($1[0], $$) yylex.(*Parser).setFreeFloating(name, token.End, $2.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $3.Tokens) @@ -721,16 +708,14 @@ use_const_declaration: | T_NS_SEPARATOR namespace_name { name := &ast.NameName{ast.Node{}, $2} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($2) $$.GetNode().Position = position.NewNodeListPosition($2) // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -738,7 +723,7 @@ use_const_declaration: { name := &ast.NameName{ast.Node{}, $2} alias := &ast.Identifier{ast.Node{}, $4.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($2) @@ -746,9 +731,7 @@ use_const_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($2, $4) // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating(name, token.End, $3.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $4.Tokens) diff --git a/internal/php5/php5_test.go b/internal/php5/php5_test.go index d36ab6d..7c4c4c6 100644 --- a/internal/php5/php5_test.go +++ b/internal/php5/php5_test.go @@ -8525,7 +8525,7 @@ func TestPhp5(t *testing.T) { }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 154, @@ -8534,17 +8534,17 @@ func TestPhp5(t *testing.T) { EndPos: 3289, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 154, - EndLine: 154, - StartPos: 3285, - EndPos: 3288, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 154, + EndLine: 154, + StartPos: 3285, + EndPos: 3288, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 154, @@ -8553,24 +8553,34 @@ func TestPhp5(t *testing.T) { EndPos: 3288, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 154, - EndLine: 154, - StartPos: 3285, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 155, @@ -8579,17 +8589,17 @@ func TestPhp5(t *testing.T) { EndPos: 3299, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 155, - EndLine: 155, - StartPos: 3295, - EndPos: 3298, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 155, + EndLine: 155, + StartPos: 3295, + EndPos: 3298, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 155, @@ -8598,24 +8608,34 @@ func TestPhp5(t *testing.T) { EndPos: 3298, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 155, - EndLine: 155, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 156, @@ -8624,54 +8644,64 @@ func TestPhp5(t *testing.T) { EndPos: 3316, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 156, - EndLine: 156, - StartPos: 3305, - EndPos: 3315, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 156, + EndLine: 156, + StartPos: 3305, + EndPos: 3315, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 157, @@ -8680,17 +8710,17 @@ func TestPhp5(t *testing.T) { EndPos: 3330, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3321, - EndPos: 3324, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 157, + EndLine: 157, + StartPos: 3321, + EndPos: 3329, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 157, @@ -8699,31 +8729,31 @@ func TestPhp5(t *testing.T) { EndPos: 3324, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3321, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 157, - EndLine: 157, - StartPos: 3326, - EndPos: 3329, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 157, @@ -8732,24 +8762,34 @@ func TestPhp5(t *testing.T) { EndPos: 3329, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - 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, + 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"), }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 158, @@ -8758,17 +8798,17 @@ func TestPhp5(t *testing.T) { EndPos: 3351, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3335, - EndPos: 3338, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 158, + EndLine: 158, + StartPos: 3335, + EndPos: 3350, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 158, @@ -8777,68 +8817,78 @@ func TestPhp5(t *testing.T) { EndPos: 3338, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3335, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 158, - EndLine: 158, - StartPos: 3340, - EndPos: 3350, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, @@ -8847,38 +8897,46 @@ func TestPhp5(t *testing.T) { EndPos: 3375, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, EndLine: 159, StartPos: 3356, - EndPos: 3364, + EndPos: 3374, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3356, + EndPos: 3364, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, EndLine: 159, StartPos: 3365, - EndPos: 3368, + EndPos: 3374, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3365, - EndPos: 3368, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3365, + EndPos: 3368, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, @@ -8887,31 +8945,31 @@ func TestPhp5(t *testing.T) { EndPos: 3368, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3365, + EndPos: 3368, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3371, - EndPos: 3374, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 159, - EndLine: 159, - StartPos: 3371, - EndPos: 3374, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3371, + EndPos: 3374, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 159, @@ -8920,14 +8978,26 @@ func TestPhp5(t *testing.T) { EndPos: 3374, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 159, + EndLine: 159, + StartPos: 3371, + EndPos: 3374, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, @@ -8936,38 +9006,46 @@ func TestPhp5(t *testing.T) { EndPos: 3413, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, EndLine: 160, StartPos: 3380, - EndPos: 3388, + EndPos: 3412, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3380, + EndPos: 3388, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, EndLine: 160, StartPos: 3389, - EndPos: 3399, + EndPos: 3412, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3389, - EndPos: 3392, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3389, + EndPos: 3399, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, @@ -8976,42 +9054,42 @@ func TestPhp5(t *testing.T) { EndPos: 3392, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3396, - EndPos: 3399, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 160, + EndLine: 160, + StartPos: 3402, + EndPos: 3412, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3402, - EndPos: 3412, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3402, - EndPos: 3405, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 160, @@ -9020,25 +9098,37 @@ func TestPhp5(t *testing.T) { EndPos: 3405, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 160, - EndLine: 160, - StartPos: 3409, - EndPos: 3412, - }, - }, - Value: []byte("bar"), - }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9047,38 +9137,46 @@ func TestPhp5(t *testing.T) { EndPos: 3434, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, EndLine: 161, StartPos: 3418, - EndPos: 3423, + EndPos: 3433, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3418, + EndPos: 3423, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, EndLine: 161, StartPos: 3424, - EndPos: 3427, + EndPos: 3433, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3424, - EndPos: 3427, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3424, + EndPos: 3427, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9087,31 +9185,31 @@ func TestPhp5(t *testing.T) { EndPos: 3427, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3424, + EndPos: 3427, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3430, - EndPos: 3433, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3430, - EndPos: 3433, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3430, + EndPos: 3433, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9120,14 +9218,26 @@ func TestPhp5(t *testing.T) { EndPos: 3433, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3430, + EndPos: 3433, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9136,38 +9246,46 @@ func TestPhp5(t *testing.T) { EndPos: 3469, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, EndLine: 162, StartPos: 3439, - EndPos: 3444, + EndPos: 3468, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3439, + EndPos: 3444, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, EndLine: 162, StartPos: 3445, - EndPos: 3455, + EndPos: 3468, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3445, - EndPos: 3448, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3445, + EndPos: 3455, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9176,42 +9294,42 @@ func TestPhp5(t *testing.T) { EndPos: 3448, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3452, - EndPos: 3455, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3458, + EndPos: 3468, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3458, - EndPos: 3468, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3458, - EndPos: 3461, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9220,21 +9338,33 @@ func TestPhp5(t *testing.T) { EndPos: 3461, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - 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 47a0eca..22f0676 100644 --- a/internal/php7/parser_test.go +++ b/internal/php7/parser_test.go @@ -12422,7 +12422,7 @@ func TestStmtUse(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12431,17 +12431,17 @@ func TestStmtUse(t *testing.T) { EndPos: 11, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12450,17 +12450,27 @@ func TestStmtUse(t *testing.T) { EndPos: 10, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, @@ -12490,7 +12500,7 @@ func TestStmtUse_FullyQualified(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12499,17 +12509,17 @@ func TestStmtUse_FullyQualified(t *testing.T) { EndPos: 12, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 11, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 11, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12518,17 +12528,27 @@ func TestStmtUse_FullyQualified(t *testing.T) { EndPos: 11, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, @@ -12558,7 +12578,7 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12567,49 +12587,59 @@ func TestStmtUse_FullyQualifiedAlias(t *testing.T) { EndPos: 19, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 8, - EndPos: 18, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 8, + EndPos: 18, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, @@ -12637,7 +12667,7 @@ func TestStmtUse_List(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12646,17 +12676,17 @@ func TestStmtUse_List(t *testing.T) { EndPos: 16, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12665,31 +12695,31 @@ func TestStmtUse_List(t *testing.T) { EndPos: 10, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12698,17 +12728,27 @@ func TestStmtUse_List(t *testing.T) { EndPos: 15, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - 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, + }, + }, + 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"), }, }, }, @@ -12738,7 +12778,7 @@ func TestStmtUse_ListAlias(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12747,17 +12787,17 @@ func TestStmtUse_ListAlias(t *testing.T) { EndPos: 23, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 22, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12766,63 +12806,73 @@ func TestStmtUse_ListAlias(t *testing.T) { EndPos: 10, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 22, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, @@ -12850,7 +12900,7 @@ func TestStmtUse_ListFunctionType(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12859,38 +12909,46 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 26, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 15, + EndPos: 25, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 19, + EndPos: 25, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12899,31 +12957,31 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 19, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 19, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 22, - EndPos: 25, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 22, - EndPos: 25, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 22, + EndPos: 25, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12932,7 +12990,19 @@ func TestStmtUse_ListFunctionType(t *testing.T) { EndPos: 25, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 22, + EndPos: 25, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, @@ -12962,7 +13032,7 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -12971,38 +13041,46 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 40, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 15, + EndPos: 39, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 16, - EndPos: 26, + EndPos: 39, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 26, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13011,42 +13089,42 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 19, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 26, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 29, + EndPos: 39, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 39, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 29, - EndPos: 32, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13055,21 +13133,33 @@ func TestStmtUse_ListFunctionTypeAliases(t *testing.T) { EndPos: 32, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 36, - EndPos: 39, - }, - }, - Value: []byte("bar"), - }, }, }, }, @@ -13096,7 +13186,7 @@ func TestStmtUse_ListConstType(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13105,38 +13195,47 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 23, }, }, - UseType: &ast.Identifier{ + + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 12, + EndPos: 22, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 12, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 16, + EndPos: 22, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13145,31 +13244,31 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 16, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 16, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - 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: 19, - EndPos: 22, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 22, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13178,7 +13277,19 @@ func TestStmtUse_ListConstType(t *testing.T) { EndPos: 22, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 19, + EndPos: 22, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, @@ -13208,7 +13319,7 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13217,38 +13328,46 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 37, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 12, + EndPos: 36, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 12, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 13, - EndPos: 23, + EndPos: 36, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 23, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13257,42 +13376,42 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 16, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 20, - EndPos: 23, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 26, + EndPos: 36, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 36, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 26, - EndPos: 29, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13301,21 +13420,33 @@ func TestStmtUse_ListConstTypeAliases(t *testing.T) { EndPos: 29, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 33, - EndPos: 36, - }, - }, - Value: []byte("bar"), - }, }, }, }, @@ -13342,7 +13473,7 @@ func TestStmtUse_GroupUse(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13351,50 +13482,58 @@ func TestStmtUse_GroupUse(t *testing.T) { EndPos: 22, }, }, - Prefix: &ast.NameName{ + UseList: &ast.StmtGroupUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 10, + EndPos: 21, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, - EndPos: 15, + EndPos: 20, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13403,31 +13542,31 @@ func TestStmtUse_GroupUse(t *testing.T) { EndPos: 15, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - 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, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 20, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13436,7 +13575,19 @@ func TestStmtUse_GroupUse(t *testing.T) { EndPos: 20, }, }, - Value: []byte("Baz"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 20, + }, + }, + Value: []byte("Baz"), + }, + }, }, }, }, @@ -13466,7 +13617,7 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13475,50 +13626,58 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { EndPos: 30, }, }, - Prefix: &ast.NameName{ + UseList: &ast.StmtGroupUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 10, + EndPos: 29, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 12, - EndPos: 15, + EndPos: 28, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 15, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13527,31 +13686,31 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { EndPos: 15, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 15, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - 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, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 17, + EndPos: 28, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13560,21 +13719,33 @@ func TestStmtUse_GroupUseAlias(t *testing.T) { EndPos: 20, }, }, - Value: []byte("Baz"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 24, - EndPos: 28, - }, - }, - Value: []byte("quux"), - }, }, }, }, @@ -13601,7 +13772,7 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13610,28 +13781,36 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 31, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 15, + EndPos: 30, }, }, - Value: []byte("function"), - }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 16, - EndPos: 19, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 15, + }, }, + Value: []byte("function"), }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.StmtGroupUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 16, + EndPos: 30, + }, + }, + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13640,31 +13819,31 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 19, }, }, - Value: []byte("Foo"), - }, - }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ - 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: 16, + EndPos: 19, + }, + }, + Value: []byte("Foo"), + }, }, }, - Use: &ast.NameName{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 21, - EndPos: 24, + EndPos: 29, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13673,31 +13852,31 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 24, }, }, - Value: []byte("Bar"), + 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"), + }, + }, + }, }, - }, - }, - }, - &ast.StmtUse{ - 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{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13706,7 +13885,29 @@ func TestStmtUse_FunctionGroupUse(t *testing.T) { EndPos: 29, }, }, - Value: []byte("Baz"), + 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"), + }, + }, + }, }, }, }, @@ -13736,7 +13937,7 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13745,28 +13946,36 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 28, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 12, + EndPos: 27, }, }, - Value: []byte("const"), - }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 13, - EndPos: 16, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 12, + }, }, + Value: []byte("const"), }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.StmtGroupUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 13, + EndPos: 27, + }, + }, + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13775,31 +13984,31 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 16, }, }, - Value: []byte("Foo"), - }, - }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ - 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: 13, + EndPos: 16, + }, + }, + Value: []byte("Foo"), + }, }, }, - Use: &ast.NameName{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 18, - EndPos: 21, + EndPos: 26, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13808,31 +14017,31 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 21, }, }, - Value: []byte("Bar"), + 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"), + }, + }, + }, }, - }, - }, - }, - &ast.StmtUse{ - 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{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13841,7 +14050,29 @@ func TestStmtUse_ConstGroupUse(t *testing.T) { EndPos: 26, }, }, - Value: []byte("Baz"), + 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"), + }, + }, + }, }, }, }, @@ -13871,7 +14102,7 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { }, }, Stmts: []ast.Vertex{ - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13880,61 +14111,69 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { EndPos: 37, }, }, - Prefix: &ast.NameName{ + UseList: &ast.StmtGroupUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, StartPos: 7, - EndPos: 10, + EndPos: 36, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 7, - EndPos: 10, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, EndLine: 1, - StartPos: 18, - EndPos: 21, + StartPos: 7, + EndPos: 10, }, }, - UseType: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 12, - EndPos: 17, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 7, + EndPos: 10, + }, }, + Value: []byte("Foo"), }, - Value: []byte("const"), }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 18, - EndPos: 21, - }, + }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 12, + EndPos: 35, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + }, + 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, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13943,42 +14182,52 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { EndPos: 21, }, }, - Value: []byte("Bar"), + 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"), + }, + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 32, - EndPos: 35, - }, - }, - UseType: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 23, - EndPos: 31, + &ast.StmtUseType{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 35, + }, }, - }, - Value: []byte("function"), - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 1, - EndLine: 1, - StartPos: 32, - EndPos: 35, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 1, + EndLine: 1, + StartPos: 23, + EndPos: 31, + }, + }, + Value: []byte("function"), }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -13987,7 +14236,29 @@ func TestStmtUse_MixedGroupUse(t *testing.T) { EndPos: 35, }, }, - Value: []byte("Baz"), + 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"), + }, + }, + }, }, }, }, diff --git a/internal/php7/php7.go b/internal/php7/php7.go index e54c1a7..33a3f5e 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 c65b0f9..752de40 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -528,58 +528,61 @@ top_statement: } | T_USE mixed_group_use_declaration ';' { - $$ = $2 + $$ = &ast.StmtUse{ast.Node{}, $2} // save position $$.GetNode().Position = position.NewTokensPosition($1, $3) // save comments yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $3.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $3.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | T_USE use_type group_use_declaration ';' { - $3.(*ast.StmtGroupUse).UseType = $2 - $$ = $3 + useType := &ast.StmtUseType{ast.Node{}, $2, $3} + $$ = &ast.StmtUse{ast.Node{}, useType} // save position + useType.GetNode().Position = position.NewNodesPosition($2, $3) $$.GetNode().Position = position.NewTokensPosition($1, $4) // save comments yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $4.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $4.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | T_USE use_declarations ';' { - $$ = &ast.StmtUseList{ast.Node{}, nil, $2} + 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.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $3.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $3.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | T_USE use_type use_declarations ';' { - $$ = &ast.StmtUseList{ast.Node{}, $2, $3} + 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.Tokens) - yylex.(*Parser).setFreeFloating($$, token.UseDeclarationList, $4.Tokens) - yylex.(*Parser).setToken($$, token.SemiColon, $4.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.End, $4.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -630,20 +633,20 @@ group_use_declaration: namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}' { name := &ast.NameName{ast.Node{}, $1} - $$ = &ast.StmtGroupUse{ast.Node{}, nil, name, $4} + useList := &ast.StmtUseList{ast.Node{}, $4} + $$ = &ast.StmtGroupUseList{ast.Node{}, name, useList} // save position name.GetNode().Position = position.NewNodeListPosition($1) + useList.GetNode().Position = position.NewNodeListPosition($4) $$.GetNode().Position = position.NewNodeListTokenPosition($1, $6) // save comments - yylex.(*Parser).MoveFreeFloating($1[0], name) - yylex.(*Parser).setFreeFloating(name, token.End, $2.Tokens) - yylex.(*Parser).setFreeFloating($$, token.Slash, $3.Tokens) + yylex.(*Parser).setFreeFloatingTokens(useList, token.Start, append($2.Tokens, $3.Tokens...)) if $5 != nil { - yylex.(*Parser).setFreeFloating($$, token.Stmts, append($5.Tokens, $6.Tokens...)) + yylex.(*Parser).setFreeFloatingTokens(useList, token.End, append($5.Tokens, $6.Tokens...)) } else { - yylex.(*Parser).setFreeFloating($$, token.Stmts, $6.Tokens) + yylex.(*Parser).setFreeFloating(useList, token.End, $6.Tokens) } yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) @@ -651,22 +654,22 @@ group_use_declaration: | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}' { name := &ast.NameName{ast.Node{}, $2} - $$ = &ast.StmtGroupUse{ast.Node{}, nil, name, $5} + useList := &ast.StmtUseList{ast.Node{}, $5} + $$ = &ast.StmtGroupUseList{ast.Node{}, name, useList} // save position name.GetNode().Position = position.NewNodeListPosition($2) + useList.GetNode().Position = position.NewNodeListPosition($5) $$.GetNode().Position = position.NewTokensPosition($1, $7) // save comments - yylex.(*Parser).setFreeFloating($$, token.UseType, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) - yylex.(*Parser).setFreeFloating(name, token.End, $3.Tokens) - yylex.(*Parser).setFreeFloating($$, token.Slash, $4.Tokens) + yylex.(*Parser).setFreeFloatingTokens(useList, token.Start, append($3.Tokens, $4.Tokens...)) if $6 != nil { - yylex.(*Parser).setFreeFloating($$, token.Stmts, append($6.Tokens, $7.Tokens...)) + yylex.(*Parser).setFreeFloatingTokens(useList, token.End, append($6.Tokens, $7.Tokens...)) } else { - yylex.(*Parser).setFreeFloating($$, token.Stmts, $7.Tokens) + yylex.(*Parser).setFreeFloating(useList, token.End, $7.Tokens) } + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -676,20 +679,20 @@ mixed_group_use_declaration: namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' { name := &ast.NameName{ast.Node{}, $1} - $$ = &ast.StmtGroupUse{ast.Node{}, nil, name, $4} + useList := &ast.StmtUseList{ast.Node{}, $4} + $$ = &ast.StmtGroupUseList{ast.Node{}, name, useList} // save position name.GetNode().Position = position.NewNodeListPosition($1) + useList.GetNode().Position = position.NewNodeListPosition($4) $$.GetNode().Position = position.NewNodeListTokenPosition($1, $6) // save comments - yylex.(*Parser).MoveFreeFloating($1[0], name) - yylex.(*Parser).setFreeFloating(name, token.End, $2.Tokens) - yylex.(*Parser).setFreeFloating($$, token.Slash, $3.Tokens) + yylex.(*Parser).setFreeFloatingTokens(useList, token.Start, append($2.Tokens, $3.Tokens...)) if $5 != nil { - yylex.(*Parser).setFreeFloating($$, token.Stmts, append($5.Tokens, $6.Tokens...)) + yylex.(*Parser).setFreeFloatingTokens(useList, token.End, append($5.Tokens, $6.Tokens...)) } else { - yylex.(*Parser).setFreeFloating($$, token.Stmts, $6.Tokens) + yylex.(*Parser).setFreeFloatingTokens(useList, token.End, $6.Tokens) } yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) @@ -697,22 +700,22 @@ mixed_group_use_declaration: | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' { name := &ast.NameName{ast.Node{}, $2} - $$ = &ast.StmtGroupUse{ast.Node{}, nil, name, $5} + useList := &ast.StmtUseList{ast.Node{}, $5} + $$ = &ast.StmtGroupUseList{ast.Node{}, name, useList} // save position name.GetNode().Position = position.NewNodeListPosition($2) + useList.GetNode().Position = position.NewNodeListPosition($5) $$.GetNode().Position = position.NewTokensPosition($1, $7) // save comments - yylex.(*Parser).setFreeFloatingTokens($$, token.Use, $1.Tokens) - yylex.(*Parser).MoveFreeFloating($2[0], name) - yylex.(*Parser).setFreeFloating(name, token.End, $3.Tokens) - yylex.(*Parser).setFreeFloating($$, token.Slash, $4.Tokens) + yylex.(*Parser).setFreeFloatingTokens(useList, token.Start, append($3.Tokens, $4.Tokens...)) if $6 != nil { - yylex.(*Parser).setFreeFloating($$, token.Stmts, append($6.Tokens, $7.Tokens...)) + yylex.(*Parser).setFreeFloatingTokens(useList, token.End, append($6.Tokens, $7.Tokens...)) } else { - yylex.(*Parser).setFreeFloating($$, token.Stmts, $7.Tokens) + yylex.(*Parser).setFreeFloating(useList, token.End, $7.Tokens) } + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -792,8 +795,10 @@ inline_use_declaration: } | use_type unprefixed_use_declaration { - $2.(*ast.StmtUse).UseType = $1 - $$ = $2 + $$ = &ast.StmtUseType{ast.Node{}, $1, $2} + + // save position + $$.GetNode().Position = position.NewNodesPosition($1, $2) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -803,14 +808,11 @@ unprefixed_use_declaration: namespace_name { name := &ast.NameName{ast.Node{}, $1} - $$ = &ast.StmtUse{ast.Node{}, nil, name, nil} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, nil} // save position name.GetNode().Position = position.NewNodeListPosition($1) - $$.GetNode().Position = position.NewNodeListPosition($1) - - // save comments - yylex.(*Parser).MoveFreeFloating($1[0], name) + $$.GetNode().Position = position.NewNodePosition(name) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } @@ -818,7 +820,7 @@ unprefixed_use_declaration: { name := &ast.NameName{ast.Node{}, $1} alias := &ast.Identifier{ast.Node{}, $3.Value} - $$ = &ast.StmtUse{ast.Node{}, nil, name, alias} + $$ = &ast.StmtUseDeclaration{ast.Node{}, name, alias} // save position name.GetNode().Position = position.NewNodeListPosition($1) @@ -826,7 +828,6 @@ unprefixed_use_declaration: $$.GetNode().Position = position.NewNodeListTokenPosition($1, $3) // save comments - yylex.(*Parser).MoveFreeFloating($1[0], name) yylex.(*Parser).setFreeFloating(name, token.End, $2.Tokens) yylex.(*Parser).setFreeFloating(alias, token.Start, $3.Tokens) @@ -839,9 +840,6 @@ use_declaration: { $$ = $1 - // save coments - yylex.(*Parser).MoveFreeFloating($1.(*ast.StmtUse).Use, $$) - yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } | T_NS_SEPARATOR unprefixed_use_declaration @@ -849,8 +847,7 @@ use_declaration: $$ = $2; // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) - yylex.(*Parser).setToken($$, token.Slash, $1.Tokens) + yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) } diff --git a/internal/php7/php7_test.go b/internal/php7/php7_test.go index 88589ee..27e217a 100644 --- a/internal/php7/php7_test.go +++ b/internal/php7/php7_test.go @@ -9013,7 +9013,7 @@ func TestPhp7(t *testing.T) { }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9022,17 +9022,17 @@ func TestPhp7(t *testing.T) { EndPos: 3370, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3366, - EndPos: 3369, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 161, + EndLine: 161, + StartPos: 3366, + EndPos: 3369, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 161, @@ -9041,24 +9041,34 @@ func TestPhp7(t *testing.T) { EndPos: 3369, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 161, - EndLine: 161, - StartPos: 3366, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9067,17 +9077,17 @@ func TestPhp7(t *testing.T) { EndPos: 3380, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - StartPos: 3376, - EndPos: 3379, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 162, + EndLine: 162, + StartPos: 3376, + EndPos: 3379, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 162, @@ -9086,24 +9096,34 @@ func TestPhp7(t *testing.T) { EndPos: 3379, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 162, - EndLine: 162, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 163, @@ -9112,54 +9132,64 @@ func TestPhp7(t *testing.T) { EndPos: 3397, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 163, - EndLine: 163, - StartPos: 3386, - EndPos: 3396, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 163, + EndLine: 163, + StartPos: 3386, + EndPos: 3396, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 164, @@ -9168,17 +9198,17 @@ func TestPhp7(t *testing.T) { EndPos: 3411, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3402, - EndPos: 3405, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 164, + EndLine: 164, + StartPos: 3402, + EndPos: 3410, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 164, @@ -9187,31 +9217,31 @@ func TestPhp7(t *testing.T) { EndPos: 3405, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3402, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 164, - EndLine: 164, - StartPos: 3407, - EndPos: 3410, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 164, @@ -9220,24 +9250,34 @@ func TestPhp7(t *testing.T) { EndPos: 3410, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - 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, + 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"), }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 165, @@ -9246,17 +9286,17 @@ func TestPhp7(t *testing.T) { EndPos: 3432, }, }, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3416, - EndPos: 3419, - }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 165, + EndLine: 165, + StartPos: 3416, + EndPos: 3431, }, - Use: &ast.NameName{ + }, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 165, @@ -9265,68 +9305,78 @@ func TestPhp7(t *testing.T) { EndPos: 3419, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3416, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 165, - EndLine: 165, - StartPos: 3421, - EndPos: 3431, - }, - }, - Use: &ast.NameName{ + &ast.StmtUseDeclaration{ 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"), + 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"), + }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, @@ -9335,38 +9385,46 @@ func TestPhp7(t *testing.T) { EndPos: 3456, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, EndLine: 166, StartPos: 3437, - EndPos: 3445, + EndPos: 3455, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3437, + EndPos: 3445, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, EndLine: 166, StartPos: 3446, - EndPos: 3449, + EndPos: 3455, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3446, - EndPos: 3449, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3446, + EndPos: 3449, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, @@ -9375,31 +9433,31 @@ func TestPhp7(t *testing.T) { EndPos: 3449, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3446, + EndPos: 3449, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3452, - EndPos: 3455, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 166, - EndLine: 166, - StartPos: 3452, - EndPos: 3455, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3452, + EndPos: 3455, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 166, @@ -9408,14 +9466,26 @@ func TestPhp7(t *testing.T) { EndPos: 3455, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 166, + EndLine: 166, + StartPos: 3452, + EndPos: 3455, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, @@ -9424,38 +9494,46 @@ func TestPhp7(t *testing.T) { EndPos: 3494, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, EndLine: 167, StartPos: 3461, - EndPos: 3469, + EndPos: 3493, }, }, - Value: []byte("function"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3461, + EndPos: 3469, + }, + }, + Value: []byte("function"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, EndLine: 167, StartPos: 3470, - EndPos: 3480, + EndPos: 3493, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3470, - EndPos: 3473, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3470, + EndPos: 3480, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, @@ -9464,42 +9542,42 @@ func TestPhp7(t *testing.T) { EndPos: 3473, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3477, - EndPos: 3480, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 167, + EndLine: 167, + StartPos: 3483, + EndPos: 3493, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3483, - EndPos: 3493, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3483, - EndPos: 3486, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 167, @@ -9508,25 +9586,37 @@ func TestPhp7(t *testing.T) { EndPos: 3486, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 167, - EndLine: 167, - StartPos: 3490, - EndPos: 3493, - }, - }, - Value: []byte("bar"), - }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, @@ -9535,38 +9625,46 @@ func TestPhp7(t *testing.T) { EndPos: 3515, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, EndLine: 168, StartPos: 3499, - EndPos: 3504, + EndPos: 3514, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3499, + EndPos: 3504, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, EndLine: 168, StartPos: 3505, - EndPos: 3508, + EndPos: 3514, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3505, - EndPos: 3508, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3505, + EndPos: 3508, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, @@ -9575,31 +9673,31 @@ func TestPhp7(t *testing.T) { EndPos: 3508, }, }, - Value: []byte("Foo"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3505, + EndPos: 3508, + }, + }, + Value: []byte("Foo"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3511, - EndPos: 3514, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 168, - EndLine: 168, - StartPos: 3511, - EndPos: 3514, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3511, + EndPos: 3514, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 168, @@ -9608,14 +9706,26 @@ func TestPhp7(t *testing.T) { EndPos: 3514, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 168, + EndLine: 168, + StartPos: 3511, + EndPos: 3514, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, }, }, }, }, - &ast.StmtUseList{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, @@ -9624,38 +9734,46 @@ func TestPhp7(t *testing.T) { EndPos: 3550, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, EndLine: 169, StartPos: 3520, - EndPos: 3525, + EndPos: 3549, }, }, - Value: []byte("const"), - }, - Uses: []ast.Vertex{ - &ast.StmtUse{ + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3520, + EndPos: 3525, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, EndLine: 169, StartPos: 3526, - EndPos: 3536, + EndPos: 3549, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3526, - EndPos: 3529, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3526, + EndPos: 3536, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, @@ -9664,42 +9782,42 @@ func TestPhp7(t *testing.T) { EndPos: 3529, }, }, - Value: []byte("Foo"), + 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"), }, }, - }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3533, - EndPos: 3536, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 169, + EndLine: 169, + StartPos: 3539, + EndPos: 3549, + }, }, - }, - Value: []byte("foo"), - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3539, - EndPos: 3549, - }, - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3539, - EndPos: 3542, - }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 169, @@ -9708,25 +9826,37 @@ func TestPhp7(t *testing.T) { EndPos: 3542, }, }, - Value: []byte("Bar"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 169, - EndLine: 169, - StartPos: 3546, - EndPos: 3549, - }, - }, - Value: []byte("bar"), - }, }, }, }, - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, @@ -9735,50 +9865,58 @@ func TestPhp7(t *testing.T) { EndPos: 3572, }, }, - Prefix: &ast.NameName{ + UseList: &ast.StmtGroupUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, EndLine: 171, - StartPos: 3557, - EndPos: 3560, + StartPos: 3556, + EndPos: 3571, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, EndLine: 171, StartPos: 3562, - EndPos: 3565, + EndPos: 3570, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 171, - EndLine: 171, - StartPos: 3562, - EndPos: 3565, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3562, + EndPos: 3565, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, @@ -9787,31 +9925,31 @@ func TestPhp7(t *testing.T) { EndPos: 3565, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3562, + EndPos: 3565, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - 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, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3567, + EndPos: 3570, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 171, @@ -9820,14 +9958,26 @@ func TestPhp7(t *testing.T) { EndPos: 3570, }, }, - Value: []byte("Baz"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 171, + EndLine: 171, + StartPos: 3567, + EndPos: 3570, + }, + }, + Value: []byte("Baz"), + }, + }, }, }, }, }, }, }, - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, @@ -9836,50 +9986,58 @@ func TestPhp7(t *testing.T) { EndPos: 3600, }, }, - Prefix: &ast.NameName{ + UseList: &ast.StmtGroupUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, EndLine: 172, StartPos: 3577, - EndPos: 3580, + EndPos: 3599, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3577, - 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, + }, + }, + Value: []byte("Foo"), }, - Value: []byte("Foo"), }, }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, EndLine: 172, StartPos: 3582, - EndPos: 3585, + EndPos: 3598, }, }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3582, - EndPos: 3585, + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3582, + EndPos: 3585, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, @@ -9888,31 +10046,31 @@ func TestPhp7(t *testing.T) { EndPos: 3585, }, }, - Value: []byte("Bar"), + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3582, + EndPos: 3585, + }, + }, + Value: []byte("Bar"), + }, + }, }, }, - }, - }, - &ast.StmtUse{ - 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, + &ast.StmtUseDeclaration{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 172, + EndLine: 172, + StartPos: 3587, + EndPos: 3598, + }, }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 172, @@ -9921,25 +10079,37 @@ func TestPhp7(t *testing.T) { EndPos: 3590, }, }, - Value: []byte("Baz"), + 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"), }, }, }, - Alias: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 172, - EndLine: 172, - StartPos: 3594, - EndPos: 3598, - }, - }, - Value: []byte("quux"), - }, }, }, }, - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -9948,28 +10118,36 @@ func TestPhp7(t *testing.T) { EndPos: 3629, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, EndLine: 173, StartPos: 3605, - EndPos: 3613, + EndPos: 3628, }, }, - Value: []byte("function"), - }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 173, - EndLine: 173, - StartPos: 3614, - EndPos: 3617, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 173, + EndLine: 173, + StartPos: 3605, + EndPos: 3613, + }, }, + Value: []byte("function"), }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.StmtGroupUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 173, + EndLine: 173, + StartPos: 3614, + EndPos: 3628, + }, + }, + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -9978,31 +10156,31 @@ func TestPhp7(t *testing.T) { EndPos: 3617, }, }, - Value: []byte("Foo"), - }, - }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ - 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: 3614, + EndPos: 3617, + }, + }, + Value: []byte("Foo"), + }, }, }, - Use: &ast.NameName{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, EndLine: 173, StartPos: 3619, - EndPos: 3622, + EndPos: 3627, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -10011,31 +10189,31 @@ func TestPhp7(t *testing.T) { EndPos: 3622, }, }, - Value: []byte("Bar"), + 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"), + }, + }, + }, }, - }, - }, - }, - &ast.StmtUse{ - 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{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 173, @@ -10044,14 +10222,36 @@ func TestPhp7(t *testing.T) { EndPos: 3627, }, }, - Value: []byte("Baz"), + 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"), + }, + }, + }, }, }, }, }, }, }, - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10060,28 +10260,36 @@ func TestPhp7(t *testing.T) { EndPos: 3656, }, }, - UseType: &ast.Identifier{ + UseList: &ast.StmtUseType{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, EndLine: 174, StartPos: 3634, - EndPos: 3639, + EndPos: 3655, }, }, - Value: []byte("const"), - }, - Prefix: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 174, - EndLine: 174, - StartPos: 3641, - EndPos: 3644, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 174, + EndLine: 174, + StartPos: 3634, + EndPos: 3639, + }, }, + Value: []byte("const"), }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.StmtGroupUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 174, + EndLine: 174, + StartPos: 3640, + EndPos: 3655, + }, + }, + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10090,31 +10298,31 @@ func TestPhp7(t *testing.T) { EndPos: 3644, }, }, - Value: []byte("Foo"), - }, - }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ - 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: 3641, + EndPos: 3644, + }, + }, + Value: []byte("Foo"), + }, }, }, - Use: &ast.NameName{ + UseList: &ast.StmtUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, EndLine: 174, StartPos: 3646, - EndPos: 3649, + EndPos: 3654, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10123,31 +10331,31 @@ func TestPhp7(t *testing.T) { EndPos: 3649, }, }, - Value: []byte("Bar"), + 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"), + }, + }, + }, }, - }, - }, - }, - &ast.StmtUse{ - 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{ + &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 174, @@ -10156,14 +10364,36 @@ func TestPhp7(t *testing.T) { EndPos: 3654, }, }, - Value: []byte("Baz"), + 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"), + }, + }, + }, }, }, }, }, }, }, - &ast.StmtGroupUse{ + &ast.StmtUse{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, @@ -10172,61 +10402,69 @@ func TestPhp7(t *testing.T) { EndPos: 3691, }, }, - Prefix: &ast.NameName{ + UseList: &ast.StmtGroupUseList{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, EndLine: 175, StartPos: 3661, - EndPos: 3664, + EndPos: 3690, }, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3661, - EndPos: 3664, - }, - }, - Value: []byte("Foo"), - }, - }, - }, - UseList: []ast.Vertex{ - &ast.StmtUse{ + Prefix: &ast.NameName{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, EndLine: 175, - StartPos: 3672, - EndPos: 3675, + StartPos: 3661, + EndPos: 3664, }, }, - UseType: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3666, - EndPos: 3671, + Parts: []ast.Vertex{ + &ast.NameNamePart{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3661, + EndPos: 3664, + }, }, + Value: []byte("Foo"), }, - Value: []byte("const"), }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3672, - EndPos: 3675, - }, + }, + UseList: &ast.StmtUseList{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3666, + EndPos: 3689, }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + }, + 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, + }, + }, + Value: []byte("const"), + }, + Use: &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, @@ -10235,42 +10473,52 @@ func TestPhp7(t *testing.T) { EndPos: 3675, }, }, - Value: []byte("Bar"), + 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"), + }, + }, + }, }, }, - }, - }, - &ast.StmtUse{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3686, - EndPos: 3689, - }, - }, - UseType: &ast.Identifier{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3677, - EndPos: 3685, + &ast.StmtUseType{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3677, + EndPos: 3689, + }, }, - }, - Value: []byte("function"), - }, - Use: &ast.NameName{ - Node: ast.Node{ - Position: &position.Position{ - StartLine: 175, - EndLine: 175, - StartPos: 3686, - EndPos: 3689, + Type: &ast.Identifier{ + Node: ast.Node{ + Position: &position.Position{ + StartLine: 175, + EndLine: 175, + StartPos: 3677, + EndPos: 3685, + }, + }, + Value: []byte("function"), }, - }, - Parts: []ast.Vertex{ - &ast.NameNamePart{ + Use: &ast.StmtUseDeclaration{ Node: ast.Node{ Position: &position.Position{ StartLine: 175, @@ -10279,7 +10527,29 @@ func TestPhp7(t *testing.T) { EndPos: 3689, }, }, - Value: []byte("Baz"), + 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"), + }, + }, + }, }, }, }, diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 41b540b..4513b11 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -59,7 +59,6 @@ type NodeVisitor interface { StmtFunction(n *StmtFunction) StmtGlobal(n *StmtGlobal) StmtGoto(n *StmtGoto) - StmtGroupUse(n *StmtGroupUse) StmtHaltCompiler(n *StmtHaltCompiler) StmtIf(n *StmtIf) StmtInlineHtml(n *StmtInlineHtml) @@ -85,7 +84,10 @@ type NodeVisitor interface { StmtTry(n *StmtTry) StmtUnset(n *StmtUnset) StmtUse(n *StmtUse) + StmtGroupUseList(n *StmtGroupUseList) StmtUseList(n *StmtUseList) + 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 0435c7c..b609578 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -532,18 +532,6 @@ func (n *StmtGoto) Accept(v NodeVisitor) { v.StmtGoto(n) } -// StmtGroupUse node -type StmtGroupUse struct { - Node - UseType Vertex - Prefix Vertex - UseList []Vertex -} - -func (n *StmtGroupUse) Accept(v NodeVisitor) { - v.StmtGroupUse(n) -} - // StmtHaltCompiler node type StmtHaltCompiler struct { Node @@ -804,26 +792,56 @@ func (n *StmtUnset) Accept(v NodeVisitor) { // StmtUse node type StmtUse struct { Node - UseType Vertex - Use Vertex - Alias Vertex + UseList Vertex } func (n *StmtUse) Accept(v NodeVisitor) { v.StmtUse(n) } +// StmtGroupUseList node +type StmtGroupUseList struct { + Node + Prefix Vertex + UseList Vertex +} + +func (n *StmtGroupUseList) Accept(v NodeVisitor) { + v.StmtGroupUseList(n) +} + // StmtUseList node type StmtUseList struct { Node - UseType Vertex - Uses []Vertex + UseDeclarations []Vertex } func (n *StmtUseList) Accept(v NodeVisitor) { v.StmtUseList(n) } +// StmtUseDeclaration node +type StmtUseDeclaration struct { + Node + Use Vertex + Alias Vertex +} + +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 d25b426..a71c83b 100644 --- a/pkg/ast/traverser/dfs.go +++ b/pkg/ast/traverser/dfs.go @@ -745,30 +745,6 @@ func (t *DFS) Traverse(n ast.Vertex) { t.Traverse(nn.Label) t.visitor.Leave("Label", true) } - case *ast.StmtGroupUse: - if nn == nil { - return - } - if !t.visitor.EnterNode(nn) { - return - } - if nn.UseType != nil { - t.visitor.Enter("UseType", true) - t.Traverse(nn.UseType) - t.visitor.Leave("UseType", 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", false) - for _, c := range nn.UseList { - t.Traverse(c) - } - t.visitor.Leave("UseList", false) - } case *ast.StmtHaltCompiler: if nn == nil { return @@ -1174,10 +1150,48 @@ func (t *DFS) Traverse(n ast.Vertex) { if !t.visitor.EnterNode(nn) { return } - if nn.UseType != nil { - t.visitor.Enter("UseType", true) - t.Traverse(nn.UseType) - t.visitor.Leave("UseType", true) + if nn.UseList != nil { + t.visitor.Enter("UseList", true) + t.Traverse(nn.UseList) + t.visitor.Leave("UseList", true) + } + case *ast.StmtGroupUseList: + if nn == nil { + return + } + if !t.visitor.EnterNode(nn) { + return + } + 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 { + t.Traverse(c) + } + 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) @@ -1189,24 +1203,22 @@ func (t *DFS) Traverse(n ast.Vertex) { t.Traverse(nn.Alias) t.visitor.Leave("Alias", true) } - case *ast.StmtUseList: + case *ast.StmtUseType: if nn == nil { return } if !t.visitor.EnterNode(nn) { return } - if nn.UseType != nil { - t.visitor.Enter("UseType", true) - t.Traverse(nn.UseType) - t.visitor.Leave("UseType", true) + if nn.Type != nil { + t.visitor.Enter("Type", true) + t.Traverse(nn.Type) + t.visitor.Leave("Type", true) } - if nn.Uses != nil { - t.visitor.Enter("Uses", false) - for _, c := range nn.Uses { - t.Traverse(c) - } - t.visitor.Leave("Uses", false) + if nn.Use != nil { + t.visitor.Enter("Use", true) + t.Traverse(nn.Use) + t.visitor.Leave("Use", true) } case *ast.StmtWhile: if nn == nil { diff --git a/pkg/ast/visitor/dump.go b/pkg/ast/visitor/dump.go index 9346d75..fd9e253 100644 --- a/pkg/ast/visitor/dump.go +++ b/pkg/ast/visitor/dump.go @@ -437,12 +437,6 @@ func (v *Dump) StmtGoto(n *ast.StmtGoto) { v.printNode(n.GetNode()) } -func (v *Dump) StmtGroupUse(n *ast.StmtGroupUse) { - v.printIndentIfNotSingle(v.indent - 1) - v.print("&ast.StmtGroupUse{\n") - v.printNode(n.GetNode()) -} - func (v *Dump) StmtHaltCompiler(n *ast.StmtHaltCompiler) { v.printIndentIfNotSingle(v.indent - 1) v.print("&ast.StmtHaltCompiler{\n") @@ -596,12 +590,30 @@ func (v *Dump) StmtUse(n *ast.StmtUse) { v.printNode(n.GetNode()) } +func (v *Dump) StmtGroupUseList(n *ast.StmtGroupUseList) { + 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.printNode(n.GetNode()) } +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()) +} + func (v *Dump) StmtWhile(n *ast.StmtWhile) { v.printIndentIfNotSingle(v.indent - 1) v.print("&ast.StmtWhile{\n") diff --git a/pkg/ast/visitor/namespace_resolver.go b/pkg/ast/visitor/namespace_resolver.go index 9438971..65f0f54 100644 --- a/pkg/ast/visitor/namespace_resolver.go +++ b/pkg/ast/visitor/namespace_resolver.go @@ -13,7 +13,9 @@ type NamespaceResolver struct { Namespace *Namespace ResolvedNames map[ast.Vertex]string - goDeep bool + goDeep bool + useType string + usePrefix []ast.Vertex } // NewNamespaceResolver NamespaceResolver type constructor @@ -45,28 +47,28 @@ func (nsr *NamespaceResolver) StmtNamespace(n *ast.StmtNamespace) { } } -func (nsr *NamespaceResolver) StmtUseList(n *ast.StmtUseList) { - useType := "" - if n.UseType != nil { - useType = string(n.UseType.(*ast.Identifier).Value) +func (nsr *NamespaceResolver) StmtUseType(n *ast.StmtUseType) { + if n.Type != nil { + nsr.useType = string(n.Type.(*ast.Identifier).Value) } - - for _, nn := range n.Uses { - nsr.AddAlias(useType, nn, nil) - } - - nsr.goDeep = false } -func (nsr *NamespaceResolver) StmtGroupUse(n *ast.StmtGroupUse) { - useType := "" - if n.UseType != nil { - useType = string(n.UseType.(*ast.Identifier).Value) +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) } - for _, nn := range n.UseList { - nsr.AddAlias(useType, nn, n.Prefix.(*ast.NameName).Parts) - } + nsr.Namespace.AddAlias(nsr.useType, concatNameParts(nsr.usePrefix, useNameParts), alias) nsr.goDeep = false } @@ -213,26 +215,10 @@ func (nsr *NamespaceResolver) LeaveNode(n ast.Vertex) { if nn.Stmts != nil { nsr.Namespace = NewNamespace("") } - } -} - -// AddAlias adds a new alias -func (nsr *NamespaceResolver) AddAlias(useType string, nn ast.Vertex, prefix []ast.Vertex) { - switch use := nn.(type) { - case *ast.StmtUse: - if use.UseType != nil { - useType = string(use.UseType.(*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) + case *ast.StmtUseType: + nsr.useType = "" + case *ast.StmtGroupUseList: + nsr.usePrefix = nil } } diff --git a/pkg/ast/visitor/namespace_resolver_test.go b/pkg/ast/visitor/namespace_resolver_test.go index d52d635..22eb8bc 100644 --- a/pkg/ast/visitor/namespace_resolver_test.go +++ b/pkg/ast/visitor/namespace_resolver_test.go @@ -16,10 +16,12 @@ func TestResolveStaticCall(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, }, }, }, @@ -48,10 +50,12 @@ func TestResolveStaticPropertyFetch(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, }, }, }, @@ -79,10 +83,12 @@ func TestResolveClassConstFetch(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, }, }, }, @@ -110,10 +116,12 @@ func TestResolveNew(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, }, }, }, @@ -141,10 +149,12 @@ func TestResolveInstanceOf(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, }, }, }, @@ -175,14 +185,15 @@ func TestResolveInstanceCatch(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, - }, - &ast.StmtUse{ - Use: nameDE, - Alias: &ast.Identifier{Value: []byte("F")}, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, &ast.StmtUseDeclaration{ + Use: nameDE, + Alias: &ast.Identifier{Value: []byte("F")}, + }, }, }, }, @@ -220,11 +231,15 @@ func TestResolveFunctionCall(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - UseType: &ast.Identifier{Value: []byte("function")}, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseType{ + Type: &ast.Identifier{Value: []byte("function")}, + Use: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, + }, }, }, }, @@ -252,11 +267,15 @@ func TestResolveConstFetch(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - UseType: &ast.Identifier{Value: []byte("const")}, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseType{ + Type: &ast.Identifier{Value: []byte("const")}, + Use: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, + }, }, }, }, @@ -286,25 +305,39 @@ func TestResolveGroupUse(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtGroupUse{ - Prefix: nameAB, - UseList: []ast.Vertex{ - &ast.StmtUse{ - UseType: &ast.Identifier{Value: []byte("Function")}, - Use: nameF, - }, - &ast.StmtUse{ - UseType: &ast.Identifier{Value: []byte("const")}, - Use: nameC, + &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: nameBD, - UseType: &ast.Identifier{Value: []byte("Function")}, - UseList: []ast.Vertex{ - &ast.StmtUse{ - Use: nameE, + &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, + }, + }, + }, }, }, }, @@ -347,10 +380,12 @@ func TestResolveTraitUse(t *testing.T) { stxTree := &ast.StmtStmtList{ Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAB, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAB, + }, }, }, }, @@ -668,10 +703,12 @@ func TestResolveNamespaces(t *testing.T) { &ast.StmtNamespace{ NamespaceName: namespaceCD, Stmts: []ast.Vertex{ - &ast.StmtUseList{ - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: nameAC, + &ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: nameAC, + }, }, }, }, diff --git a/pkg/ast/visitor/null.go b/pkg/ast/visitor/null.go index 6fd6261..e291500 100644 --- a/pkg/ast/visitor/null.go +++ b/pkg/ast/visitor/null.go @@ -182,10 +182,6 @@ func (v *Null) StmtGoto(_ *ast.StmtGoto) { // do nothing } -func (v *Null) StmtGroupUse(_ *ast.StmtGroupUse) { - // do nothing -} - func (v *Null) StmtHaltCompiler(_ *ast.StmtHaltCompiler) { // do nothing } @@ -286,10 +282,22 @@ func (v *Null) StmtUse(_ *ast.StmtUse) { // do nothing } +func (v *Null) StmtGroupUseList(_ *ast.StmtGroupUseList) { + // do nothing +} + func (v *Null) StmtUseList(_ *ast.StmtUseList) { // do nothing } +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 0948cdd..71a89a8 100644 --- a/pkg/printer/pretty_printer.go +++ b/pkg/printer/pretty_printer.go @@ -353,8 +353,6 @@ func (p *PrettyPrinter) printNode(n ast.Vertex) { p.printStmtGlobal(n) case *ast.StmtGoto: p.printStmtGoto(n) - case *ast.StmtGroupUse: - p.printStmtGroupUse(n) case *ast.StmtHaltCompiler: p.printStmtHaltCompiler(n) case *ast.StmtIf: @@ -399,10 +397,16 @@ func (p *PrettyPrinter) printNode(n ast.Vertex) { p.printStmtTry(n) case *ast.StmtUnset: p.printStmtUnset(n) - case *ast.StmtUseList: - p.printStmtUseList(n) case *ast.StmtUse: p.printStmtUse(n) + case *ast.StmtGroupUseList: + p.printStmtGroupUseList(n) + case *ast.StmtUseList: + p.printStmtUseList(n) + case *ast.StmtUseDeclaration: + p.printStmtUseDeclaration(n) + case *ast.StmtUseType: + p.printStmtUseType(n) case *ast.StmtWhile: p.printStmtWhile(n) } @@ -1847,22 +1851,6 @@ func (p *PrettyPrinter) printStmtGoto(n ast.Vertex) { io.WriteString(p.w, ";") } -func (p *PrettyPrinter) printStmtGroupUse(n ast.Vertex) { - nn := n.(*ast.StmtGroupUse) - - io.WriteString(p.w, "use ") - - if nn.UseType != nil { - p.Print(nn.UseType) - io.WriteString(p.w, " ") - } - - p.Print(nn.Prefix) - io.WriteString(p.w, "\\{") - p.joinPrint(", ", nn.UseList) - io.WriteString(p.w, "};") -} - func (p *PrettyPrinter) printStmtHaltCompiler(n ast.Vertex) { io.WriteString(p.w, "__halt_compiler();") } @@ -2146,27 +2134,34 @@ func (p *PrettyPrinter) printStmtUnset(n ast.Vertex) { io.WriteString(p.w, ");") } -func (p *PrettyPrinter) printStmtUseList(n ast.Vertex) { - nn := n.(*ast.StmtUseList) - - io.WriteString(p.w, "use ") - - if nn.UseType != nil { - p.Print(nn.UseType) - io.WriteString(p.w, " ") - } - - p.joinPrint(", ", nn.Uses) - io.WriteString(p.w, ";") -} - func (p *PrettyPrinter) printStmtUse(n ast.Vertex) { nn := n.(*ast.StmtUse) - if nn.UseType != nil { - p.Print(nn.UseType) - io.WriteString(p.w, " ") - } + io.WriteString(p.w, "use ") + + p.Print(nn.UseList) + + io.WriteString(p.w, ";") +} + +func (p *PrettyPrinter) printStmtGroupUseList(n ast.Vertex) { + nn := n.(*ast.StmtGroupUseList) + + 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) +} + +func (p *PrettyPrinter) printStmtUseDeclaration(n ast.Vertex) { + nn := n.(*ast.StmtUseDeclaration) p.Print(nn.Use) @@ -2176,6 +2171,15 @@ func (p *PrettyPrinter) printStmtUse(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 dd20c5d..72f4988 100644 --- a/pkg/printer/pretty_printer_test.go +++ b/pkg/printer/pretty_printer_test.go @@ -3256,32 +3256,6 @@ func TestPrintStmtGoto(t *testing.T) { } } -func TestPrintStmtGroupUse(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrettyPrinter(o, " ") - p.Print(&ast.StmtGroupUse{ - UseType: &ast.Identifier{Value: []byte("function")}, - Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, - UseList: []ast.Vertex{ - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}}, - Alias: &ast.Identifier{Value: []byte("Baz")}, - }, - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Quuz")}}}, - }, - }, - }) - - expected := `use function Foo\{Bar as Baz, Quuz};` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - func TestPrintHaltCompiler(t *testing.T) { o := bytes.NewBufferString("") @@ -3975,24 +3949,15 @@ func TestPrintStmtUset(t *testing.T) { } } -func TestPrintStmtUseList(t *testing.T) { +func TestPrintUse(t *testing.T) { o := bytes.NewBufferString("") p := printer.NewPrettyPrinter(o, " ") - p.Print(&ast.StmtUseList{ - UseType: &ast.Identifier{Value: []byte("function")}, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, - Alias: &ast.Identifier{Value: []byte("Bar")}, - }, - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}}, - }, - }, + p.Print(&ast.StmtUse{ + UseList: &ast.StmtUseList{}, }) - expected := `use function Foo as Bar, Baz;` + expected := `use ;` actual := o.String() if expected != actual { @@ -4000,14 +3965,74 @@ func TestPrintStmtUseList(t *testing.T) { } } -func TestPrintUse(t *testing.T) { +func TestPrintStmtGroupUseList(t *testing.T) { o := bytes.NewBufferString("") p := printer.NewPrettyPrinter(o, " ") - p.Print(&ast.StmtUse{ - UseType: &ast.Identifier{Value: []byte("function")}, - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, - Alias: &ast.Identifier{Value: []byte("Bar")}, + 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{ + 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 := `Foo as Bar, Baz` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintUseDeclaration(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&ast.StmtUseDeclaration{ + Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, + Alias: &ast.Identifier{Value: []byte("Bar")}, + }) + + expected := `Foo as Bar` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrintUseType(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&ast.StmtUseType{ + Type: &ast.Identifier{Value: []byte("function")}, + Use: &ast.StmtUseDeclaration{ + Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, + Alias: &ast.Identifier{Value: []byte("Bar")}, + }, }) expected := `function Foo as Bar` diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 47a82fb..4eff938 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -16,8 +16,10 @@ const ( ) type Printer struct { - w io.Writer - s printerState + w io.Writer + s printerState + bufStart string + bufEnd string } // NewPrinter - Constructor for Printer @@ -60,6 +62,21 @@ func (p *Printer) printNodes(nn []ast.Vertex) { } } +func (p *Printer) printFreeFloatingOrDefault(n ast.Vertex, pos token.Position, def string) { + if n == nil { + return + } + + if len(n.GetNode().Tokens[pos]) == 0 { + io.WriteString(p.w, def) + return + } + + for _, m := range n.GetNode().Tokens[pos] { + io.WriteString(p.w, string(m.Value)) + } +} + func (p *Printer) printFreeFloating(n ast.Vertex, pos token.Position) { if n == nil { return @@ -374,8 +391,6 @@ func (p *Printer) printNode(n ast.Vertex) { p.printStmtGlobal(n) case *ast.StmtGoto: p.printStmtGoto(n) - case *ast.StmtGroupUse: - p.printStmtGroupUse(n) case *ast.StmtHaltCompiler: p.printStmtHaltCompiler(n) case *ast.StmtIf: @@ -422,10 +437,16 @@ func (p *Printer) printNode(n ast.Vertex) { p.printStmtTry(n) case *ast.StmtUnset: p.printStmtUnset(n) - case *ast.StmtUseList: - p.printStmtUseList(n) case *ast.StmtUse: p.printStmtUse(n) + case *ast.StmtGroupUseList: + p.printStmtGroupUseList(n) + case *ast.StmtUseList: + p.printStmtUseList(n) + case *ast.StmtUseDeclaration: + p.printStmtUseDeclaration(n) + case *ast.StmtUseType: + p.printStmtUseType(n) case *ast.StmtWhile: p.printStmtWhile(n) } @@ -443,8 +464,11 @@ func (p *Printer) printNodeRoot(n ast.Vertex) { func (p *Printer) printNodeIdentifier(n ast.Vertex) { nn := n.(*ast.Identifier) - p.printFreeFloating(nn, token.Start) + p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart) + p.bufStart = "" + io.WriteString(p.w, string(nn.Value)) + p.printFreeFloating(nn, token.End) } @@ -519,7 +543,8 @@ func (p *Printer) printNodeArgument(n ast.Vertex) { func (p *Printer) printNameNamePart(n ast.Vertex) { nn := n.(*ast.NameNamePart) - p.printFreeFloating(nn, token.Start) + p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart) + p.bufStart = "" io.WriteString(p.w, string(nn.Value)) @@ -532,22 +557,26 @@ func (p *Printer) printNameName(n ast.Vertex) { p.joinPrint("\\", nn.Parts) - p.printFreeFloating(nn, token.End) + p.printFreeFloatingOrDefault(nn, token.End, p.bufEnd) + p.bufEnd = "" } func (p *Printer) printNameFullyQualified(n ast.Vertex) { nn := n.(*ast.NameFullyQualified) - p.printFreeFloating(nn, token.Start) + p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart) + p.bufStart = "" io.WriteString(p.w, "\\") p.joinPrint("\\", nn.Parts) - p.printFreeFloating(nn, token.End) + p.printFreeFloatingOrDefault(nn, token.End, p.bufEnd) + p.bufEnd = "" } func (p *Printer) printNameRelative(n ast.Vertex) { nn := n.(*ast.NameRelative) - p.printFreeFloating(nn, token.Start) + p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart) + p.bufStart = "" io.WriteString(p.w, "namespace") p.printFreeFloating(nn, token.Namespace) @@ -557,7 +586,8 @@ func (p *Printer) printNameRelative(n ast.Vertex) { p.Print(part) } - p.printFreeFloating(nn, token.End) + p.printFreeFloatingOrDefault(nn, token.End, p.bufEnd) + p.bufEnd = "" } // scalar @@ -2710,41 +2740,6 @@ func (p *Printer) printStmtGoto(n ast.Vertex) { p.printFreeFloating(nn, token.End) } -func (p *Printer) printStmtGroupUse(n ast.Vertex) { - nn := n.(*ast.StmtGroupUse) - p.printFreeFloating(nn, token.Start) - - io.WriteString(p.w, "use") - p.printFreeFloating(nn, token.Use) - - if nn.UseType != nil { - if nn.UseType.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.Print(nn.UseType) - } - - if nn.Prefix.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.Print(nn.Prefix) - io.WriteString(p.w, "\\") - p.printFreeFloating(nn, token.Slash) - - io.WriteString(p.w, "{") - p.joinPrint(",", nn.UseList) - p.printFreeFloating(nn, token.Stmts) - io.WriteString(p.w, "}") - p.printFreeFloating(nn, token.UseDeclarationList) - - p.printFreeFloating(nn, token.SemiColon) - if nn.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, ";") - } - - p.printFreeFloating(nn, token.End) -} - func (p *Printer) printStmtHaltCompiler(n ast.Vertex) { nn := n.(*ast.StmtHaltCompiler) p.printFreeFloating(nn, token.Start) @@ -3197,59 +3192,78 @@ func (p *Printer) printStmtUnset(n ast.Vertex) { p.printFreeFloating(nn, token.End) } -func (p *Printer) printStmtUseList(n ast.Vertex) { - nn := n.(*ast.StmtUseList) +func (p *Printer) printStmtUse(n ast.Vertex) { + nn := n.(*ast.StmtUse) p.printFreeFloating(nn, token.Start) io.WriteString(p.w, "use") - if nn.UseType != nil { - if nn.UseType.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.Print(nn.UseType) + p.bufStart = " " + p.Print(nn.UseList) + + p.printFreeFloatingOrDefault(nn, token.End, ";") +} + +func (p *Printer) printStmtGroupUseList(n ast.Vertex) { + nn := n.(*ast.StmtGroupUseList) + p.printFreeFloating(nn, token.Start) + + p.Print(nn.Prefix) + + p.bufStart = "\\{" + p.bufEnd = "}" + p.Print(nn.UseList) + + p.printFreeFloating(nn, token.End) +} + +func (p *Printer) printStmtUseList(n ast.Vertex) { + nn := n.(*ast.StmtUseList) + + bufEnd := p.bufEnd + p.bufEnd = "" + + if p.bufStart == "\\{" { + p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart) + p.bufStart = "" + } else { + p.printFreeFloating(nn, token.Start) } - if nn.Uses[0].GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.joinPrint(",", nn.Uses) - p.printFreeFloating(nn, token.UseDeclarationList) + p.joinPrint(",", nn.UseDeclarations) - p.printFreeFloating(nn, token.SemiColon) - if nn.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, ";") + p.printFreeFloatingOrDefault(nn, token.End, bufEnd) +} + +func (p *Printer) printStmtUseDeclaration(n ast.Vertex) { + nn := n.(*ast.StmtUseDeclaration) + p.printFreeFloating(nn, token.Start) + + if nn.Alias != nil { + p.bufEnd = " " + } + + p.Print(nn.Use) + + if nn.Alias != nil { + io.WriteString(p.w, "as") + + p.bufStart = " " + p.Print(nn.Alias) } p.printFreeFloating(nn, token.End) } -func (p *Printer) printStmtUse(n ast.Vertex) { - nn := n.(*ast.StmtUse) +func (p *Printer) printStmtUseType(n ast.Vertex) { + nn := n.(*ast.StmtUseType) p.printFreeFloating(nn, token.Start) - if nn.UseType != nil { - p.Print(nn.UseType) - if nn.UseType.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - } - - p.printFreeFloating(nn, token.Slash) + p.Print(nn.Type) + p.bufStart = " " p.Print(nn.Use) - if nn.Alias != nil { - if nn.Alias.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - io.WriteString(p.w, "as") - if nn.Alias.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.Print(nn.Alias) - } - p.printFreeFloating(nn, token.End) } diff --git a/pkg/printer/printer_test.go b/pkg/printer/printer_test.go index c7a8303..8e85ac0 100644 --- a/pkg/printer/printer_test.go +++ b/pkg/printer/printer_test.go @@ -3673,32 +3673,6 @@ func TestPrinterPrintStmtGoto(t *testing.T) { } } -func TestPrinterPrintStmtGroupUse(t *testing.T) { - o := bytes.NewBufferString("") - - p := printer.NewPrinter(o) - p.Print(&ast.StmtGroupUse{ - UseType: &ast.Identifier{Value: []byte("function")}, - Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, - UseList: []ast.Vertex{ - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}}, - Alias: &ast.Identifier{Value: []byte("Baz")}, - }, - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Quuz")}}}, - }, - }, - }) - - expected := `use function Foo\{Bar as Baz,Quuz};` - actual := o.String() - - if expected != actual { - t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) - } -} - func TestPrinterPrintHaltCompiler(t *testing.T) { o := bytes.NewBufferString("") @@ -4412,24 +4386,21 @@ func TestPrinterPrintStmtUnset(t *testing.T) { } } -func TestPrinterPrintStmtUseList(t *testing.T) { +func TestPrinterPrintUse(t *testing.T) { o := bytes.NewBufferString("") p := printer.NewPrinter(o) - p.Print(&ast.StmtUseList{ - UseType: &ast.Identifier{Value: []byte("function")}, - Uses: []ast.Vertex{ - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, - Alias: &ast.Identifier{Value: []byte("Bar")}, - }, - &ast.StmtUse{ - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}}, + p.Print(&ast.StmtUse{ + UseList: &ast.StmtUseList{ + UseDeclarations: []ast.Vertex{ + &ast.StmtUseDeclaration{ + Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, + }, }, }, }) - expected := `use function Foo as Bar,Baz;` + expected := `use Foo;` actual := o.String() if expected != actual { @@ -4437,14 +4408,74 @@ func TestPrinterPrintStmtUseList(t *testing.T) { } } -func TestPrinterPrintUse(t *testing.T) { +func TestPrinterPrintStmtGroupUseList(t *testing.T) { o := bytes.NewBufferString("") p := printer.NewPrinter(o) - p.Print(&ast.StmtUse{ - UseType: &ast.Identifier{Value: []byte("function")}, - Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, - Alias: &ast.Identifier{Value: []byte("Bar")}, + p.Print(&ast.StmtGroupUseList{ + Prefix: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, + UseList: &ast.StmtUseList{}, + }) + + expected := `Foo\{}` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintStmtUseList(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) + p.Print(&ast.StmtUseList{ + 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 := `Foo as Bar,Baz` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintUseDeclaration(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) + p.Print(&ast.StmtUseDeclaration{ + Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, + Alias: &ast.Identifier{Value: []byte("Bar")}, + }) + + expected := `Foo as Bar` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + +func TestPrinterPrintUseType(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrinter(o) + p.Print(&ast.StmtUseType{ + Type: &ast.Identifier{Value: []byte("function")}, + Use: &ast.StmtUseDeclaration{ + Use: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, + Alias: &ast.Identifier{Value: []byte("Bar")}, + }, }) expected := `function Foo as Bar` diff --git a/pkg/token/position.go b/pkg/token/position.go index 7032e5a..1a3b02d 100644 --- a/pkg/token/position.go +++ b/pkg/token/position.go @@ -6,7 +6,6 @@ type Position int const ( Start Position = iota End - Slash Colon SemiColon AltEnd diff --git a/pkg/token/position_string.go b/pkg/token/position_string.go index cc51fe2..a2f713a 100644 --- a/pkg/token/position_string.go +++ b/pkg/token/position_string.go @@ -10,85 +10,84 @@ func _() { var x [1]struct{} _ = x[Start-0] _ = x[End-1] - _ = x[Slash-2] - _ = x[Colon-3] - _ = x[SemiColon-4] - _ = x[AltEnd-5] - _ = x[Dollar-6] - _ = x[Ampersand-7] - _ = x[Name-8] - _ = x[Prefix-9] - _ = x[Key-10] - _ = x[Var-11] - _ = x[UseType-12] - _ = x[ReturnType-13] - _ = x[OptionalType-14] - _ = x[CaseSeparator-15] - _ = x[LexicalVars-16] - _ = x[Params-17] - _ = x[Ref-18] - _ = x[Cast-19] - _ = x[Expr-20] - _ = x[InitExpr-21] - _ = x[CondExpr-22] - _ = x[IncExpr-23] - _ = x[True-24] - _ = x[Cond-25] - _ = x[HaltCompiller-26] - _ = x[Namespace-27] - _ = x[Static-28] - _ = x[Class-29] - _ = x[Use-30] - _ = x[While-31] - _ = x[For-32] - _ = x[Switch-33] - _ = x[Break-34] - _ = x[Foreach-35] - _ = x[Declare-36] - _ = x[Label-37] - _ = x[Finally-38] - _ = x[List-39] - _ = x[Default-40] - _ = x[If-41] - _ = x[ElseIf-42] - _ = x[Else-43] - _ = x[Variadic-44] - _ = x[Function-45] - _ = x[DoubleArrow-46] - _ = x[Alias-47] - _ = x[As-48] - _ = x[Equal-49] - _ = x[Exit-50] - _ = x[Array-51] - _ = x[Isset-52] - _ = x[Empty-53] - _ = x[Eval-54] - _ = x[Echo-55] - _ = x[Try-56] - _ = x[Catch-57] - _ = x[Unset-58] - _ = x[Stmts-59] - _ = x[VarList-60] - _ = x[ConstList-61] - _ = x[NameList-62] - _ = x[ParamList-63] - _ = x[ModifierList-64] - _ = x[ArrayPairList-65] - _ = x[CaseListStart-66] - _ = x[CaseListEnd-67] - _ = x[ArgumentList-68] - _ = x[PropertyList-69] - _ = x[ParameterList-70] - _ = x[AdaptationList-71] - _ = x[LexicalVarList-72] - _ = x[UseDeclarationList-73] - _ = x[OpenParenthesisToken-74] - _ = x[CloseParenthesisToken-75] + _ = x[Colon-2] + _ = x[SemiColon-3] + _ = x[AltEnd-4] + _ = x[Dollar-5] + _ = x[Ampersand-6] + _ = x[Name-7] + _ = x[Prefix-8] + _ = x[Key-9] + _ = x[Var-10] + _ = x[UseType-11] + _ = x[ReturnType-12] + _ = x[OptionalType-13] + _ = x[CaseSeparator-14] + _ = x[LexicalVars-15] + _ = x[Params-16] + _ = x[Ref-17] + _ = x[Cast-18] + _ = x[Expr-19] + _ = x[InitExpr-20] + _ = x[CondExpr-21] + _ = x[IncExpr-22] + _ = x[True-23] + _ = x[Cond-24] + _ = x[HaltCompiller-25] + _ = x[Namespace-26] + _ = x[Static-27] + _ = x[Class-28] + _ = x[Use-29] + _ = x[While-30] + _ = x[For-31] + _ = x[Switch-32] + _ = x[Break-33] + _ = x[Foreach-34] + _ = x[Declare-35] + _ = x[Label-36] + _ = x[Finally-37] + _ = x[List-38] + _ = x[Default-39] + _ = x[If-40] + _ = x[ElseIf-41] + _ = x[Else-42] + _ = x[Variadic-43] + _ = x[Function-44] + _ = x[DoubleArrow-45] + _ = x[Alias-46] + _ = x[As-47] + _ = x[Equal-48] + _ = x[Exit-49] + _ = x[Array-50] + _ = x[Isset-51] + _ = x[Empty-52] + _ = x[Eval-53] + _ = x[Echo-54] + _ = x[Try-55] + _ = x[Catch-56] + _ = x[Unset-57] + _ = x[Stmts-58] + _ = x[VarList-59] + _ = x[ConstList-60] + _ = x[NameList-61] + _ = x[ParamList-62] + _ = x[ModifierList-63] + _ = x[ArrayPairList-64] + _ = x[CaseListStart-65] + _ = x[CaseListEnd-66] + _ = x[ArgumentList-67] + _ = x[PropertyList-68] + _ = x[ParameterList-69] + _ = x[AdaptationList-70] + _ = x[LexicalVarList-71] + _ = x[UseDeclarationList-72] + _ = x[OpenParenthesisToken-73] + _ = x[CloseParenthesisToken-74] } -const _Position_name = "StartEndSlashColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionDoubleArrowAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken" +const _Position_name = "StartEndColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionDoubleArrowAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken" -var _Position_index = [...]uint16{0, 5, 8, 13, 18, 27, 33, 39, 48, 52, 58, 61, 64, 71, 81, 93, 106, 117, 123, 126, 130, 134, 142, 150, 157, 161, 165, 178, 187, 193, 198, 201, 206, 209, 215, 220, 227, 234, 239, 246, 250, 257, 259, 265, 269, 277, 285, 296, 301, 303, 308, 312, 317, 322, 327, 331, 335, 338, 343, 348, 353, 360, 369, 377, 386, 398, 411, 424, 435, 447, 459, 472, 486, 500, 518, 538, 559} +var _Position_index = [...]uint16{0, 5, 8, 13, 22, 28, 34, 43, 47, 53, 56, 59, 66, 76, 88, 101, 112, 118, 121, 125, 129, 137, 145, 152, 156, 160, 173, 182, 188, 193, 196, 201, 204, 210, 215, 222, 229, 234, 241, 245, 252, 254, 260, 264, 272, 280, 291, 296, 298, 303, 307, 312, 317, 322, 326, 330, 333, 338, 343, 348, 355, 364, 372, 381, 393, 406, 419, 430, 442, 454, 467, 481, 495, 513, 533, 554} func (i Position) String() string { if i < 0 || i >= Position(len(_Position_index)-1) {