2018-04-09 20:08:29 +00:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-07-30 18:01:34 +00:00
|
|
|
"github.com/VKCOM/php-parser/pkg/position"
|
2018-04-09 20:08:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Error parsing error
|
|
|
|
type Error struct {
|
|
|
|
Msg string
|
2018-04-15 19:56:20 +00:00
|
|
|
Pos *position.Position
|
2018-04-09 20:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewError creates and returns new Error
|
2018-11-05 14:56:27 +00:00
|
|
|
func NewError(msg string, p *position.Position) *Error {
|
2018-04-09 20:08:29 +00:00
|
|
|
return &Error{
|
|
|
|
Msg: msg,
|
2018-11-05 14:56:27 +00:00
|
|
|
Pos: p,
|
2018-04-09 20:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Error) String() string {
|
2018-11-05 14:56:27 +00:00
|
|
|
atLine := ""
|
|
|
|
if e.Pos != nil {
|
|
|
|
atLine = fmt.Sprintf(" at line %d", e.Pos.StartLine)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s%s", e.Msg, atLine)
|
2018-04-09 20:08:29 +00:00
|
|
|
}
|