[refactoring] remove general Node struct
This commit is contained in:
		
							parent
							
								
									f6f86bf99b
								
							
						
					
					
						commit
						20a42da7c9
					
				| @ -1,7 +1,6 @@ | |||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"bytes" |  | ||||||
| 	"flag" | 	"flag" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| @ -21,7 +20,6 @@ import ( | |||||||
| 	"github.com/z7zmey/php-parser/pkg/ast/visitor" | 	"github.com/z7zmey/php-parser/pkg/ast/visitor" | ||||||
| 	"github.com/z7zmey/php-parser/pkg/errors" | 	"github.com/z7zmey/php-parser/pkg/errors" | ||||||
| 	"github.com/z7zmey/php-parser/pkg/parser" | 	"github.com/z7zmey/php-parser/pkg/parser" | ||||||
| 	"github.com/z7zmey/php-parser/pkg/printer" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var wg sync.WaitGroup | var wg sync.WaitGroup | ||||||
| @ -165,12 +163,12 @@ func printerWorker(r <-chan result) { | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if *printBack { | 		if *printBack { | ||||||
| 			o := bytes.NewBuffer([]byte{}) | 			//o := bytes.NewBuffer([]byte{}) | ||||||
| 			p := printer.NewPrinter(o) | 			//p := printer.NewPrinter(o) | ||||||
| 			p.Print(res.rootNode) | 			//p.Print(res.rootNode) | ||||||
| 
 | 			// | ||||||
| 			err := ioutil.WriteFile(res.path, o.Bytes(), 0644) | 			//err := ioutil.WriteFile(res.path, o.Bytes(), 0644) | ||||||
| 			checkErr(err) | 			//checkErr(err) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if *showResolvedNs { | 		if *showResolvedNs { | ||||||
|  | |||||||
							
								
								
									
										2052
									
								
								internal/php5/php5.go
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2052
									
								
								internal/php5/php5.go
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1012
									
								
								internal/php5/php5.y
									
									
									
									
									
								
							
							
						
						
									
										1012
									
								
								internal/php5/php5.y
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1711
									
								
								internal/php7/php7.go
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1711
									
								
								internal/php7/php7.go
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -36,7 +36,7 @@ func getNodeStartPos(n ast.Vertex) startPos { | |||||||
| 		return startPos{-1, -1} | 		return startPos{-1, -1} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	p := n.GetNode().Position | 	p := n.GetPosition() | ||||||
| 	if p != nil { | 	if p != nil { | ||||||
| 		sl = p.StartLine | 		sl = p.StartLine | ||||||
| 		sp = p.StartPos | 		sp = p.StartPos | ||||||
| @ -65,7 +65,7 @@ func getNodeEndPos(n ast.Vertex) endPos { | |||||||
| 		return endPos{-1, -1} | 		return endPos{-1, -1} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	p := n.GetNode().Position | 	p := n.GetPosition() | ||||||
| 	if p != nil { | 	if p != nil { | ||||||
| 		el = p.EndLine | 		el = p.EndLine | ||||||
| 		ep = p.EndPos | 		ep = p.EndPos | ||||||
|  | |||||||
| @ -23,9 +23,7 @@ func TestNewTokenPosition(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	pos := builder.NewTokenPosition(tkn) | 	pos := builder.NewTokenPosition(tkn) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 1, 0, 3}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 1, EndPos: 3}, pos) | ||||||
| 
 |  | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 1, 0, 3}, pos) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewTokensPosition(t *testing.T) { | func TestNewTokensPosition(t *testing.T) { | ||||||
| @ -50,24 +48,22 @@ func TestNewTokensPosition(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	pos := builder.NewTokensPosition(token1, token2) | 	pos := builder.NewTokensPosition(token1, token2) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 2, 0, 6}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 2, EndPos: 6}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodePosition(t *testing.T) { | func TestNewNodePosition(t *testing.T) { | ||||||
| 	n := &ast.Identifier{ | 	n := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    3, | 			EndPos:    3, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodePosition(n) | 	pos := builder.NewNodePosition(n) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 1, 0, 3}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 1, EndPos: 3}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewTokenNodePosition(t *testing.T) { | func TestNewTokenNodePosition(t *testing.T) { | ||||||
| @ -81,31 +77,27 @@ func TestNewTokenNodePosition(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	n := &ast.Identifier{ | 	n := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  4, | 			StartPos:  4, | ||||||
| 			EndPos:    12, | 			EndPos:    12, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewTokenNodePosition(tkn, n) | 	pos := builder.NewTokenNodePosition(tkn, n) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 2, 0, 12}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 2, EndPos: 12}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodeTokenPosition(t *testing.T) { | func TestNewNodeTokenPosition(t *testing.T) { | ||||||
| 	n := &ast.Identifier{ | 	n := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    9, | 			EndPos:    9, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	tkn := &token.Token{ | 	tkn := &token.Token{ | ||||||
| @ -120,86 +112,74 @@ func TestNewNodeTokenPosition(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeTokenPosition(n, tkn) | 	pos := builder.NewNodeTokenPosition(n, tkn) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 2, 0, 12}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 2, EndPos: 12}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodeListPosition(t *testing.T) { | func TestNewNodeListPosition(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    9, | 			EndPos:    9, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  10, | 			StartPos:  10, | ||||||
| 			EndPos:    19, | 			EndPos:    19, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeListPosition([]ast.Vertex{n1, n2}) | 	pos := builder.NewNodeListPosition([]ast.Vertex{n1, n2}) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 2, 0, 19}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 2, EndPos: 19}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodesPosition(t *testing.T) { | func TestNewNodesPosition(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    9, | 			EndPos:    9, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  10, | 			StartPos:  10, | ||||||
| 			EndPos:    19, | 			EndPos:    19, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodesPosition(n1, n2) | 	pos := builder.NewNodesPosition(n1, n2) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 2, 0, 19}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 2, EndPos: 19}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodeListTokenPosition(t *testing.T) { | func TestNewNodeListTokenPosition(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    9, | 			EndPos:    9, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  10, | 			StartPos:  10, | ||||||
| 			EndPos:    19, | 			EndPos:    19, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	tkn := &token.Token{ | 	tkn := &token.Token{ | ||||||
| @ -214,7 +194,7 @@ func TestNewNodeListTokenPosition(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeListTokenPosition([]ast.Vertex{n1, n2}, tkn) | 	pos := builder.NewNodeListTokenPosition([]ast.Vertex{n1, n2}, tkn) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 3, 0, 22}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 3, EndPos: 22}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewTokenNodeListPosition(t *testing.T) { | func TestNewTokenNodeListPosition(t *testing.T) { | ||||||
| @ -229,106 +209,90 @@ func TestNewTokenNodeListPosition(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  3, | 			StartPos:  3, | ||||||
| 			EndPos:    10, | 			EndPos:    10, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 3, | 			StartLine: 3, | ||||||
| 			EndLine:   3, | 			EndLine:   3, | ||||||
| 			StartPos:  11, | 			StartPos:  11, | ||||||
| 			EndPos:    20, | 			EndPos:    20, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewTokenNodeListPosition(tkn, []ast.Vertex{n1, n2}) | 	pos := builder.NewTokenNodeListPosition(tkn, []ast.Vertex{n1, n2}) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 3, 0, 20}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 3, EndPos: 20}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodeNodeListPosition(t *testing.T) { | func TestNewNodeNodeListPosition(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    8, | 			EndPos:    8, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  9, | 			StartPos:  9, | ||||||
| 			EndPos:    17, | 			EndPos:    17, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	n3 := &ast.Identifier{ | 	n3 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 3, | 			StartLine: 3, | ||||||
| 			EndLine:   3, | 			EndLine:   3, | ||||||
| 			StartPos:  18, | 			StartPos:  18, | ||||||
| 			EndPos:    26, | 			EndPos:    26, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeNodeListPosition(n1, []ast.Vertex{n2, n3}) | 	pos := builder.NewNodeNodeListPosition(n1, []ast.Vertex{n2, n3}) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 3, 0, 26}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 3, EndPos: 26}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewNodeListNodePosition(t *testing.T) { | func TestNewNodeListNodePosition(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    8, | 			EndPos:    8, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  9, | 			StartPos:  9, | ||||||
| 			EndPos:    17, | 			EndPos:    17, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 	n3 := &ast.Identifier{ | 	n3 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 3, | 			StartLine: 3, | ||||||
| 			EndLine:   3, | 			EndLine:   3, | ||||||
| 			StartPos:  18, | 			StartPos:  18, | ||||||
| 			EndPos:    26, | 			EndPos:    26, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeListNodePosition([]ast.Vertex{n1, n2}, n3) | 	pos := builder.NewNodeListNodePosition([]ast.Vertex{n1, n2}, n3) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 3, 0, 26}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 3, EndPos: 26}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewOptionalListTokensPosition(t *testing.T) { | func TestNewOptionalListTokensPosition(t *testing.T) { | ||||||
| @ -353,29 +317,25 @@ func TestNewOptionalListTokensPosition(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	pos := builder.NewOptionalListTokensPosition(nil, token1, token2) | 	pos := builder.NewOptionalListTokensPosition(nil, token1, token2) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, 2, 0, 6}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: 2, EndPos: 6}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNewOptionalListTokensPosition2(t *testing.T) { | func TestNewOptionalListTokensPosition2(t *testing.T) { | ||||||
| 	n2 := &ast.Identifier{ | 	n2 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 2, | 			StartLine: 2, | ||||||
| 			EndLine:   2, | 			EndLine:   2, | ||||||
| 			StartPos:  9, | 			StartPos:  9, | ||||||
| 			EndPos:    17, | 			EndPos:    17, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 	n3 := &ast.Identifier{ | 	n3 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 3, | 			StartLine: 3, | ||||||
| 			EndLine:   3, | 			EndLine:   3, | ||||||
| 			StartPos:  18, | 			StartPos:  18, | ||||||
| 			EndPos:    26, | 			EndPos:    26, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	token1 := &token.Token{ | 	token1 := &token.Token{ | ||||||
| @ -399,34 +359,32 @@ func TestNewOptionalListTokensPosition2(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| 	pos := builder.NewOptionalListTokensPosition([]ast.Vertex{n2, n3}, token1, token2) | 	pos := builder.NewOptionalListTokensPosition([]ast.Vertex{n2, n3}, token1, token2) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{2, 5, 9, 32}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 2, EndLine: 5, StartPos: 9, EndPos: 32}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNilNodePos(t *testing.T) { | func TestNilNodePos(t *testing.T) { | ||||||
| 	pos := builder.NewNodesPosition(nil, nil) | 	pos := builder.NewNodesPosition(nil, nil) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{-1, -1, -1, -1}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: -1, EndLine: -1, StartPos: -1, EndPos: -1}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNilNodeListPos(t *testing.T) { | func TestNilNodeListPos(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    8, | 			EndPos:    8, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeNodeListPosition(n1, nil) | 	pos := builder.NewNodeNodeListPosition(n1, nil) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, -1, 0, -1}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: -1, EndPos: -1}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestNilNodeListTokenPos(t *testing.T) { | func TestNilNodeListTokenPos(t *testing.T) { | ||||||
| 	token := &token.Token{ | 	tkn := &token.Token{ | ||||||
| 		Value: []byte(`foo`), | 		Value: []byte(`foo`), | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| @ -436,30 +394,28 @@ func TestNilNodeListTokenPos(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeListTokenPosition(nil, token) | 	pos := builder.NewNodeListTokenPosition(nil, tkn) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{-1, 1, -1, 3}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: -1, EndLine: 1, StartPos: -1, EndPos: 3}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestEmptyNodeListPos(t *testing.T) { | func TestEmptyNodeListPos(t *testing.T) { | ||||||
| 	n1 := &ast.Identifier{ | 	n1 := &ast.Identifier{ | ||||||
| 		Node: ast.Node{ |  | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| 			EndLine:   1, | 			EndLine:   1, | ||||||
| 			StartPos:  0, | 			StartPos:  0, | ||||||
| 			EndPos:    8, | 			EndPos:    8, | ||||||
| 		}, | 		}, | ||||||
| 		}, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeNodeListPosition(n1, []ast.Vertex{}) | 	pos := builder.NewNodeNodeListPosition(n1, []ast.Vertex{}) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{1, -1, 0, -1}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: 1, EndLine: -1, EndPos: -1}, pos) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestEmptyNodeListTokenPos(t *testing.T) { | func TestEmptyNodeListTokenPos(t *testing.T) { | ||||||
| 	token := &token.Token{ | 	tkn := &token.Token{ | ||||||
| 		Value: []byte(`foo`), | 		Value: []byte(`foo`), | ||||||
| 		Position: &position.Position{ | 		Position: &position.Position{ | ||||||
| 			StartLine: 1, | 			StartLine: 1, | ||||||
| @ -469,7 +425,7 @@ func TestEmptyNodeListTokenPos(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pos := builder.NewNodeListTokenPosition([]ast.Vertex{}, token) | 	pos := builder.NewNodeListTokenPosition([]ast.Vertex{}, tkn) | ||||||
| 
 | 
 | ||||||
| 	assert.DeepEqual(t, &position.Position{-1, 1, -1, 3}, pos) | 	assert.DeepEqual(t, &position.Position{StartLine: -1, EndLine: 1, StartPos: -1, EndPos: 3}, pos) | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,8 +1,10 @@ | |||||||
| package ast | package ast | ||||||
| 
 | 
 | ||||||
|  | import "github.com/z7zmey/php-parser/pkg/position" | ||||||
|  | 
 | ||||||
| type Vertex interface { | type Vertex interface { | ||||||
| 	Accept(v NodeVisitor) | 	Accept(v NodeVisitor) | ||||||
| 	GetNode() *Node | 	GetPosition() *position.Position | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Traverser interface { | type Traverser interface { | ||||||
|  | |||||||
							
								
								
									
										987
									
								
								pkg/ast/node.go
									
									
									
									
									
								
							
							
						
						
									
										987
									
								
								pkg/ast/node.go
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -20,12 +20,6 @@ func ExampleDump() { | |||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Position: &position.Position{ |  | ||||||
| 				StartLine: 1, |  | ||||||
| 				EndLine:   1, |  | ||||||
| 				StartPos:  0, |  | ||||||
| 				EndPos:    1, |  | ||||||
| 			}, |  | ||||||
| 		}, | 		}, | ||||||
| 		Stmts: []ast.Vertex{ | 		Stmts: []ast.Vertex{ | ||||||
| 			&ast.Identifier{}, | 			&ast.Identifier{}, | ||||||
|  | |||||||
| @ -1,74 +0,0 @@ | |||||||
| package token |  | ||||||
| 
 |  | ||||||
| type Position int |  | ||||||
| 
 |  | ||||||
| //go:generate stringer -type=Position -output ./position_string.go |  | ||||||
| const ( |  | ||||||
| 	Start Position = iota |  | ||||||
| 	End |  | ||||||
| 	SemiColon |  | ||||||
| 	AltEnd |  | ||||||
| 	Ampersand |  | ||||||
| 	Name |  | ||||||
| 	Key |  | ||||||
| 	Var |  | ||||||
| 	ReturnType |  | ||||||
| 	CaseSeparator |  | ||||||
| 	LexicalVars |  | ||||||
| 	Params |  | ||||||
| 	Ref |  | ||||||
| 	Cast |  | ||||||
| 	Expr |  | ||||||
| 	InitExpr |  | ||||||
| 	CondExpr |  | ||||||
| 	IncExpr |  | ||||||
| 	True |  | ||||||
| 	Cond |  | ||||||
| 
 |  | ||||||
| 	Namespace |  | ||||||
| 	Static |  | ||||||
| 	Use |  | ||||||
| 	For |  | ||||||
| 	Foreach |  | ||||||
| 	Declare |  | ||||||
| 	Label |  | ||||||
| 	Finally |  | ||||||
| 	List |  | ||||||
| 	Default |  | ||||||
| 	Function |  | ||||||
| 	Alias |  | ||||||
| 	Equal |  | ||||||
| 	Array |  | ||||||
| 	Isset |  | ||||||
| 	Echo |  | ||||||
| 	Try |  | ||||||
| 	Catch |  | ||||||
| 	Unset |  | ||||||
| 
 |  | ||||||
| 	Stmts |  | ||||||
| 	VarList |  | ||||||
| 	ConstList |  | ||||||
| 	NameList |  | ||||||
| 	ParamList |  | ||||||
| 	ModifierList |  | ||||||
| 	ArrayPairList |  | ||||||
| 	CaseListStart |  | ||||||
| 	CaseListEnd |  | ||||||
| 	PropertyList |  | ||||||
| 	ParameterList |  | ||||||
| 	AdaptationList |  | ||||||
| 	LexicalVarList |  | ||||||
| 
 |  | ||||||
| 	CloseParenthesisToken |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| type Collection map[Position][]*Token |  | ||||||
| 
 |  | ||||||
| func (c Collection) IsEmpty() bool { |  | ||||||
| 	for _, v := range c { |  | ||||||
| 		if len(v) > 0 { |  | ||||||
| 			return false |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	return true |  | ||||||
| } |  | ||||||
| @ -1,75 +0,0 @@ | |||||||
| // Code generated by "stringer -type=Position -output ./position_string.go"; DO NOT EDIT. |  | ||||||
| 
 |  | ||||||
| package token |  | ||||||
| 
 |  | ||||||
| import "strconv" |  | ||||||
| 
 |  | ||||||
| func _() { |  | ||||||
| 	// An "invalid array index" compiler error signifies that the constant values have changed. |  | ||||||
| 	// Re-run the stringer command to generate them again. |  | ||||||
| 	var x [1]struct{} |  | ||||||
| 	_ = x[Start-0] |  | ||||||
| 	_ = x[End-1] |  | ||||||
| 	_ = x[SemiColon-2] |  | ||||||
| 	_ = x[AltEnd-3] |  | ||||||
| 	_ = x[Ampersand-4] |  | ||||||
| 	_ = x[Name-5] |  | ||||||
| 	_ = x[Key-6] |  | ||||||
| 	_ = x[Var-7] |  | ||||||
| 	_ = x[ReturnType-8] |  | ||||||
| 	_ = x[CaseSeparator-9] |  | ||||||
| 	_ = x[LexicalVars-10] |  | ||||||
| 	_ = x[Params-11] |  | ||||||
| 	_ = x[Ref-12] |  | ||||||
| 	_ = x[Cast-13] |  | ||||||
| 	_ = x[Expr-14] |  | ||||||
| 	_ = x[InitExpr-15] |  | ||||||
| 	_ = x[CondExpr-16] |  | ||||||
| 	_ = x[IncExpr-17] |  | ||||||
| 	_ = x[True-18] |  | ||||||
| 	_ = x[Cond-19] |  | ||||||
| 	_ = x[Namespace-20] |  | ||||||
| 	_ = x[Static-21] |  | ||||||
| 	_ = x[Use-22] |  | ||||||
| 	_ = x[For-23] |  | ||||||
| 	_ = x[Foreach-24] |  | ||||||
| 	_ = x[Declare-25] |  | ||||||
| 	_ = x[Label-26] |  | ||||||
| 	_ = x[Finally-27] |  | ||||||
| 	_ = x[List-28] |  | ||||||
| 	_ = x[Default-29] |  | ||||||
| 	_ = x[Function-30] |  | ||||||
| 	_ = x[Alias-31] |  | ||||||
| 	_ = x[Equal-32] |  | ||||||
| 	_ = x[Array-33] |  | ||||||
| 	_ = x[Isset-34] |  | ||||||
| 	_ = x[Echo-35] |  | ||||||
| 	_ = x[Try-36] |  | ||||||
| 	_ = x[Catch-37] |  | ||||||
| 	_ = x[Unset-38] |  | ||||||
| 	_ = x[Stmts-39] |  | ||||||
| 	_ = x[VarList-40] |  | ||||||
| 	_ = x[ConstList-41] |  | ||||||
| 	_ = x[NameList-42] |  | ||||||
| 	_ = x[ParamList-43] |  | ||||||
| 	_ = x[ModifierList-44] |  | ||||||
| 	_ = x[ArrayPairList-45] |  | ||||||
| 	_ = x[CaseListStart-46] |  | ||||||
| 	_ = x[CaseListEnd-47] |  | ||||||
| 	_ = x[PropertyList-48] |  | ||||||
| 	_ = x[ParameterList-49] |  | ||||||
| 	_ = x[AdaptationList-50] |  | ||||||
| 	_ = x[LexicalVarList-51] |  | ||||||
| 	_ = x[CloseParenthesisToken-52] |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| const _Position_name = "StartEndSemiColonAltEndAmpersandNameKeyVarReturnTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondNamespaceStaticUseForForeachDeclareLabelFinallyListDefaultFunctionAliasEqualArrayIssetEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndPropertyListParameterListAdaptationListLexicalVarListCloseParenthesisToken" |  | ||||||
| 
 |  | ||||||
| var _Position_index = [...]uint16{0, 5, 8, 17, 23, 32, 36, 39, 42, 52, 65, 76, 82, 85, 89, 93, 101, 109, 116, 120, 124, 133, 139, 142, 145, 152, 159, 164, 171, 175, 182, 190, 195, 200, 205, 210, 214, 217, 222, 227, 232, 239, 248, 256, 265, 277, 290, 303, 314, 326, 339, 353, 367, 388} |  | ||||||
| 
 |  | ||||||
| func (i Position) String() string { |  | ||||||
| 	if i < 0 || i >= Position(len(_Position_index)-1) { |  | ||||||
| 		return "Position(" + strconv.FormatInt(int64(i), 10) + ")" |  | ||||||
| 	} |  | ||||||
| 	return _Position_name[_Position_index[i]:_Position_index[i+1]] |  | ||||||
| } |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user