rename PositionBuilder
This commit is contained in:
parent
56127a4a2c
commit
bc15825663
@ -6,8 +6,8 @@ import (
|
||||
"github.com/z7zmey/php-parser/scanner"
|
||||
)
|
||||
|
||||
// Builder provide functions to constuct positions
|
||||
type Builder struct {
|
||||
// PositionBuilder provide functions to constuct positions
|
||||
type PositionBuilder struct {
|
||||
Positions *Positions
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ type endPos struct {
|
||||
endPos int
|
||||
}
|
||||
|
||||
func (b *Builder) getListStartPos(l []node.Node) startPos {
|
||||
func (b *PositionBuilder) getListStartPos(l []node.Node) startPos {
|
||||
if l == nil {
|
||||
return startPos{-1, -1}
|
||||
}
|
||||
@ -33,7 +33,7 @@ func (b *Builder) getListStartPos(l []node.Node) startPos {
|
||||
return b.getNodeStartPos(l[0])
|
||||
}
|
||||
|
||||
func (b *Builder) getNodeStartPos(n node.Node) startPos {
|
||||
func (b *PositionBuilder) getNodeStartPos(n node.Node) startPos {
|
||||
sl := -1
|
||||
sp := -1
|
||||
|
||||
@ -50,7 +50,7 @@ func (b *Builder) getNodeStartPos(n node.Node) startPos {
|
||||
return startPos{sl, sp}
|
||||
}
|
||||
|
||||
func (b *Builder) getListEndPos(l []node.Node) endPos {
|
||||
func (b *PositionBuilder) getListEndPos(l []node.Node) endPos {
|
||||
if l == nil {
|
||||
return endPos{-1, -1}
|
||||
}
|
||||
@ -62,7 +62,7 @@ func (b *Builder) getListEndPos(l []node.Node) endPos {
|
||||
return b.getNodeEndPos(l[len(l)-1])
|
||||
}
|
||||
|
||||
func (b *Builder) getNodeEndPos(n node.Node) endPos {
|
||||
func (b *PositionBuilder) getNodeEndPos(n node.Node) endPos {
|
||||
el := -1
|
||||
ep := -1
|
||||
|
||||
@ -80,120 +80,120 @@ func (b *Builder) getNodeEndPos(n node.Node) endPos {
|
||||
}
|
||||
|
||||
// NewNodeListPosition returns new Position
|
||||
func (b *Builder) NewNodeListPosition(list []node.Node) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewNodeListPosition(list []node.Node) *position.Position {
|
||||
return position.NewPosition(
|
||||
b.getListStartPos(list).startLine,
|
||||
b.getListEndPos(list).endLine,
|
||||
b.getListStartPos(list).startPos,
|
||||
b.getListEndPos(list).endPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewNodePosition returns new Position
|
||||
func (b *Builder) NewNodePosition(n node.Node) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewNodePosition(n node.Node) *position.Position {
|
||||
return position.NewPosition(
|
||||
b.getNodeStartPos(n).startLine,
|
||||
b.getNodeEndPos(n).endLine,
|
||||
b.getNodeStartPos(n).startPos,
|
||||
b.getNodeEndPos(n).endPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewTokenPosition returns new Position
|
||||
func (b *Builder) NewTokenPosition(t scanner.Token) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewTokenPosition(t scanner.Token) *position.Position {
|
||||
return position.NewPosition(
|
||||
t.StartLine,
|
||||
t.EndLine,
|
||||
t.StartPos,
|
||||
t.EndPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewTokensPosition returns new Position
|
||||
func (b *Builder) NewTokensPosition(startToken scanner.Token, endToken scanner.Token) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewTokensPosition(startToken scanner.Token, endToken scanner.Token) *position.Position {
|
||||
return position.NewPosition(
|
||||
startToken.StartLine,
|
||||
endToken.EndLine,
|
||||
startToken.StartPos,
|
||||
endToken.EndPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewTokenNodePosition returns new Position
|
||||
func (b *Builder) NewTokenNodePosition(t scanner.Token, n node.Node) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewTokenNodePosition(t scanner.Token, n node.Node) *position.Position {
|
||||
return position.NewPosition(
|
||||
t.StartLine,
|
||||
b.getNodeEndPos(n).endLine,
|
||||
t.StartPos,
|
||||
b.getNodeEndPos(n).endPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewNodeTokenPosition returns new Position
|
||||
func (b *Builder) NewNodeTokenPosition(n node.Node, t scanner.Token) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewNodeTokenPosition(n node.Node, t scanner.Token) *position.Position {
|
||||
return position.NewPosition(
|
||||
b.getNodeStartPos(n).startLine,
|
||||
t.EndLine,
|
||||
b.getNodeStartPos(n).startPos,
|
||||
t.EndPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewNodesPosition returns new Position
|
||||
func (b *Builder) NewNodesPosition(startNode node.Node, endNode node.Node) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewNodesPosition(startNode node.Node, endNode node.Node) *position.Position {
|
||||
return position.NewPosition(
|
||||
b.getNodeStartPos(startNode).startLine,
|
||||
b.getNodeEndPos(endNode).endLine,
|
||||
b.getNodeStartPos(startNode).startPos,
|
||||
b.getNodeEndPos(endNode).endPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewNodeListTokenPosition returns new Position
|
||||
func (b *Builder) NewNodeListTokenPosition(list []node.Node, t scanner.Token) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewNodeListTokenPosition(list []node.Node, t scanner.Token) *position.Position {
|
||||
return position.NewPosition(
|
||||
b.getListStartPos(list).startLine,
|
||||
t.EndLine,
|
||||
b.getListStartPos(list).startPos,
|
||||
t.EndPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewTokenNodeListPosition returns new Position
|
||||
func (b *Builder) NewTokenNodeListPosition(t scanner.Token, list []node.Node) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewTokenNodeListPosition(t scanner.Token, list []node.Node) *position.Position {
|
||||
return position.NewPosition(
|
||||
t.StartLine,
|
||||
b.getListEndPos(list).endLine,
|
||||
t.StartPos,
|
||||
b.getListEndPos(list).endPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewNodeNodeListPosition returns new Position
|
||||
func (b *Builder) NewNodeNodeListPosition(n node.Node, list []node.Node) *position.Position {
|
||||
return &position.Position{
|
||||
func (b *PositionBuilder) NewNodeNodeListPosition(n node.Node, list []node.Node) *position.Position {
|
||||
return position.NewPosition(
|
||||
b.getNodeStartPos(n).startLine,
|
||||
b.getListEndPos(list).endLine,
|
||||
b.getNodeStartPos(n).startPos,
|
||||
b.getListEndPos(list).endPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// NewOptionalListTokensPosition returns new Position
|
||||
func (b *Builder) NewOptionalListTokensPosition(list []node.Node, t scanner.Token, endToken scanner.Token) *position.Position {
|
||||
func (b *PositionBuilder) NewOptionalListTokensPosition(list []node.Node, t scanner.Token, endToken scanner.Token) *position.Position {
|
||||
if list == nil {
|
||||
return &position.Position{
|
||||
return position.NewPosition(
|
||||
t.StartLine,
|
||||
endToken.EndLine,
|
||||
t.StartPos,
|
||||
endToken.EndPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return &position.Position{
|
||||
return position.NewPosition(
|
||||
b.getListStartPos(list).startLine,
|
||||
endToken.EndLine,
|
||||
b.getListStartPos(list).startPos,
|
||||
endToken.EndPos,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNewTokenPosition(t *testing.T) {
|
||||
builder := parser.Builder{}
|
||||
builder := parser.PositionBuilder{}
|
||||
|
||||
tkn := scanner.NewToken([]byte(`foo`), 1, 1, 0, 3)
|
||||
|
||||
@ -23,7 +23,7 @@ func TestNewTokenPosition(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewTokensPosition(t *testing.T) {
|
||||
builder := parser.Builder{}
|
||||
builder := parser.PositionBuilder{}
|
||||
|
||||
token1 := scanner.NewToken([]byte(`foo`), 1, 1, 0, 3)
|
||||
token2 := scanner.NewToken([]byte(`foo`), 2, 2, 4, 6)
|
||||
@ -46,7 +46,7 @@ func TestNewNodePosition(t *testing.T) {
|
||||
EndPos: 3,
|
||||
})
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: p,
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ func TestNewTokenNodePosition(t *testing.T) {
|
||||
EndPos: 12,
|
||||
})
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: p,
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ func TestNewNodeTokenPosition(t *testing.T) {
|
||||
EndPos: 9,
|
||||
})
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: p,
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ func TestNewNodeListPosition(t *testing.T) {
|
||||
n1 := node.NewIdentifier("test node")
|
||||
n2 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -135,7 +135,7 @@ func TestNewNodesPosition(t *testing.T) {
|
||||
n1 := node.NewIdentifier("test node")
|
||||
n2 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -164,7 +164,7 @@ func TestNewNodeListTokenPosition(t *testing.T) {
|
||||
n2 := node.NewIdentifier("test node")
|
||||
tkn := scanner.NewToken([]byte(`foo`), 3, 3, 20, 22)
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -193,7 +193,7 @@ func TestNewTokenNodeListPosition(t *testing.T) {
|
||||
n1 := node.NewIdentifier("test node")
|
||||
n2 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 2,
|
||||
@ -222,7 +222,7 @@ func TestNewNodeNodeListPosition(t *testing.T) {
|
||||
n2 := node.NewIdentifier("test node")
|
||||
n3 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -253,7 +253,7 @@ func TestNewNodeNodeListPosition(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewOptionalListTokensPosition(t *testing.T) {
|
||||
builder := parser.Builder{}
|
||||
builder := parser.PositionBuilder{}
|
||||
|
||||
token1 := scanner.NewToken([]byte(`foo`), 1, 1, 0, 3)
|
||||
token2 := scanner.NewToken([]byte(`foo`), 2, 2, 4, 6)
|
||||
@ -270,7 +270,7 @@ func TestNewOptionalListTokensPosition2(t *testing.T) {
|
||||
n2 := node.NewIdentifier("test node")
|
||||
n3 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -304,7 +304,7 @@ func TestNewOptionalListTokensPosition2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNilNodePos(t *testing.T) {
|
||||
builder := parser.Builder{}
|
||||
builder := parser.PositionBuilder{}
|
||||
|
||||
pos := builder.NewNodesPosition(nil, nil)
|
||||
|
||||
@ -316,7 +316,7 @@ func TestNilNodePos(t *testing.T) {
|
||||
func TestNilNodeListPos(t *testing.T) {
|
||||
n1 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -337,7 +337,7 @@ func TestNilNodeListPos(t *testing.T) {
|
||||
func TestNilNodeListTokenPos(t *testing.T) {
|
||||
token1 := scanner.NewToken([]byte(`foo`), 1, 1, 0, 3)
|
||||
|
||||
builder := parser.Builder{}
|
||||
builder := parser.PositionBuilder{}
|
||||
|
||||
pos := builder.NewNodeListTokenPosition(nil, token1)
|
||||
|
||||
@ -349,7 +349,7 @@ func TestNilNodeListTokenPos(t *testing.T) {
|
||||
func TestEmptyNodeListPos(t *testing.T) {
|
||||
n1 := node.NewIdentifier("test node")
|
||||
|
||||
builder := parser.Builder{
|
||||
builder := parser.PositionBuilder{
|
||||
Positions: &parser.Positions{
|
||||
n1: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -370,7 +370,7 @@ func TestEmptyNodeListPos(t *testing.T) {
|
||||
func TestEmptyNodeListTokenPos(t *testing.T) {
|
||||
token1 := scanner.NewToken([]byte(`foo`), 1, 1, 0, 3)
|
||||
|
||||
builder := parser.Builder{}
|
||||
builder := parser.PositionBuilder{}
|
||||
|
||||
pos := builder.NewNodeListTokenPosition([]node.Node{}, token1)
|
||||
|
||||
|
@ -19,7 +19,7 @@ type Parser struct {
|
||||
*scanner.Lexer
|
||||
path string
|
||||
lastToken *scanner.Token
|
||||
positionBuilder *parser.Builder
|
||||
positionBuilder *parser.PositionBuilder
|
||||
errors []*errors.Error
|
||||
rootNode node.Node
|
||||
comments parser.Comments
|
||||
@ -63,7 +63,7 @@ func (l *Parser) Parse() int {
|
||||
l.rootNode = nil
|
||||
l.comments = parser.Comments{}
|
||||
l.positions = parser.Positions{}
|
||||
l.positionBuilder = &parser.Builder{
|
||||
l.positionBuilder = &parser.PositionBuilder{
|
||||
Positions: &l.positions,
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ type Parser struct {
|
||||
*scanner.Lexer
|
||||
path string
|
||||
lastToken *scanner.Token
|
||||
positionBuilder *parser.Builder
|
||||
positionBuilder *parser.PositionBuilder
|
||||
errors []*errors.Error
|
||||
rootNode node.Node
|
||||
comments parser.Comments
|
||||
@ -63,7 +63,7 @@ func (l *Parser) Parse() int {
|
||||
l.rootNode = nil
|
||||
l.comments = parser.Comments{}
|
||||
l.positions = parser.Positions{}
|
||||
l.positionBuilder = &parser.Builder{
|
||||
l.positionBuilder = &parser.PositionBuilder{
|
||||
Positions: &l.positions,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user