2
0

errors.go 608 B

1234567891011121314151617181920212223242526272829
  1. package parser
  2. import "fmt"
  3. // ParseError represents a parsing error with position information.
  4. type ParseError struct {
  5. Message string
  6. Line int
  7. Column int
  8. Token string
  9. }
  10. func (e *ParseError) Error() string {
  11. if e.Line > 0 {
  12. return fmt.Sprintf("parse error at line %d, column %d: %s (near %q)",
  13. e.Line, e.Column, e.Message, e.Token)
  14. }
  15. return fmt.Sprintf("parse error: %s", e.Message)
  16. }
  17. // newError creates a new ParseError.
  18. func newError(msg string, line, col int, token string) *ParseError {
  19. return &ParseError{
  20. Message: msg,
  21. Line: line,
  22. Column: col,
  23. Token: token,
  24. }
  25. }