#67: skip unexpected character in input
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/scanner"
|
||||
)
|
||||
|
||||
// Error parsing error
|
||||
@@ -14,13 +13,18 @@ type Error struct {
|
||||
}
|
||||
|
||||
// NewError creates and returns new Error
|
||||
func NewError(msg string, t *scanner.Token) *Error {
|
||||
func NewError(msg string, p *position.Position) *Error {
|
||||
return &Error{
|
||||
Msg: msg,
|
||||
Pos: t.Position,
|
||||
Pos: p,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Error) String() string {
|
||||
return fmt.Sprintf("%s at line %d", e.Msg, e.Pos.StartLine)
|
||||
atLine := ""
|
||||
if e.Pos != nil {
|
||||
atLine = fmt.Sprintf(" at line %d", e.Pos.StartLine)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s", e.Msg, atLine)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
"github.com/z7zmey/php-parser/scanner"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
)
|
||||
@@ -27,12 +26,8 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
|
||||
func TestConstructor(t *testing.T) {
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
token := &scanner.Token{
|
||||
Value: `test`,
|
||||
Position: pos,
|
||||
}
|
||||
|
||||
actual := errors.NewError("message", token)
|
||||
actual := errors.NewError("message", pos)
|
||||
|
||||
expected := &errors.Error{
|
||||
Msg: "message",
|
||||
@@ -44,12 +39,8 @@ func TestConstructor(t *testing.T) {
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
token := &scanner.Token{
|
||||
Value: `test`,
|
||||
Position: pos,
|
||||
}
|
||||
|
||||
Error := errors.NewError("message", token)
|
||||
Error := errors.NewError("message", pos)
|
||||
|
||||
actual := Error.String()
|
||||
|
||||
@@ -57,3 +48,13 @@ func TestPrint(t *testing.T) {
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPrintWithotPos(t *testing.T) {
|
||||
Error := errors.NewError("message", nil)
|
||||
|
||||
actual := Error.String()
|
||||
|
||||
expected := "message"
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user