Merge branch 'comments3'

This commit is contained in:
z7zmey
2018-06-07 15:06:54 +03:00
138 changed files with 17339 additions and 10027 deletions

View File

@@ -4,25 +4,20 @@ import (
"fmt"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/scanner"
)
// Error parsing error
type Error struct {
Msg string
Pos position.Position
Pos *position.Position
}
// NewError creates and returns new Error
func NewError(msg string, t token.Token) *Error {
func NewError(msg string, t *scanner.Token) *Error {
return &Error{
Msg: msg,
Pos: position.Position{
StartLine: t.StartLine,
EndLine: t.EndLine,
StartPos: t.StartPos,
EndPos: t.EndPos,
},
Pos: t.Position(),
}
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/scanner"
"github.com/kylelemons/godebug/pretty"
)
@@ -26,37 +26,22 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
}
func TestConstructor(t *testing.T) {
token := token.Token{
Value: "test",
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
}
pos := position.NewPosition(1, 2, 3, 4)
token := scanner.NewToken(`test`, pos)
actual := errors.NewError("message", token)
expected := &errors.Error{
Msg: "message",
Pos: position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
},
Pos: pos,
}
assertEqual(t, expected, actual)
}
func TestPrint(t *testing.T) {
token := token.Token{
Value: "test",
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
}
pos := position.NewPosition(1, 2, 3, 4)
token := scanner.NewToken(`test`, pos)
Error := errors.NewError("message", token)