php-parser/pkg/errors/error.go

31 lines
480 B
Go
Raw Permalink Normal View History

2018-04-09 20:08:29 +00:00
package errors
import (
"fmt"
2023-12-09 21:36:19 +00:00
"git.maride.cc/maride/php-parser/pkg/position"
2018-04-09 20:08:29 +00:00
)
// Error parsing error
type Error struct {
Msg string
Pos *position.Position
2018-04-09 20:08:29 +00:00
}
// NewError creates and returns new Error
func NewError(msg string, p *position.Position) *Error {
2018-04-09 20:08:29 +00:00
return &Error{
Msg: msg,
Pos: p,
2018-04-09 20:08:29 +00:00
}
}
func (e *Error) String() string {
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
}