move Positions and Comments into parser package

This commit is contained in:
z7zmey
2018-04-15 22:02:07 +03:00
parent 781a55659b
commit 56127a4a2c
14 changed files with 142 additions and 76 deletions

View File

@@ -2,8 +2,6 @@ package position
import (
"fmt"
"github.com/z7zmey/php-parser/node"
)
// Position represents node position
@@ -27,11 +25,3 @@ func NewPosition(StartLine int, EndLine int, StartPos int, EndPos int) *Position
func (p Position) String() string {
return fmt.Sprintf("Pos{Line: %d-%d Pos: %d-%d}", p.StartLine, p.EndLine, p.StartPos, p.EndPos)
}
// Positions a collection of positions attached to nodes
type Positions map[node.Node]*Position
// AddPosition attaches a position to a node
func (p Positions) AddPosition(node node.Node, position *Position) {
p[node] = position
}

19
position/position_test.go Normal file
View File

@@ -0,0 +1,19 @@
package position_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
)
func TestPrintPosition(t *testing.T) {
pos := position.NewPosition(1, 1, 2, 5)
expected := "Pos{Line: 1-1 Pos: 2-5}"
actual := pos.String()
if expected != actual {
t.Errorf("expected and actual are not equal\n")
}
}