2018-04-09 20:08:29 +00:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/z7zmey/php-parser/position"
|
2018-04-15 11:47:40 +00:00
|
|
|
"github.com/z7zmey/php-parser/scanner"
|
2018-04-09 20:08:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Error parsing error
|
|
|
|
type Error struct {
|
|
|
|
Msg string
|
|
|
|
Pos position.Position
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewError creates and returns new Error
|
2018-04-15 11:47:40 +00:00
|
|
|
func NewError(msg string, t scanner.Token) *Error {
|
2018-04-09 20:08:29 +00:00
|
|
|
return &Error{
|
|
|
|
Msg: msg,
|
|
|
|
Pos: position.Position{
|
|
|
|
StartLine: t.StartLine,
|
|
|
|
EndLine: t.EndLine,
|
|
|
|
StartPos: t.StartPos,
|
|
|
|
EndPos: t.EndPos,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Error) String() string {
|
|
|
|
return fmt.Sprintf("%s at line %d", e.Msg, e.Pos.StartLine)
|
|
|
|
}
|